JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #1101  
Old 26.02.2020, 23:40
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

Quote:
Originally Posted by mgpai View Post
Code:
var dateTime = new Date().toJSON().substr(0, 19).replace("T", "_-_").replace(/:/g, "-");

How do you refine it to local dateTime? plus able to chose 12hour and 24hour format?

with example above it returns 20:35 which is 08:35PM but my local time is 12:35PM
Reply With Quote
  #1102  
Old 27.02.2020, 06:11
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,484
Default

Quote:
Originally Posted by zreenmkr View Post
How do you refine it to local dateTime? plus able to chose 12hour and 24hour format?

with example above it returns 20:35 which is 08:35PM but my local time is 12:35PM
Your original example converts the date into JSON format where the timezone offfset is zero, as denoted by the suffix "Z".

Use JS date object methods to convert it to your desired format.
Code:
www.w3schools.com/jsref/jsref_obj_date.asp
Reply With Quote
  #1103  
Old 27.02.2020, 09:23
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

Quote:
Originally Posted by mgpai View Post
Your original example converts the date into JSON format where the timezone offfset is zero, as denoted by the suffix "Z".

Use JS date object methods to convert it to your desired format.
Code:
www.w3schools.com/jsref/jsref_obj_date.asp
I've been there not familiar with timezone. I tried to get 'yyyy-mm-dd' but almost everything else return 'February 27, 2020'. JSON is one of a few that returns 'yyyy-mm-dd'


var n = new Date();
alert(n.toLocaleDateString("en-US")) //'February 27, 2020'

Is there anyway to convert ''February 27, 2020' to numeric 'yyyy-mm-dd'?
Reply With Quote
  #1104  
Old 27.02.2020, 09:35
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

I'm trying to have two scripts with trigger via 'Toolbar Button Pressed'
Button 1 is called 'This is script'
Button 2 is called 'This is script Child'
but when Button 1 is pressed both are executed at the same time. Could review examples bellow.


Code:
//Caller Script - Parent
//Trigger: Toolbar Button Pressed

if (name = 'This is script') {
   alert('script 1')
}

Code:
//Be called - Child
//Trigger: Toolbar Button Pressed

if (name = 'This is script Child') {
   alert('script 2')
}


Off topic: Is it possible to have script1 call script2? Thanks

Last edited by zreenmkr; 27.02.2020 at 09:38.
Reply With Quote
  #1105  
Old 27.02.2020, 10:04
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,484
Default

Quote:
Originally Posted by zreenmkr View Post
Is there anyway to convert ''February 27, 2020' to numeric 'yyyy-mm-dd'?
Has to be formatted using JS code. Check 'stackoverflow.com' for examples. Easier method is to include an external date format library in your script.

Quote:
... but when Button 1 is pressed both are executed at the same time ...
You have used 'assignment operator' in the script.
Code:
if (name = 'This is script') {

Use 'comparision operator' instead.
Code:
if (name == 'This is script') {

Quote:
Off topic: Is it possible to have script1 call script2?
No. But you can include the code from script2 in script1 and execute it conditionally.
Reply With Quote
  #1106  
Old 27.02.2020, 10:24
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

Quote:
Use 'comparision operator' instead.
Code:
if (name == 'This is script') {

Sorry for he typo, comparison operator is what I had in the script. So any idea?

see attached for the created buttons.
Attached Images
File Type: png Toolbar Button Pressed.png (72.9 KB, 0 views)
Reply With Quote
  #1107  
Old 27.02.2020, 10:41
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,484
Default

Quote:
Originally Posted by mgpai View Post
Has to be formatted using JS code
Example:
Code:
var myDate = function() {
    var t = new Date();
    var year = t.getFullYear();
    var month = ("0" + (t.getMonth() + 1)).slice(-2);
    var date = ("0" + t.getDate()).slice(-2);

    return [year, month, date].join("-");
}

alert(myDate());

Quote:
Originally Posted by zreenmkr View Post
...comparison operator is what I had in the script. So any idea?
Only the mods have access to the attachment. I have tested both scripts using comparision operator and they are working correctly.
Reply With Quote
  #1108  
Old 27.02.2020, 11:09
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

Code:
var myDate = function() {
    var t = new Date();
    var year = t.getFullYear();
    var month = ("0" + (t.getMonth() + 1)).slice(-2);
    var date = ("0" + t.getDate()).slice(-2);

    return [year, month, date].join("-");
}

alert(myDate());
Sweet, thanks!!


Quote:
Only the mods have access to the attachment. I have tested both scripts using comparision operator and they are working correctly.
here is the attached on public imgur. See both scripts executed when Button 1 is pressed

screenshots

Last edited by zreenmkr; 27.02.2020 at 12:37.
Reply With Quote
  #1109  
Old 27.02.2020, 11:41
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

tried to create trigger 'Toolbar Button Pressed' in Right Click 'Open Menu Manger' but script didn't get executed
Reply With Quote
  #1110  
Old 27.02.2020, 11:50
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Talking

Quote:
here is the attached on public imgur. See both scripts executed when Button 1 is pressed
MY BAD! script Child has

Code:
if (name = 'This is script Child') {
instead of this, as pointed out.
Code:
if (name == 'This is script Child') {
Reply With Quote
  #1111  
Old 27.02.2020, 11:56
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,484
Default

Quote:
Originally Posted by zreenmkr View Post
here is the attached on public imgur. See both scripts executed when Button 1 is pressed
Quote:
Originally Posted by zreenmkr View Post
tried to create trigger 'Toolbar Button Pressed' in Right Click 'Open Menu Manger' but script didn't get executed
Everything seems to fine in your screenshot. The only way I could reproduce the behaviour was by using 'asignment operators'.

Try creating a different one using instructions provided in this KB article.
Reply With Quote
  #1112  
Old 27.02.2020, 12:34
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

Quote:
The only way I could reproduce the behaviour was by using 'asignment operators'.
Issue resolved itself as described above. sorry for wasting yourtime on this.

Quote:
Try creating a different one using instructions provided in this KB article.
I was able to create a functionional Button in 'Table Main Toolbar' but failed in 'Right Click Menu: Linkgrabber'. I've restarted jd, deleted and created w/out success.

One more thing. Is it normal for EventScripter to failed when code has mistakes in them. Code is triggered by Interval. When executed and error message popup. Went back in the editor and fixed the error but Script would not execute again until restart jd. (exit out jd/and reload). Is this a bug?
Reply With Quote
  #1113  
Old 27.02.2020, 13:32
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,484
Default

Quote:
Originally Posted by zreenmkr View Post
Issue resolved itself as described above. sorry for wasting yourtime on this.
No problem. Only after I submitted my reply, I realised you had posted yours while I was composing mine.

Quote:
I was able to create a functionional Button in 'Table Main Toolbar' but failed in 'Right Click Menu: Linkgrabber'. I've restarted jd, deleted and created w/out success.
Your earlier test scripts work fine with context menu trigger too. Shoul also not require a restart. Check the code and button name (is case sensitve).

Quote:
Is it normal for EventScripter to failed when code has mistakes in them. Code is triggered by Interval. When executed and error message popup. Went back in the editor and fixed the error but Script would not execute again until restart jd. (exit out jd/and reload). Is this a bug?
Except in rare cases, (for e.g. interval script is executed and does not stop with errror, it will keep running in a loop till you quit JD) a restart is not required.

The script will be disabled on error. While there are methods which can be used to prevent it, I would recommend using it only for debugging.

Code:
setDisableOnException(myBoolean); // enable/disable script on exceptions
setNotifyOnException(myBoolean); // enable/disable notification on exceptions

You can also use the use JS error handling methods:
Code:
www.w3schools.com/js/js_errors.asp
Reply With Quote
  #1114  
Old 27.02.2020, 14:20
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

Quote:
The script will be disabled on error. While there are methods which can be used to prevent it, I would recommend using it only for debugging.
Code:
setDisableOnException(myBoolean); // enable/disable script on exceptions
setNotifyOnException(myBoolean); // enable/disable notification on exceptions
Awesome, Thank!

yea, I gave 'JS error handling methods' a go before and for some odd reasons it kept saying "missing ';' before try" so I gave up (couldnt remember exactly). Now the switches above is easier to implement.

Disable Match Files
https
://
github.com/mgpai/resources/blob/master/jdownloader/eventscripter/scripts/netgearjd.js

This script utilized 92% of cpu power to the point where mouse movement was no longer possible. End task was not possible so It required hard reset. I have a few thousand links in Downloads tabs alone.

Last edited by zreenmkr; 27.02.2020 at 14:23.
Reply With Quote
  #1115  
Old 27.02.2020, 15:18
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,484
Default

Quote:
Originally Posted by zreenmkr View Post
This script utilized 92% of cpu power to the point where mouse movement was no longer possible. End task was not possible so It required hard reset. I have a few thousand links in Downloads tabs alone.
Check memory stats during high cpu usage. 'Allocated' should always be reasonably lower than 'Max'.

Code:
Help > About JDownloader > Memory

You may need to increase memory allocation based on the number of links in JD and the text file.

Related post #414379
Reply With Quote
  #1116  
Old 27.02.2020, 23:39
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

Quote:
A better option would be to use a script (Javascript) with packagizer hook in the Eventscripter extension, where you can control the exit accurately. It is also more convenient to search/add/remove keywords.
Quote above from post: Exit Packagizer Loop

Could you give an example where say one of Packgizer rules below return true then exit without trying the next rule bellow?

I want to sort books and group them into different packages. If none of new books match any given given Packagizer rules then group those in general ebooks package. As of right now, due to linear rules execution in Packagizer all ebooks will be grouped in '___Ebooks' Package although some books return true to some of prior rules.


<Condition Name> = _Book Of Animals
if <File Name> contains (birds|elephant) [x]RegExp
then <Package Name> = __Book Of Animals

<Condition Name> = _Book Of Cars
if <File Name> contains (bmw|honda|tesla) [x]RegExp
then <Package Name> = __Book Of Animals
...
<Condition Name> = _eBooks
if <File Type> is pdf,epub,mobi [x]RegExp
then <Package Name> = ___eBooks
Reply With Quote
  #1117  
Old 28.02.2020, 01:59
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

Revisit prior resolved post above by @mgpai

Objective is to get dateTime in numeric format such as 'yyyy-mm-dd' with an alternative other than above.

toJSON() and toISOString() are a few that return this layout but timezone is not local as explained bellow.

Desired layout yyyy-mm-ss_-_hh-mm-ss
Code:
//@mgpai
var dateTime = new Date().toJSON().substr(0, 19).replace("T", "_-_").replace(/:/g, "-");
Quote:
@mgpai
Your original example converts the date into JSON format where the timezone offfset is zero, as denoted by the suffix "Z"

So here is the alternative
Code:
var date = new Date();
var n = date.getTimezoneOffset();
//alert(n); //return time different in #minutes

var dateTime = new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toJSON();
//alert(dateTime); //yyyy-mm-ssThh:mm:ss.msZ - Converted to Local Time


var finalDateTime = dateTime.substr(0, 23).replace("T", "_-_").replace(/:/g, ".");
alert(finalDateTime ); Final modified yyyy-mm-ss_-_hh.mm.ss.ms
Reply With Quote
  #1118  
Old 28.02.2020, 07:07
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,484
Default

Quote:
Originally Posted by zreenmkr View Post
... example where say one of Packgizer rules below return true then exit without trying the next rule ...
Example code:
Code:
// Trigger: Packagizer Hook

var fn = link.getName();
var pn;

if (!pn && /birds|elephant/.test(fn)) pn = "animals";
if (!pn && /bmw|honda|tesla/.test(fn)) pn = "cars";
if (!pn && /.*\.(pdf|epub|mobi)$/.test(fn)) pn = "ebooks";

if (pn) link.setPackageName(pn);
Reply With Quote
  #1119  
Old 28.02.2020, 07:13
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

a) Is there a function to get filename or link on selected file in Downloads/LinkGrabber tab
b) and function that return all subfolders and a function return files in dir
Thanks
Reply With Quote
  #1120  
Old 28.02.2020, 07:37
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

Is it possible to check file exist via regex?

Original fileName with spaces and/or underscore and/or hyphen ect... code below doesn't work.

Code:
var file = 'c:/docs/my(.*?)file(.*?)name(.*?)by(.*?)author.pdf'
 
if (!file.exists()) return;
alert('file exist');
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 01:43.
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 - 2023, Jelsoft Enterprises Ltd.