usamimi2323

JDownloader2 EventScript - リネーム系アクション集用メニュー自動設定 Ver 0.3

Jan 26th, 2025 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 15.71 KB | Source Code | 0 0
  1. /**
  2.  * JDownloader2 EventScript - リネーム系アクション集用メニュー自動設定
  3.  *
  4.  * リネーム系アクション集に対応したメニュー項目を
  5.  * JD2のコンテキストメニューに登録するEventScript
  6.  *
  7.  * 実行後は必ずJDを再起動し、
  8.  * 追加されたメニュー項目をメニュー管理画面から
  9.  * 適宜、移動・編集・削除してください
  10.  *
  11.  *
  12.  * 【使い方】
  13.  *
  14.  * 0. [WEBで検索] 部分(173行目から183行目辺り)を自分用に書き換える
  15.  *
  16.  * 1. [設定]→[イベントスクリプト]→[+追加]ボタンを押す
  17.  *    →追加された項目の[編集]ボタンを押す
  18.  *   (※ ここで追加した無名スクリプトは、後で削除してください)
  19.  *
  20.  * 2. このスクリプトファイルの内容を全てコピーして貼り付ける
  21.  *
  22.  * 3. [試行]ボタンを押す
  23.  *
  24.  * 4. 登録したいメニューで「はい」を選ぶ
  25.  *
  26.  * 5. JD2を再起動
  27.  *
  28.  * 6. ダウンロードリスト画面、リンクグラバー画面
  29.  *    それぞれのメニュー管理画面から好きなように編集
  30.  *
  31.  *
  32.  * 【履歴】
  33.  * 2025/01/07 - JDにshowConfirmDialog()が追加されたので置き換え
  34.  * 2025/01/20 - リネームスクリプト更新に合わせて色々更新
  35.  *
  36.  */
  37.  
  38. // -----【設定ここから】-----
  39.  
  40. // 検索メニュー
  41. //(先に「リネーム系アクション集」のUserConfig.web_search_tableを編集し、
  42. // その名前に合わせて書き換えてください)
  43.  
  44. const search_items = [
  45.     "888**.ps",
  46.     "x3**.net",
  47.     "*****-zip.info",
  48.     "bs***.com",
  49.     "raw*****.cc",
  50.     "-",
  51.     "******core.com",
  52.     "******omg.com",
  53.     "nhentai.net",
  54.     "-",
  55.     "google.com (Author)",
  56.     "google.com (Title)",
  57. ];
  58.  
  59. // -----【設定ここまで】-----
  60.  
  61. function getSearchItems(separator)
  62. {
  63.     return search_items.map(function(i){return {'name':(i=='-'?separator:i)}});
  64. }
  65. const separator_name_ja='セパレータ';
  66. const separator_name_en='Separator';
  67.  
  68. //SeparatorData_SeparatorData=セパレータ
  69.  
  70. /**
  71.  * @typedef {object} menuItem
  72.  * @prop {string} name メニュー名
  73.  * @prop {string} [iconKey=null] アイコン名
  74.  * @prop {string} [shortcut=null] ショートカットキー
  75.  * @prop {menuItem[]} [items] サブメニューのmenuItem配列
  76.  * ----------------------------------
  77.  * @prop {string} [type]
  78.  * @prop {string} [className]
  79.  * @prop {object} [actionData={}]
  80.  * @prop {string} [mnemonic=null]
  81.  * @prop {boolean} [visible=true]
  82.  */
  83. var menu_items = {};
  84. /** @type {menuItem[]} Japanese data, 追加するメニューデータ 編集可 */
  85. menu_items.ja =
  86. [
  87.     {"name":separator_name_ja},
  88.     {
  89.         "name":"リネーム - ファイル名を揃える",
  90.         "iconKey":"edit",
  91.         "items":[
  92.             {
  93.                 "name":"パッケージ名でファイル名を揃える",
  94. //              "shortcut"  :"pressed F7",
  95.             },
  96.             {"name":"このファイル名でパッケージ内を全て揃える"},
  97.             {"name":separator_name_ja},
  98.             {"name":"名前を揃える"},
  99.             {"name":"名前を揃える(作者名)"},
  100.             {"name":"名前を揃える(タイトル)"},
  101.             {"name":"名前を揃える(カテゴリ+作者名)"},
  102.             {"name":"名前を揃える(カテゴリ+作者名+タイトル)"},
  103.             {"name":separator_name_ja},
  104.             {"name":"[]内のスワップ"},
  105.             {"name":"[]内の末尾切り捨て"},
  106.             {"name":"[]内のxを×に変換"},
  107.             {"name":separator_name_ja},
  108.             {"name":"第○○巻化"},
  109.             {"name":"名前の数字部分の桁を揃える"},
  110.             {"name":separator_name_ja},
  111.             {"name":"先頭括弧を後方送り"},
  112.             {"name":"末尾の括弧削除"},
  113.         ]
  114.     },
  115.     {
  116.         "name":"リネーム - 修正/追加/置換",
  117.         "iconKey":"edit",
  118.         "items":[
  119.             {"name":"<< 別スキャン"},
  120.             {"name":"<< 単行本"},
  121.             {"name":"<< 透かし有り"},
  122.             {"name":"<< 寄せ集め"},
  123.             {"name":separator_name_ja},
  124.             {"name":"(一般コミック) >>"},
  125.             {"name":"(一般コミック・少女) >>"},
  126.             {"name":"(一般コミック) [雑誌] >>"},
  127.             {"name":"(一般小説) >>"},
  128.             {"name":"(一般書籍) >>"},
  129.             {"name":"(成年コミック) >>"},
  130.             {"name":"(成年コミック) [雑誌] >>"},
  131.             {"name":"(同人誌) >>"},
  132.             {"name":"(同人CG集) >>"},
  133.             {"name":"(18禁アニメ) >>"},
  134.         ]
  135.     },
  136.     {
  137.         "name":"移動/ファイル/再登録",
  138.         "iconKey":"folder_add",
  139.         "items":[
  140.             {
  141.                 "name":"この名前を使用して新しいパッケージに移動",
  142.                 "iconKey":"package_new",
  143. //              "iconKey":"folder_add",
  144. //              "shortcut"  :"pressed F9",
  145.             },
  146.             {"name":"同じ名前のパッケージをまとめる"},
  147.             {"name":"リンクを同じ名前のパッケージに移動"},
  148.             {"name":separator_name_ja},
  149.             {"name":"タイトルで並べ替え(昇順)"},
  150.             {"name":"タイトルで並べ替え(降順)"},
  151.             {"name":"作者名で並べ替え(昇順)"},
  152.             {"name":"作者名で並べ替え(降順)"},
  153.             {"name":"追加日時で並べ替え(昇順)"},
  154.             {"name":"追加日時で並べ替え(降順)"},
  155.             {"name":separator_name_ja},
  156.             {"name":"リンクグラバーへ再登録","iconKey":"linkgrabber"},
  157.             {"name":separator_name_ja},
  158.             {"name":"JDバックアップフォルダを開く"},
  159.             {"name":"登録元ページを開く","iconKey":"search"},
  160.             {"name":separator_name_ja},
  161.             {"name":"ブラウザで開く - rosefile.net のみ","iconKey":"search"},
  162.         ]
  163.     },
  164.     {
  165.         "name":"有効/無効",
  166.         "iconKey":"checkbox_true",
  167.         "items":[
  168.             {"name":"優先ホスト(単一)以外を無効"},
  169.             {"name":"優先ホスト(複数)以外を無効"},
  170.             {"name":separator_name_ja},
  171.             {"name":"frdl.to以外を無効"},
  172.             {"name":"dailyuploads.net以外を無効"},
  173.             {"name":"hexload.com以外を無効"},
  174.             {"name":"mexa.sh以外を無効"},
  175.             {"name":"katfile.com以外を無効"},
  176.             {"name":"rapidgator.net以外を無効"},
  177.             {"name":"dashfile.net以外を無効"},
  178.             {"name":"btafile.com以外を無効"},
  179.             {"name":separator_name_ja},
  180.             {"name":"rosefile.netを無効"},
  181.             {"name":"takefile.linkを無効"},
  182.         ]
  183.     },
  184.    
  185.     {
  186.         "name":"EveryThingで検索(作者名)",
  187.         "iconKey":"search",
  188. //      "shortcut"  :"pressed F1",
  189.     },
  190.     {
  191.         "name":"EveryThingで検索(タイトル)",
  192.         "iconKey":"search",
  193.     },
  194.     {
  195.         "name":"ブラウザで開く",
  196.         "iconKey":"search",
  197.     },
  198.     {
  199.         "name":"WEBで検索",
  200.         "iconKey":"url",
  201.         "items":getSearchItems(separator_name_ja),
  202.     }
  203. ];
  204.  
  205.  
  206. /** @type {menuItem[]} English data */
  207. menu_items.en =
  208. [
  209.     {"name":separator_name_en},
  210.     {
  211.         "name":"rename - align",
  212.         "iconKey":"edit",
  213.         "items":[
  214.             {
  215.                 "name":"Rename links to package name",
  216. //              "shortcut"  :"pressed F7"
  217.             },
  218.             {"name":"Rename package and links to this link name"},
  219.             {"name":separator_name_en},
  220.             {"name":"Rename links to this link name"},
  221.             {"name":"Rename links to this link name(Author)"},
  222.             {"name":"Rename links to this link name(Title)"},
  223.             {"name":"Rename links to this link name(Category+Author)"},
  224.             {"name":"Rename links to this link name(Category+Author+Title)"},
  225.             {"name":separator_name_en},
  226.             {"name":"Rename Author - swap"},
  227.             {"name":"Rename Author - chop last author"},
  228.             {"name":"Rename Author - x to ×"},
  229.             {"name":separator_name_en},
  230.             {"name":"Rename Numbering to comic format"},
  231.             {"name":"Rename links to align the digits length"},
  232.             {"name":separator_name_en},
  233.             {"name":"Rename links to move starting brackets to end"},
  234.             {"name":"Rename to removing trailed brackets"},
  235.         ]
  236.     },
  237.     {
  238.         "name":"rename - add/replace",
  239.         "iconKey":"edit",
  240.         "items":[
  241.             {"name":"<< 別スキャン"},
  242.             {"name":"<< 単行本"},
  243.             {"name":"<< 透かし有り"},
  244.             {"name":"<< 寄せ集め"},
  245.             {"name":separator_name_en},
  246.             {"name":"(一般コミック) >>"},
  247.             {"name":"(一般コミック・少女) >>"},
  248.             {"name":"(一般コミック) [雑誌] >>"},
  249.             {"name":"(一般小説) >>"},
  250.             {"name":"(一般書籍) >>"},
  251.             {"name":"(成年コミック) >>"},
  252.             {"name":"(成年コミック) [雑誌] >>"},
  253.             {"name":"(同人誌) >>"},
  254.             {"name":"(同人CG集) >>"},
  255.             {"name":"(18禁アニメ) >>"},
  256.         ]
  257.     },
  258.     {
  259.         "name":"move/sort/...",
  260.         "iconKey":"folder_add",
  261.         "items":[
  262.             {
  263.                 "name":"Move to new package with this name",
  264.                 "iconKey":"package_new",
  265. //              "iconKey":"folder_add",
  266. //              "shortcut"  :"pressed F9"
  267.             },
  268.             {"name":"Merge same packages"},
  269.             {"name":"Move links to same name package"},
  270.             {"name":separator_name_en},
  271.             {"name":"Sort packages by Title(ASC)"},
  272.             {"name":"Sort packages by Title(DESC)"},
  273.             {"name":"Sort packages by Author(ASC)"},
  274.             {"name":"Sort packages by Author(DESC)"},
  275.             {"name":"Sort packages by Added Date(ASC)"},
  276.             {"name":"Sort packages by Added Date(DESC)"},
  277.             {"name":separator_name_en},
  278.             {"name":"Add to LinkGrabber","iconKey":"linkgrabber"},
  279.             {"name":separator_name_en},
  280.             {"name":"Open JD Backup Folder"},
  281.             {"name":"Open the Source Page","iconKey":"search"},
  282.             {"name":separator_name_en},
  283.             {"name":"Open browser - only rosefile.net","iconKey":"search"},
  284.         ]
  285.     },
  286.     {
  287.         "name":"enable/disable",
  288.         "iconKey":"checkbox_true",
  289.         "items":[
  290.             {"name":"Diable links by my Rules (Single)"},
  291.             {"name":"Diable links by my Rules (Multiple)"},
  292.             {"name":separator_name_en},
  293.             {"name":"Disable all but frdl.to"},
  294.             {"name":"Disable all but dailyuploads.net"},
  295.             {"name":"Disable all but hexload.com"},
  296.             {"name":"Disable all but mexa.sh"},
  297.             {"name":"Disable all but katfile.com"},
  298.             {"name":"Disable all but rapidgator.net"},
  299.             {"name":"Disable all but dashfile.net"},
  300.             {"name":"Disable all but btafile.com"},
  301.             {"name":separator_name_en},
  302.             {"name":"Disable rosefile.net"},
  303.             {"name":"Disable takefile.link"},
  304.         ]
  305.     },
  306.    
  307.     {
  308.         "name":"EveryThing(Author)",
  309.         "iconKey":"search",
  310. //      "shortcut"  :"pressed F1",
  311.     },
  312.     {
  313.         "name":"EveryThing(Title)",
  314.         "iconKey":"search",
  315.     },
  316.     {
  317.         "name":"Open Browser",
  318.         "iconKey":"search",
  319.     },
  320.     {
  321.         "name":"Search WEB",
  322.         "iconKey":"url",
  323.         "items":getSearchItems(separator_name_en),
  324.     }
  325. ];
  326.  
  327.  
  328.  
  329. /////////////////////////////////////////////////
  330.  
  331. const StringTable =
  332. {
  333.     "Separator":"セパレータ",
  334.     "Select the language of the menu item that you want to install.":"インストールするメニューアイテムの言語を選択してください",
  335.     "Japanese":"日本語",
  336.     "English":"英語",
  337.     "Do you want to install Menu Items to the DOWNLOAD Context Menu ?":"ダウンロードリストのコンテキストメニューにメニューを追加します\r\nよろしいですか?",
  338.     "YES":"はい",
  339.     "NO":"いいえ",
  340.     "Do you want to install Menu Items to the LINKGRABBER Context Menu ?":"リンクグラバーのコンテキストメニューにメニューを追加します\r\nよろしいですか?",
  341.     "Your installation require a JDownloader restart to take effect. Restart now?":"設定の反映にはJDownloaderの再起動が必要です\r\n今すぐ再起動しますか?",
  342.     "Restart Now":"再起動する",
  343.     "To later...":"後にする・・・",
  344. };
  345.  
  346. function I(t)
  347. {
  348.     const lang = getLanguage();
  349.     if (lang != 'ja') return t;
  350.     return (t in StringTable) ? StringTable[t] : t;
  351. }
  352.  
  353. function jdPath(path)
  354. {
  355.     const sep = getPathSeparator();
  356.     if (sep == '\\')
  357.         path = path.replace('/', '\\');
  358.     else if (sep == '/')
  359.         path = path.replace('\\', '/');
  360.     return JD_HOME+sep+path;
  361. }
  362. function DQ(s){ return '"'+ s.trim() +'"'}
  363. function unDQ(s){return s && s.replace(/^[\s\xA0]*"|"[\s\xA0]*$/g, '')}
  364. const PATH_CFG_LANGUAGE_JSON          = 'cfg\\language.json';
  365.  
  366. var getLanguage = function()
  367. {
  368.     if (getLanguage.cache) return getLanguage.cache;
  369.     const buf = unDQ(readFile(jdPath(PATH_CFG_LANGUAGE_JSON)));
  370.     return getLanguage.cache = (buf != '' && /^([a-zA-Z][-a-zA-Z\d_]+)$/.test(buf)) ? buf : 'en';
  371. }
  372.  
  373. /**
  374.  * メニューデータを再構築
  375.  *
  376.  * @param {menuItem|menuItem[]} x メニューデータ
  377.  */
  378. function rebuildMenu(x)
  379. {
  380.     function r(m)
  381.     {
  382.         // Set default value
  383.         if (! ('visible' in m)) m['visible']  = true;
  384.         if (! ('shortcut'in m)) m['shortcut'] = null;
  385.         if (! ('mnemonic'in m)) m['mnemonic'] = null;
  386.         if (! ('iconKey' in m)) m['iconKey']  = null;
  387.        
  388.         if (('items' in m) && m['items'].length)
  389.         {
  390.             m['type'] = 'CONTAINER';
  391.             m['className'] = 'org.jdownloader.controlling.contextmenu.MenuContainer';
  392.             m['actionData'] = {};
  393.            
  394.             m['items'].forEach(function(val,idx,list){
  395.                 r(list[idx]);
  396.             });
  397.         }
  398.         else if (m['name']==separator_name_ja || m['name']==separator_name_en)
  399.         {
  400.             m['type'] = 'ACTION';
  401.             m['className'] = 'org.jdownloader.controlling.contextmenu.SeparatorData';
  402.             m['actionData'] = {};
  403.             m['items'] = [];
  404.         }
  405.         else
  406.         {
  407.             m['type'] = 'ACTION';
  408.             m['className'] = null;
  409.             if (!('actionData' in m))
  410.                 m['actionData'] = {'clazzName':'org.jdownloader.extensions.eventscripter.GenericEventScriptTriggerContextMenuAction'};
  411.             m['items'] = [];
  412.         }
  413.        
  414. //      if (m['visible']) true;
  415.     }
  416.     if (Array.isArray(x))
  417.         x.forEach(function(val,idx,list){r(list[idx])});
  418.     else
  419.         (r)(x);
  420. }
  421. /**
  422.  * コンテキストに応じたルートメニューを取得する
  423.  *
  424.  * @param {"DownloadTableContext"|"LinkgrabberContext"} context コンテキスト
  425.  * @returns {menuItem} ルートメニューデータ(JSON)
  426.  */
  427.  
  428. function getRootContextMenu(context)
  429. {
  430.     const storage = "cfg/menus_v2/" + context;
  431.     const interface = "org.jdownloader.controlling.contextmenu.ContextMenuConfigInterface";
  432.     const root_menu = callAPI(
  433.         "config", "get",
  434.         interface,
  435.         storage,
  436.         "menu"
  437.     );
  438.    
  439.     return root_menu;
  440. }
  441.  
  442. /**
  443.  * メニューデータをルートとして、コンテキストに応じたメニューに設定する
  444.  * (設定の反映にはJDの再起動が必要)
  445.  *
  446.  * @param {menuItem} x メニューデータ
  447.  * @param {"DownloadTableContext"|"LinkgrabberContext"} context コンテキスト
  448.  * @returns {boolean} 成功か失敗か
  449.  */
  450. function setRootContextMenu(root_menu, context) {
  451.     const storage = "cfg/menus_v2/"+context;
  452.     const interface = "org.jdownloader.controlling.contextmenu.ContextMenuConfigInterface";
  453.     return callAPI(
  454.         "config", "set",
  455.         interface,
  456.         storage,
  457.         "menu",
  458.         root_menu
  459.     );
  460. }
  461.  
  462. /**
  463.  * メニューデータをコンテキストに応じたルートメニューに追加して設定する
  464.  * (設定の反映にはJDの再起動が必要)
  465.  *
  466.  * @param {menuItem|menuItem[]} menu_items メニューデータ
  467.  * @param {"DownloadTableContext"|"LinkgrabberContext"} context コンテキスト
  468.  * @returns {boolean} 成功か失敗か
  469.  */
  470. function addMenuToContextMenu(menu_items, context)
  471. {
  472.     const c = context||"DownloadTableContext";
  473.    
  474.     /** @type {menuItem} ルートメニュー取得 */
  475.     const root_container = getRootContextMenu(c);
  476.     if (root_container && root_container.type=='CONTAINER' && Array.isArray(root_container.items))
  477.     {
  478.         if (Array.isArray(menu_items))
  479.             menu_items.forEach(function(menu_item){root_container.items.push(menu_item)});
  480.         else
  481.             root_container.items.push(menu_items);
  482.        
  483.         setRootContextMenu(root_container, c);
  484.     }
  485. }
  486.  
  487.  
  488. const menu_lang = showConfirmDialog(I("Select the language of the menu item that you want to install."),I("Japanese"),I("English"))
  489.                     ? 'ja'
  490.                     : 'en';
  491.  
  492. rebuildMenu(menu_items[menu_lang]);
  493.  
  494. var restart_f = 0;
  495.  
  496. if (showConfirmDialog(I("Do you want to install Menu Items to the DOWNLOAD Context Menu ?"),I("YES"), I("NO")))
  497.     addMenuToContextMenu(menu_items[menu_lang], "DownloadTableContext") || restart_f++;
  498.    
  499. if (showConfirmDialog(I("Do you want to install Menu Items to the LINKGRABBER Context Menu ?"),I("YES"), I("NO")))
  500.     addMenuToContextMenu(menu_items[menu_lang], "LinkgrabberContext") || restart_f++;
  501.  
  502. if (restart_f && showConfirmDialog(I("Your installation require a JDownloader restart to take effect. Restart now?"),I("Restart Now"),I("To later...")))
  503.     callAPI("system","restartJD");
  504.  
  505.  
  506.  
Add Comment
Please, Sign In to add comment