Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * JDownloader2 EventScript - Link Crawler Rules Installer
- *
- * Paste script to the script edittor in JD2, and press "Test Run" button.
- * After installation, You can delete this script in JD2 event script settings.
- *
- * Sample:
- *
- * REWRITE frdl.to --> frdl.io
- *
- */
- (function()
- {
- // Define new "Link Crawled Rules" (install data)
- const install_rules =
- [
- {
- "name" : "frdl.to Domain replace",
- "pattern" : "https://frdl\\.to/(.+)",
- "rewriteReplaceWith" : "https://frdl.io/$1",
- "rule" : "REWRITE",
- "enabled" : true,
- },
- ];
- // process start...
- if (!showConfirmDialog("Install new Link Crawler Rules ?\n\nLinkCrawlerRules=\n"+JSON.stringify(install_rules,null,2), "Install","Cancel"))
- return;
- const interface = "jd.controlling.linkcrawler.LinkCrawlerConfig";
- const storage = null;
- var key = "LinkCrawlerRules";
- // load rules
- const linkcrawler_rules = callAPI(
- "config", "get",
- interface,
- storage,
- key
- );
- if (!linkcrawler_rules || !Array.isArray(linkcrawler_rules))
- {
- alert("ERROR: JD2 returned the invalid data as LinkCrawlerRules.");
- return;
- }
- var install_f = 0;
- //merge without the same name rule
- install_rules.forEach(function(i_r)
- {
- if (! linkcrawler_rules.some(function(r){if (i_r.name==r.name)return true}))
- {
- linkcrawler_rules.push(i_r);
- install_f++;
- }
- });
- if (!install_f)
- {
- alert("ERROR: These rules have been already installed.");
- return;
- }
- // restore rules
- callAPI(
- "config", "set",
- interface,
- storage,
- key,
- linkcrawler_rules
- );
- // check enable/disable Link Crawled Rules
- key = "LinkCrawlerRulesEnabled";
- if (callAPI(
- "config", "get",
- interface,
- storage,
- key
- ))
- return;
- // ask enable/disable Link Crawled Rules, and enable it
- if (showConfirmDialog("Enable Link Crawler Rules ?", "Yes","No"))
- callAPI(
- "config", "set",
- interface,
- storage,
- key,
- true
- );
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement