Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Bookmarklet - nhentai 日本語タイトルJD2登録用リンク生成スクリプト
- //
- // サイトの個別ページ上でスクリプトを実行、生成されたURLリストをJD2に渡す
- // 日本語タイトルでパッケージ名を設定
- //
- // タグから検索、EveryThingのオプション → 全般 → es:URLプロトコルハンドラーをオン
- // Windowsの古い環境なので参考程度で
- //
- //
- // ※ 事前に一番下のパッケージャルールをインポートしておく
- // パッケージャルールのサブフォルダは、インポート後に自分の環境のDLパス名に変更しておく
- // (行末 \\<jd:packagename> は変えない)
- //
- //
- //-------------------------------------------------------------------------------------
- /*
- 【ブックマークレット】
- 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",
- "\u9ed1":"\u9ed2","\u95dc":"\u95a2","\u7e6a":"\u7d75","\u6703":"\u4f1a","\u4e9e":"\u4e9c","\u9ad9":"\u9ad8"},d={"×":"\u00d7","&":"\uff06"," ":" ","%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(/\.\.+/,
- ".")},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(\.[^\/]+)$/;
- 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">'+
- (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<=
- 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))})();
- */
- // ↑の短縮化前のコード
- (function(){
- var search_prefix='es:';
- var jdp="jdp";
- var jdl="jdl";
- var subfolder="subfolder=ON";
- var z=String.fromCharCode;
- var y=Object.keys;
- var d=document;
- window.Q=(a,b=d)=>b.querySelector(a);
- // 0埋め
- var zeroPadding=(s,l)=>((s.length<l?'0'.repeat(l-s.length):'')+s);
- var stripTag = s=>s.replace(/<[^>]*>/g,'');
- var normalizeTitle=function(s)
- {
- var NT1 = {
- "!":"!","\"":"”","#":"#","$":"$","%":"%","&":"&","'":"’","~":"~","|":"|",
- "*":"*",":":":","<":"<",">":">","?":"?","/":"/","\\":"¥","`":"‘",",":",",
- " ":" ","〜":"~","♡":"","♥":"",
- "―":"-","─":"-","━":"-",
- '卷':'巻','學':'学','黑':'黒','關':'関','繪':'絵','會':'会','亞':'亜','髙':'高'
- };
- var NT2={
- "×":"×","&":"&"," ":" ","%u2019;":"’"
- };
- if (!s) return s;
- var pat1 = new RegExp("["+y(NT1).join('')+"]","g");
- var pat2 = new RegExp("("+y(NT2).join('|')+")","g");
- return( s
- // .replace(/\u309B/g,"\u3099")
- // .replace(/\u309C/g,"\u309A")
- .normalize('NFKC')
- .replace(pat1,m=>(m in NT1?NT1[m]:m))
- .replace(pat2,m=>(m in NT2?NT2[m]:m))
- .replace(/([\]\)])([^\s\.\)\]])/g, '$1 $2')
- .replace(/([^ ])([\[\(])/g, '$1 $2')
- .replace(/ +/g," ")
- .replace(/\.\.+/,".")
- );
- }
- var repEverything=function(s)
- {
- var t1 = '<a class="tag" href="';
- var t2 = '"><span class=name>';
- var t3 = '</span></a>'
- return s
- .replace(/([\]\)]) ?([^\[\]\(\) ]+)/, '$1 '+t1+search_prefix+'$2'+t2+'$2'+t3)
- .replace(/^([^\[\( ]+)/, t1+search_prefix+'$1'+t2+'$1'+t3)
- .replace(/\[([^\]\(]+)(?: *\(([^\)\(]+)\))?\]/g, function (m, s1, s2){
- var ret='[';
- var e1 = /×|&|,|、|//;
- var authors = s1.split(e1);
- for (var i=0;i<authors.length;i++)
- {
- if (1 <= i) ret+='×';
- ret+=t1+search_prefix+authors[i]+t2+authors[i]+t3;
- }
- if (s2)
- {
- ret+=' (';
- authors = s2.split(e1);
- for (var i=0;i<authors.length;i++)
- {
- if (1 <= i) ret+='×';
- ret+=t1+search_prefix+authors[i]+t2+authors[i]+t3;
- }
- ret+=')';
- }
- ret+=']';
- return ret;
- }
- )
- .replace(/\(([^\)\<\>]+)\)/g, t1+search_prefix+'$1'+t2+'($1)'+t3)
- .replace(new RegExp("(href=\""+search_prefix+"[^\"]*)[!?。.、,]\">","g"),"$1\">");
- }
- var tmp;
- // 前回までに挿入した要素があればリセット
- if (tmp=Q("#X_l")) tmp.parentNode.remove();
- // 情報テキスト取得
- tmp = Q("#tags").textContent;
- // ページ数からファイル名の桁数取得
- var digit = 4 <= (tmp.match(/Pages:\s+(\d+)/))[1].length ? 4 : 3;
- // カテゴリ取得 Categories: doujinshi/manga/?
- var categories = (tmp.match(/Categories:\s+([a-z]+)/i))[1];
- // タイトル取得、日本語名がなければ英語名
- var tmp=Q("h2.title");
- if (tmp===null) tmp=Q("h1.title");
- var t = tmp.textContent.trim();
- // カテゴリ名を付与、先頭の配布イベント名は後方へやっておく
- //if (t.indexOf("(同人")==-1)
- if (!/^\(同人/.test(t))
- {
- // 先頭の括弧"(*****) ~~~~"を後方へ送る
- var limit = t.length;
- while (0 < limit)
- {
- if (tmp=t.match(/^(\([^\)\[]+\))\s*(.+?)(\s*\[[^\]\[]+\])*$/))
- {
- t=tmp[2]+" "+tmp[1];
- if (tmp[3]) t+=" "+tmp[3].trim();
- limit -= tmp[1].length;
- }
- else
- break;
- }
- // 同人誌の場合のみ
- if (categories=="doujinshi") t = "(同人誌) "+t;
- }
- var buf="";
- var r=/^https:\/\/t(\d+)(\.[^\/]+\/galleries\/)(\d+)\/(\d+)t(\.[^\/]+)$/;
- var c=d.querySelectorAll("div.thumb-container");
- for (var i=0;i<c.length;i++)
- {
- var w = Q("img", c[i]).getAttribute("data-src");
- if (w)
- buf+=w.replace(r,
- (ma,m1,m2,m3,m4,m5)=>("https://i"+m1+m2+m3+"/"+m4+m5
- +"#"+jdp+"="+encodeURIComponent(normalizeTitle(t))+"&"+jdl+"="+zeroPadding(m4,digit)+(subfolder?('&'+subfolder):'')))
- +"<br>\r\n";
- }
- tmp = d.createElement('div');
- tmp.style = "border:inset thin gray;margin:5pt;padding:5pt;background-color:#333;";
- 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">'
- + repEverything(normalizeTitle(t)) + "</span></h3></div><div id=X_l style=font-size:65%;width:100%;height:150px;overflow:scroll;>"
- + buf + "</div>";
- d.getElementById("bigcontainer").appendChild(tmp);
- d.getSelection().selectAllChildren(Q("#X_l", tmp));
- })();
- /*
- 【パッケージャルール】
- ファイルに保存してパッケージャからインポート
- url2name.packagizer (UTF-8)
- --------------------------[ ここから ]----------------------------------
- [
- {
- "name":"パッケージ名指定 \"#jdp=パッケージ名\"&...",
- "sourceURLFilter":
- {
- "matchType":"CONTAINS",
- "regex":"#.*?(?<=[#&])jdp=([^#&]+)",
- "useRegex":true,
- "enabled":true
- },
- "packageName":"<jd:source:1>",
- "testUrl":"https://www.google.com/favicon.ico#jdl=my_filename_yade&jdp=my_packagename_desuyo","enabled":true
- },
- {
- "name":"ファイル名指定 \"#...&jdl=ファイル名\"",
- "sourceURLFilter":
- {
- "matchType":"CONTAINS",
- "regex":"#.*?(?<=[#&])jdl=([^#&]+)",
- "useRegex":true,
- "enabled":true
- },
- "filename":"<jd:source:1>.<jd:orgfiletype>",
- "testUrl":"https://www.google.com/favicon.ico#jdl=my_filename_yade&jdp=my_packagename_desuyo","enabled":true
- },
- {
- "name":"パッケージ名でサブフォルダ作成 \"#...&subfolder=ON\" (\"パッケージ名指定\"ルールより下に置く、保存先は自分で変更)",
- "sourceURLFilter":
- {
- "matchType":"CONTAINS",
- "regex":"#.*?(?<=[#&])subfolder=ON",
- "useRegex":true,
- "enabled":true
- },
- "downloadDestination":"C:\\download\\<jd:packagename>",
- "testUrl":"https://www.google.com/favicon.ico#jdl=my_filename_yade&jdp=my_packagename_desuyo&subfolder=ON","enabled":true
- },
- ]
- --------------------------[ ここまで ]----------------------------------
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement