Advertisement
usamimi2323

Bookmarklet - nhentai 日本語タイトルJD2登録用リンク生成スクリプト

Nov 11th, 2023 (edited)
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 10.15 KB | Source Code | 0 0
  1. //
  2. // Bookmarklet - nhentai 日本語タイトルJD2登録用リンク生成スクリプト
  3. //
  4. // サイトの個別ページ上でスクリプトを実行、生成されたURLリストをJD2に渡す
  5. // 日本語タイトルでパッケージ名を設定
  6. //
  7. //   タグから検索、EveryThingのオプション → 全般 → es:URLプロトコルハンドラーをオン
  8. //   Windowsの古い環境なので参考程度で
  9. //
  10. //
  11. //   ※ 事前に一番下のパッケージャルールをインポートしておく
  12. //     パッケージャルールのサブフォルダは、インポート後に自分の環境のDLパス名に変更しておく
  13. //     (行末 \\<jd:packagename> は変えない)
  14. //
  15. //
  16. //-------------------------------------------------------------------------------------
  17.  
  18. /*
  19. 【ブックマークレット】
  20.  
  21. javascript:(()=>{var p=Object.keys,k=document;window.Q=(a,b=k)=>b.querySelector(a);var q=f=>{var c={"!":"\uff01",'"':"\u201d","#":"\uff03",$:"\uff04","%":"\uff05","&":"\uff06","'":"\u2019","~":"\uff5e","|":"\uff5c","*":"\uff0a",":":"\uff1a","<":"\uff1c",">":"\uff1e","?":"\uff1f","/":"\uff0f","\\":"\uffe5","`":"\u2018",",":"\uff0c","\u3000":" ","\u301c":"\uff5e","\u2661":"","\u2665":"","\u2015":"\uff0d","\u2500":"\uff0d","\u2501":"\uff0d","\u5377":"\u5dfb","\u5b78":"\u5b66",
  22. "\u9ed1":"\u9ed2","\u95dc":"\u95a2","\u7e6a":"\u7d75","\u6703":"\u4f1a","\u4e9e":"\u4e9c","\u9ad9":"\u9ad8"},d={"&times;":"\u00d7","&amp;":"\uff06","&nbsp;":" ","%u2019;":"\u2019"};if(!f)return f;var h=new RegExp("["+p(c).join("")+"]","g"),e=new RegExp("("+p(d).join("|")+")","g");return f.normalize("NFKC").replace(h,a=>a in c?c[a]:a).replace(e,a=>a in d?d[a]:a).replace(/([\]\)])([^\s\.\)\]])/g,"$1 $2").replace(/([^ ])([\[\(])/g,"$1 $2").replace(/  +/g," ").replace(/\.\.+/,
  23. ".")},b;(b=Q("#X_l"))&&b.parentNode.remove();b=Q("#tags").textContent;var r=4<=b.match(/Pages:\s+(\d+)/)[1].length?4:3,m=b.match(/Categories:\s+([a-z]+)/i)[1];b=Q("h2.title");null===b&&(b=Q("h1.title"));var g=b.textContent.trim();if(!/^\(\u540c\u4eba/.test(g)){for(var l=g.length;0<l;)if(b=g.match(/^(\([^\)\[]+\))\s*(.+?)(\s*\[[^\]\[]+\])*$/))g=b[2]+" "+b[1],b[3]&&(g+=" "+b[3].trim()),l-=b[1].length;else break;"doujinshi"==m&&(g="(\u540c\u4eba\u8a8c) "+g)}m="";b=/^https:\/\/t(\d+)(\.[^\/]+\/galleries\/)(\d+)\/(\d+)t(\.[^\/]+)$/;
  24. l=k.querySelectorAll("div.thumb-container");for(var n=0;n<l.length;n++){var t=Q("img",l[n]).getAttribute("data-src");t&&(m+=t.replace(b,(f,c,d,h,e,a)=>{f="https://i"+c+d+h+"/"+e+a+"#jdp="+encodeURIComponent(q(g))+"&jdl=";e=(e.length<r?"0".repeat(r-e.length):"")+e;return f+e+"&subfolder=ON"})+"<br>\r\n")}b=k.createElement("div");b.style="border:inset thin gray;margin:5pt;padding:5pt;background-color:#333;";b.innerHTML='<br><button onclick="document.getSelection().selectAllChildren(this.parentNode.querySelector(\'#X_l\'))"> \u9078\u629e </button> <button onclick="this.parentNode.remove()"> \u9589\u3058\u308b </button><br><div id=X_t class="tag-container field-name title"><h3><span class="tags">'+
  25. (f=>{return f.replace(/([\]\)]) ?([^\[\]\(\) ]+)/,'$1 <a class="tag" href="es:$2"><span class=name>$2</span></a>').replace(/^([^\[\( ]+)/,'<a class="tag" href="es:$1"><span class=name>$1</span></a>').replace(/\[([^\]\(]+)(?: *\(([^\)\(]+)\))?\]/g,(c,d,h)=>{c="[";var e=/\u00d7|\uff06|\uff0c|\u3001|\uff0f/;d=d.split(e);for(var a=0;a<d.length;a++)1<=a&&(c+="\u00d7"),c+='<a class="tag" href="es:'+d[a]+'"><span class=name>'+d[a]+"</span></a>";if(h){c+=" (";d=h.split(e);for(a=0;a<d.length;a++)1<=
  26. a&&(c+="\u00d7"),c+='<a class="tag" href="es:'+d[a]+'"><span class=name>'+d[a]+"</span></a>";c+=")"}return c+"]"}).replace(/\(([^\)<>]+)\)/g,'<a class="tag" href="es:$1"><span class=name>($1)</span></a>').replace(RegExp('(href="es:[^"]*)[\uff01\uff1f\u3002\uff0e\u3001\uff0c]">',"g"),'$1">')})(q(g))+"</span></h3></div><div id=X_l style=font-size:65%;width:100%;height:150px;overflow:scroll;>"+m+"</div>";k.getElementById("bigcontainer").appendChild(b);k.getSelection().selectAllChildren(Q("#X_l",b))})();
  27.  
  28. */
  29.  
  30. // ↑の短縮化前のコード
  31. (function(){
  32.     var search_prefix='es:';
  33.     var jdp="jdp";
  34.     var jdl="jdl";
  35.     var subfolder="subfolder=ON";
  36.    
  37.     var z=String.fromCharCode;
  38.     var y=Object.keys;
  39.     var d=document;
  40.     window.Q=(a,b=d)=>b.querySelector(a);
  41.     // 0埋め
  42.     var zeroPadding=(s,l)=>((s.length<l?'0'.repeat(l-s.length):'')+s);
  43.     var stripTag = s=>s.replace(/<[^>]*>/g,'');
  44.     var normalizeTitle=function(s)
  45.     {
  46.         var NT1 = {
  47.             "!":"!","\"":"”","#":"#","$":"$","%":"%","&":"&","'":"’","~":"~","|":"|",
  48.             "*":"*",":":":","<":"<",">":">","?":"?","/":"/","\\":"¥","`":"‘",",":",",
  49.             " ":" ","〜":"~","♡":"","♥":"",
  50.             "―":"-","─":"-","━":"-",
  51.             '卷':'巻','學':'学','黑':'黒','關':'関','繪':'絵','會':'会','亞':'亜','髙':'高'
  52.         };
  53.  
  54.         var NT2={
  55.             "&times;":"×","&amp;":"&","&nbsp;":" ","%u2019;":"’"
  56.         };
  57.         if (!s) return s;
  58.         var pat1 = new RegExp("["+y(NT1).join('')+"]","g");
  59.         var pat2 = new RegExp("("+y(NT2).join('|')+")","g");
  60.         return( s
  61.     //          .replace(/\u309B/g,"\u3099")
  62.     //          .replace(/\u309C/g,"\u309A")
  63.                 .normalize('NFKC')
  64.                 .replace(pat1,m=>(m in NT1?NT1[m]:m))
  65.                 .replace(pat2,m=>(m in NT2?NT2[m]:m))
  66.                 .replace(/([\]\)])([^\s\.\)\]])/g, '$1 $2')
  67.                 .replace(/([^ ])([\[\(])/g, '$1 $2')
  68.                 .replace(/  +/g," ")
  69.                 .replace(/\.\.+/,".")
  70.             );
  71.     }
  72.  
  73.     var repEverything=function(s)
  74.     {
  75.    
  76.         var t1 = '<a class="tag" href="';
  77.         var t2 = '"><span class=name>';
  78.         var t3 = '</span></a>'
  79.         return s
  80.             .replace(/([\]\)]) ?([^\[\]\(\) ]+)/, '$1 '+t1+search_prefix+'$2'+t2+'$2'+t3)
  81.             .replace(/^([^\[\( ]+)/, t1+search_prefix+'$1'+t2+'$1'+t3)
  82.             .replace(/\[([^\]\(]+)(?: *\(([^\)\(]+)\))?\]/g, function (m, s1, s2){
  83.                     var ret='[';
  84.                     var e1 = /×|&|,|、|//;
  85.                     var authors = s1.split(e1);
  86.                     for (var i=0;i<authors.length;i++)
  87.                     {
  88.                         if (1 <= i) ret+='×';
  89.                         ret+=t1+search_prefix+authors[i]+t2+authors[i]+t3;
  90.                     }
  91.                     if (s2)
  92.                     {
  93.                         ret+=' (';
  94.                         authors = s2.split(e1);
  95.                         for (var i=0;i<authors.length;i++)
  96.                         {
  97.                             if (1 <= i) ret+='×';
  98.                             ret+=t1+search_prefix+authors[i]+t2+authors[i]+t3;
  99.                         }
  100.                         ret+=')';
  101.                     }
  102.                     ret+=']';
  103.                     return ret;
  104.                 }
  105.             )
  106.             .replace(/\(([^\)\<\>]+)\)/g, t1+search_prefix+'$1'+t2+'($1)'+t3)
  107.             .replace(new RegExp("(href=\""+search_prefix+"[^\"]*)[!?。.、,]\">","g"),"$1\">");
  108.     }
  109.  
  110.     var tmp;
  111.  
  112.     // 前回までに挿入した要素があればリセット
  113.     if (tmp=Q("#X_l")) tmp.parentNode.remove();
  114.  
  115.     // 情報テキスト取得
  116.     tmp = Q("#tags").textContent;
  117.  
  118.     // ページ数からファイル名の桁数取得
  119.     var digit = 4 <= (tmp.match(/Pages:\s+(\d+)/))[1].length ? 4 : 3;
  120.  
  121.     // カテゴリ取得 Categories: doujinshi/manga/?
  122.     var categories = (tmp.match(/Categories:\s+([a-z]+)/i))[1];
  123.  
  124.     // タイトル取得、日本語名がなければ英語名
  125.     var tmp=Q("h2.title");
  126.     if (tmp===null) tmp=Q("h1.title");
  127.     var t = tmp.textContent.trim();
  128.  
  129.     // カテゴリ名を付与、先頭の配布イベント名は後方へやっておく
  130.     //if (t.indexOf("(同人")==-1)
  131.     if (!/^\(同人/.test(t))
  132.     {
  133.         // 先頭の括弧"(*****) ~~~~"を後方へ送る
  134.         var limit = t.length;
  135.         while (0 < limit)
  136.         {
  137.             if (tmp=t.match(/^(\([^\)\[]+\))\s*(.+?)(\s*\[[^\]\[]+\])*$/))
  138.             {
  139.                 t=tmp[2]+" "+tmp[1];
  140.                 if (tmp[3]) t+=" "+tmp[3].trim();
  141.                 limit -= tmp[1].length;
  142.             }
  143.             else
  144.                 break;
  145.         }
  146.         // 同人誌の場合のみ
  147.         if (categories=="doujinshi") t = "(同人誌) "+t;
  148.     }
  149.  
  150.     var buf="";
  151.     var r=/^https:\/\/t(\d+)(\.[^\/]+\/galleries\/)(\d+)\/(\d+)t(\.[^\/]+)$/;
  152.     var c=d.querySelectorAll("div.thumb-container");
  153.     for (var i=0;i<c.length;i++)
  154.     {
  155.         var w = Q("img", c[i]).getAttribute("data-src");
  156.         if (w)
  157.         buf+=w.replace(r,
  158.             (ma,m1,m2,m3,m4,m5)=>("https://i"+m1+m2+m3+"/"+m4+m5
  159.                 +"#"+jdp+"="+encodeURIComponent(normalizeTitle(t))+"&"+jdl+"="+zeroPadding(m4,digit)+(subfolder?('&'+subfolder):'')))
  160.             +"<br>\r\n";
  161.     }
  162.  
  163.     tmp = d.createElement('div');
  164.     tmp.style = "border:inset thin gray;margin:5pt;padding:5pt;background-color:#333;";
  165.     tmp.innerHTML = '<br><button onclick="document.getSelection().selectAllChildren(this.parentNode.querySelector(\'#X_l\'))"> 選択 </button> <button onclick="this.parentNode.remove()"> 閉じる </button><br><div id=X_t class="tag-container field-name title"><h3><span class="tags">'
  166.         + repEverything(normalizeTitle(t)) + "</span></h3></div><div id=X_l style=font-size:65%;width:100%;height:150px;overflow:scroll;>"
  167.         + buf + "</div>";
  168.     d.getElementById("bigcontainer").appendChild(tmp);
  169.     d.getSelection().selectAllChildren(Q("#X_l", tmp));
  170. })();
  171.  
  172.  
  173.  
  174. /*
  175.  
  176. 【パッケージャルール】
  177. ファイルに保存してパッケージャからインポート
  178.  
  179. url2name.packagizer (UTF-8)
  180. --------------------------[ ここから ]----------------------------------
  181. [
  182.     {
  183.         "name":"パッケージ名指定 \"#jdp=パッケージ名\"&...",
  184.         "sourceURLFilter":
  185.         {
  186.             "matchType":"CONTAINS",
  187.             "regex":"#.*?(?<=[#&])jdp=([^#&]+)",
  188.             "useRegex":true,
  189.             "enabled":true
  190.         },
  191.         "packageName":"<jd:source:1>",
  192.         "testUrl":"https://www.google.com/favicon.ico#jdl=my_filename_yade&jdp=my_packagename_desuyo","enabled":true
  193.     },
  194.     {
  195.         "name":"ファイル名指定 \"#...&jdl=ファイル名\"",
  196.         "sourceURLFilter":
  197.         {
  198.             "matchType":"CONTAINS",
  199.             "regex":"#.*?(?<=[#&])jdl=([^#&]+)",
  200.             "useRegex":true,
  201.             "enabled":true
  202.         },
  203.         "filename":"<jd:source:1>.<jd:orgfiletype>",
  204.         "testUrl":"https://www.google.com/favicon.ico#jdl=my_filename_yade&jdp=my_packagename_desuyo","enabled":true
  205.     },
  206.     {
  207.         "name":"パッケージ名でサブフォルダ作成 \"#...&subfolder=ON\" (\"パッケージ名指定\"ルールより下に置く、保存先は自分で変更)",
  208.         "sourceURLFilter":
  209.         {
  210.             "matchType":"CONTAINS",
  211.             "regex":"#.*?(?<=[#&])subfolder=ON",
  212.             "useRegex":true,
  213.             "enabled":true
  214.         },
  215.         "downloadDestination":"C:\\download\\<jd:packagename>",
  216.         "testUrl":"https://www.google.com/favicon.ico#jdl=my_filename_yade&jdp=my_packagename_desuyo&subfolder=ON","enabled":true
  217.     },
  218. ]
  219. --------------------------[ ここまで ]----------------------------------
  220.  
  221.  
  222. */
  223.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement