JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #1  
Old 25.12.2024, 18:19
FWD079 FWD079 is offline
Baby Loader
 
Join Date: Apr 2020
Location: England
Posts: 6
Default JavaScript confirm dialog

Hi and Merry Christmas to all celebrating
Firstly thank you for wonderful Even Scripter, I started playing around, and tried using convert to mp3 script which works. Was just thinking of adding an "Are you sure" box before converting to mp3 file as below:

Code:
// Convert aac/m4a/ogg files to mp3.
// Trigger required: "A Download Stopped".
// Requires ffmpeg/ffprobe. Uses JD ffmpeg/ffprobe settings if available.
// Overwrites destination file (mp3) if it already exists.
disablePermissionChecks();
//confirm("Pree OK to convert AAC to MP3, Cancel to ignore");
if (window.confirm("Convert to Mp3?")) {   
    if (link.finished) {
        var input = link.downloadPath;
        var output = input.replace(/(aac)$/, "mp3");
    
        if (input != output) {
            try {
                var ffmpeg = callAPI("config", "get", "org.jdownloader.controlling.ffmpeg.FFmpegSetup", null, "binarypath");
                var bitrate = callSync(ffmpeg, "-i", input).match(/bitrate: (\d+) kb/)[1];
    
                callAsync(function(error) {
                    !error && getPath(input).delete();
                }, ffmpeg, "-y", "-i", input, "-b:a", bitrate + "k", output);
            } catch (e) {};
        }
    }
}
But I get an error:



Details tell me:

Code:
net.sourceforge.htmlunit.corejs.javascript.EcmaError: ReferenceError: "window" is not defined.
I also tried just "confirm" without "window" too. I thought it was one of the basic JavaScript code, am I missing something?

Please can you advise?
Thanks.

Last edited by FWD079; 25.12.2024 at 18:23.
Reply With Quote
  #2  
Old 25.12.2024, 18:22
FWD079 FWD079 is offline
Baby Loader
 
Join Date: Apr 2020
Location: England
Posts: 6
Default

Images are not being uploaded from imgur somehow, please see attachment to this thread.
Thanks.
Attached Images
File Type: png 8M5rOxp.png (16.7 KB, 1 views)
Reply With Quote
  #3  
Old 25.12.2024, 22:12
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 81,914
Default

@FWD079: JDownloader is no browser. No window object exists. Please don't rely/ask chatgpt for help
At the moment, there is no support for a confirm dialog but I can add one. You just need a dialog that you can define text and button text and then get back the result=clicked button?
__________________
JD-Dev & Server-Admin
Reply With Quote
  #4  
Old 26.12.2024, 17:12
FWD079 FWD079 is offline
Baby Loader
 
Join Date: Apr 2020
Location: England
Posts: 6
Thumbs up

Quote:
Originally Posted by Jiaz View Post
@FWD079: JDownloader is no browser. No window object exists. Please don't rely/ask chatgpt for help
At the moment, there is no support for a confirm dialog but I can add one. You just need a dialog that you can define text and button text and then get back the result=clicked button?
Oh yes please that will be brilliant. That is exactly what I need as my code (not chatgpt's code lol) above suggests, just need to ask before it converts to mp3.

Thank you so much for super fast reply.
Reply With Quote
  #5  
Old 27.12.2024, 22:04
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 81,914
Default

@FWD079: I will ping here once I've added a "confirm dialog" support
__________________
JD-Dev & Server-Admin
Reply With Quote
  #6  
Old 28.12.2024, 13:19
FWD079 FWD079 is offline
Baby Loader
 
Join Date: Apr 2020
Location: England
Posts: 6
Thumbs up

Quote:
Originally Posted by Jiaz View Post
@FWD079: I will ping here once I've added a "confirm dialog" support
Awesome. Will wait no problem.
Thanks.
Reply With Quote
  #7  
Old 31.12.2024, 02:19
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 81,914
Default

Quote:
Originally Posted by FWD079 View Post
Awesome. Will wait no problem.
Thanks.
Update is live.
Quote:
showConfirmDialog("message","ok button text", "cancel button text");
returns 1/true for okay, 0/false for not okay.
in future(if needed) I can add finer *not okay* return status (closed, cancelled, timeout support,.....).
__________________
JD-Dev & Server-Admin
Reply With Quote
  #8  
Old 02.01.2025, 13:24
pspzockerscene's Avatar
pspzockerscene pspzockerscene is offline
Community Manager
 
Join Date: Mar 2009
Location: Deutschland
Posts: 74,051
Default

@Jiaz
Is there any docs for this or maybe at least an example code where you could include such methods so ppl can not only find them by browsing our forums?
__________________
JD Supporter, Plugin Dev. & Community Manager

Erste Schritte & Tutorials || JDownloader 2 Setup Download
Spoiler:

A users' JD crashes and the first thing to ask is:
Quote:
Originally Posted by Jiaz View Post
Do you have Nero installed?
Reply With Quote
  #9  
Old 02.01.2025, 14:03
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,668
Default

Can be found in the 'global' methods section in the built-in editor help:
Code:
var myInt = showConfirmDialog(myString/*message*/, myString/*okOption*/, myString/*cancelOption*/);/*Show a Confirm Dialog*/
Reply With Quote
  #10  
Old 02.01.2025, 14:19
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 81,914
Default

@pspzockerscene: I've posted working example in my answer
__________________
JD-Dev & Server-Admin
Reply With Quote
  #11  
Old 02.01.2025, 14:24
pspzockerscene's Avatar
pspzockerscene pspzockerscene is offline
Community Manager
 
Join Date: Mar 2009
Location: Deutschland
Posts: 74,051
Default

@mgpai
Ahh indeed.
Thanks! I've never looked at that lol

@Jiaz
Yes I know but as explained, my post was about finding the availability of that code without the need to do a websearch and find this thread.
__________________
JD Supporter, Plugin Dev. & Community Manager

Erste Schritte & Tutorials || JDownloader 2 Setup Download
Spoiler:

A users' JD crashes and the first thing to ask is:
Quote:
Originally Posted by Jiaz View Post
Do you have Nero installed?
Reply With Quote
  #12  
Old 14.01.2025, 20:26
FWD079 FWD079 is offline
Baby Loader
 
Join Date: Apr 2020
Location: England
Posts: 6
Default

Quote:
Originally Posted by Jiaz View Post
Update is live.

returns 1/true for okay, 0/false for not okay.
in future(if needed) I can add finer *not okay* return status (closed, cancelled, timeout support,.....).
Ah brilliant, I checked and all my notifications are on, but this neither sent an email nor popped up for some reason. Thank you 🙏🙏
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +2. The time now is 09:52.
Provided By AppWork GmbH | Privacy | Imprint
Parts of the Design are used from Kirsch designed by Andrew & Austin
Powered by vBulletin® Version 3.8.10 Beta 1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.