Advertisement
usamimi2323

JDownloader2 EventScript - Link Crawler Rules Installer

Feb 8th, 2025
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.06 KB | Source Code | 0 0
  1. /**
  2.  * JDownloader2 EventScript - Link Crawler Rules Installer
  3.  *
  4.  * Paste script to the script edittor in JD2, and press "Test Run" button.
  5.  * After installation, You can delete this script in JD2 event script settings.
  6.  *
  7.  * Sample:
  8.  *
  9.  * REWRITE  frdl.to --> frdl.io
  10.  *
  11.  */
  12. (function()
  13. {
  14.     // Define new "Link Crawled Rules" (install data)
  15.     const install_rules =
  16.     [
  17.         {
  18.             "name"               : "frdl.to Domain replace",
  19.             "pattern"            : "https://frdl\\.to/(.+)",
  20.             "rewriteReplaceWith" : "https://frdl.io/$1",
  21.             "rule"               : "REWRITE",
  22.             "enabled"            : true,
  23.         },
  24.     ];
  25.    
  26.    
  27.     // process start...
  28.    
  29.     if (!showConfirmDialog("Install new Link Crawler Rules ?\n\nLinkCrawlerRules=\n"+JSON.stringify(install_rules,null,2), "Install","Cancel"))
  30.         return;
  31.    
  32.     const interface = "jd.controlling.linkcrawler.LinkCrawlerConfig";
  33.     const storage = null;
  34.     var key = "LinkCrawlerRules";
  35.    
  36.     // load rules
  37.     const linkcrawler_rules = callAPI(
  38.         "config", "get",
  39.         interface,
  40.         storage,
  41.         key
  42.     );
  43.    
  44.     if (!linkcrawler_rules || !Array.isArray(linkcrawler_rules))
  45.     {
  46.         alert("ERROR: JD2 returned the invalid data as LinkCrawlerRules.");
  47.         return;
  48.     }
  49.     var install_f = 0;
  50.     //merge without the same name rule
  51.     install_rules.forEach(function(i_r)
  52.     {
  53.         if (! linkcrawler_rules.some(function(r){if (i_r.name==r.name)return true}))
  54.         {
  55.             linkcrawler_rules.push(i_r);
  56.             install_f++;
  57.         }
  58.     });
  59.  
  60.     if (!install_f)
  61.     {
  62.         alert("ERROR: These rules have been already installed.");
  63.         return;
  64.     }
  65.    
  66.     // restore rules
  67.     callAPI(
  68.         "config", "set",
  69.         interface,
  70.         storage,
  71.         key,
  72.         linkcrawler_rules
  73.     );
  74.    
  75.     // check enable/disable Link Crawled Rules
  76.     key = "LinkCrawlerRulesEnabled";
  77.     if (callAPI(
  78.         "config", "get",
  79.         interface,
  80.         storage,
  81.         key
  82.     ))
  83.         return;
  84.    
  85.     // ask enable/disable Link Crawled Rules, and enable it
  86.     if (showConfirmDialog("Enable Link Crawler Rules ?", "Yes","No"))
  87.         callAPI(
  88.             "config", "set",
  89.             interface,
  90.             storage,
  91.             key,
  92.             true
  93.         );
  94.    
  95. })();
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement