Advertisement
usamimi2323

JDownloader2 EventScript - 「名前を元に戻す」用リンクプロパティ設定

Apr 2nd, 2025 (edited)
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.00 KB | Source Code | 0 0
  1. /**
  2.  * 「名前を元に戻す」用リンクプロパティ設定
  3.  * 「登録元ページを開く」用リンクプロパティ設定
  4.  *
  5.  * Trigger:ON_PACKAGIZER
  6.  */
  7. (function(){
  8.     const prop_name1 = "ORIGIN_NAME";
  9.     const prop_name2 = "PACKAGIZER_NAME";
  10.     const prop_name3 = "SOURCE_URL";
  11.     const SOURCE_URL_KEYNAME_IN_URL = "ref";
  12.    
  13.     var regexp_is_url_ok = /^https?:\/\//;
  14.     var regexp_get_SOURCE_URL = new RegExp('#(?:.*&)?'+SOURCE_URL_KEYNAME_IN_URL+'=([^&]*)(?:&.*)?$','i');
  15.    
  16.     // check
  17.     if (link.getProperty(prop_name1))
  18.         return;
  19.    
  20.     if (state=='BEFORE')
  21.     {
  22.         link.setProperty(prop_name1, link.name);
  23.        
  24.         link.getSourceUrls() && link.getSourceUrls().some(function(u)
  25.         {
  26.             var r = u.match(regexp_get_SOURCE_URL);
  27.             if (!r || !r[1]) return false;
  28.             var url = decodeURIComponent(r[1]);
  29.             if (regexp_is_url_ok.test(url))
  30.             {
  31.                 link.setProperty(prop_name3, url);
  32.             }
  33.             return true;
  34.         });
  35.     }
  36.     else if (state == 'AFTER')
  37.     {
  38.         link.setProperty(prop_name2, link.name);
  39.     }
  40. })();
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement