Skip to content

Instantly share code, notes, and snippets.

@kagekiyo7
Last active August 1, 2020 13:42
Show Gist options
  • Save kagekiyo7/8839a085d6feb052a927903057a81eb5 to your computer and use it in GitHub Desktop.
Save kagekiyo7/8839a085d6feb052a927903057a81eb5 to your computer and use it in GitHub Desktop.
amazonページから百合作品まとめWiki向けの表組みを出力するブックマークレット
javascript:
(() => {
try {
if (document.querySelector("textarea[name=_result]")) return;
const titleAndLavelReg = /^(.+)\s\((.+)\)\s?$/;
const title = // 「~シリーズ(x冊) のx冊目」表記から
document.querySelector("#reviewFeatureGroup>.a-size-small.a-color-secondary")?.childNodes?.[1]?.textContent
?? document.querySelector("#productTitle")?.innerText.match(titleAndLavelReg)?.[1]
?? document.querySelector("#productTitle")?.innerText;
const label = document.querySelector("#productTitle")?.innerText?.match(titleAndLavelReg)?.[2]
?? "";
function calcHeightRatio(imgUrl) {
if (!imgUrl) return;
const img = new Image();
img.src = imgUrl;
return img.height / img.width;
}
const imgUrl = document.querySelector(".a-dynamic-image.frontImage")?.src
?.replace(/^(https?:\/\/images-na\.ssl-images-amazon\.com\/images\/.\/.+?\.).+\.(.+)^/, "$1$2")
?? document.querySelector("#imgTagWrapperId>img")?.src
?? "";
const imgWidth = 180;
const imgHeight = Math.round(imgWidth * calcHeightRatio(imgUrl));
const amazonUrl = `https://www.amazon.co.jp/dp/${document.querySelector("input[name='ASIN'], input[name='ASIN.0']").value}`;
const author = // アンソロジー本 → "多数"
(/アンソロジー/.test(title) ? "多数" : null)
// 本
?? document.querySelector(".authorNameColumn")?.textContent?.replace(/[\r\n]/g, "")
// ゲーム
?? document.querySelector("#bylineInfo_feature_div>.a-section.a-spacing-none>.a-link-normal[href]")?.textContent
// 原作者がいる本
?? document.querySelector(".author.notFaded>.a-link-normal")?.textContent
   //document.querySelector(".author.notFaded>.a-declarative")?.textContent?.replace(/[\r\n]/g, "")
?? "";
const publisher = Array.from(document.querySelectorAll(".content>ul>li"))
?.filter((e)=>e.childNodes?.[0].innerText === "出版社:")?.[0]
?.childNodes?.[1]?.textContent?.match(/^\s(.+)\s\((.+)\)$/)?.[1]
?? document.querySelector("#bylineInfo_feature_div>.a-section.a-spacing-none>.a-link-normal[href]")?.textContent
?? "";
const description = //amazon下の方
document.querySelector(".a-section.a-spacing-small.a-padding-small")?.textContent
?.replace(/--このテキストは.+/, "").replace(/[\r\n]/g, "").replace(/$/, "&br;(公式あらすじより)")
//amazon上の方
?? document.querySelector("#bookDesc_iframe")?.contentWindow?.document?.querySelector("#iframeContent")?.textContent
?.replace(/\s+/g, "").replace(/$/, "&br;(公式あらすじより)")
?? "";
// 「~シリーズ(x冊) のx冊目」表記から
const volume = document.querySelector("#reviewFeatureGroup>.a-size-small.a-color-secondary")
?.childNodes?.[2]?.textContent?.match(/\((\d+)冊\)/)?.[1]
?? "1";
//ゲームのみ
const platform = document.querySelector("#platformInformation_feature_div")?.childNodes?.[2]?.textContent?.replace(/[\r\n]/g, "")
?? "";
//ゲームのみ
const date = Array.from(document.querySelectorAll(".content>ul>li"))
?.filter((e)=>e.childNodes?.[0]?.innerText === "発売日:")?.[0]
?.childNodes?.[1]?.textContent?.match(/^\s(.+)$/)?.[1]
?.replace("/", "年").replace("/", "月").replace(/$/, "日")
 ?? "";
const result = {
manga:
`***&size(15){${title}};
||CENTER:SIZE(15):50|SIZE(15):150|CENTER:SIZE(15):50|SIZE(15):150|CENTER:SIZE(15):50|SIZE(15):150|CENTER:SIZE(15):50|SIZE(15):150|c
|[[&ref(${imgUrl},${imgWidth}x${imgHeight});>${amazonUrl}]]|見所|>|>|>|>|>|>||
|~|原作者||漫画家|${author}|出版社|${publisher}|現況|${volume}巻|
|~|百合度|%|属性|>|>||掲載誌|${label}|
|~|備考|>|>|>|>|>|>||
|~|概略|>|>|>|>|>|>|${description}|
~
-------------------------------------------------------------------------------------`,
novel:
`***&size(15){${title}};
||CENTER:SIZE(15):50|SIZE(15):150|CENTER:SIZE(15):50|SIZE(15):150|CENTER:SIZE(15):50|SIZE(15):150|CENTER:SIZE(15):50|SIZE(15):300|c
|[[&ref(${imgUrl},${imgWidth}x${imgHeight});>${amazonUrl}]]|見所|>|>|>|>|>|>||
|~|作者|>|>|${author}|出版社|${publisher}|現況|${volume}巻|
|~|百合度|%|属性|>|>||レーベル|${label}|
|~|備考|>|>|>|>|>|>||
|~|概略|>|>|>|>|>|>|${description}|
~
--------------------------------------------------------------------------------------`,
game:
`***&size(15){${title}};
||CENTER:SIZE(15):50|SIZE(15):150|CENTER:SIZE(15):70|SIZE(15):150|CENTER:SIZE(15):50|SIZE(15):150|CENTER:SIZE(15):50|SIZE(15):130|c
|[[&ref(${imgUrl},${imgWidth}x${imgHeight});>${amazonUrl}]]|見所|>|>|>|>|>|>||
|~|原作|ゲーム|製作会社|${publisher}|機種|${platform}|発売日|${date}|
|~|百合度|%|属性|>|>|>|>||
|~|備考|>|>|>|>|>|>||
|~|概略|>|>|>|>|>|>|${description}|
~
-------------------------------------------------------------------------------------`
};
document.querySelector(".ja_JP").insertAdjacentHTML("beforebegin",
`<h1>結果</h1>
<textarea name="_result" readonly rows="10" cols="150">${result.manga}</textarea>
<button id="_copy" ">コピー</button>
<button id="_manga">漫画のフォーマットにする</button>
<button id="_novel">小説のフォーマットにする</button>
<button id="_game">ゲームのフォーマットにする</button>`);
function _copy() {
const text = document.querySelector("textarea[name=_result]");
text.select();
document.execCommand("copy");
}
function _switchTextarea() {
document.querySelector("textarea[name=_result]").textContent = this.text;
}
document.querySelector("#_copy").addEventListener("click", _copy);
document.querySelector("#_manga").addEventListener("click", {text: result.manga, handleEvent: _switchTextarea});
document.querySelector("#_novel").addEventListener("click", {text: result.novel, handleEvent: _switchTextarea});
document.querySelector("#_game").addEventListener("click", {text: result.game, handleEvent: _switchTextarea});
} catch (err) {
alert("エラーが発生しました。対応しないページもしくはページが読み込み中です。");
}
})();
javascript: (function(){try{var c,g,h,k,l,m,n,p,q,r,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,aa,ba,ca,da,ea,fa,ha,ia,ja,ka,la,ma,na,oa,pa,qa,ra,sa,ta,ua,va,wa=function(){document.querySelector("textarea[name=_result]").textContent=this.text};if(!document.querySelector("textarea[name=_result]")){var Ca=/^(.+)\s\((.+)\)\s?$/,d=null!==(c=null!==(g=null===(h=document.querySelector("#reviewFeatureGroup>.a-size-small.a-color-secondary"))||void 0===h?void 0:null===(k=h.childNodes)||void 0===k?void 0:null===(l=k[1])||void 0===l?void 0:l.textContent)&&void 0!==g?g:null===(m=document.querySelector("#productTitle"))||void 0===m?void 0:null===(n=m.innerText.match(Ca))||void 0===n?void 0:n[1])&&void 0!==c?c:null===(p=document.querySelector("#productTitle"))||void 0===p?void 0:p.innerText,e=null!==(q=null===(r=document.querySelector("#productTitle"))||void 0===r?void 0:null===(t=r.innerText)||void 0===t?void 0:null===(u=t.match(Ca))||void 0===u?void 0:u[2])&&void 0!==q?q:"",f=null!==(v=null!==(w=null===(x=document.querySelector(".a-dynamic-image.frontImage"))||void 0===x?void 0:null===(y=x.src)||void 0===y?void 0:y.replace(/^(https?:\/\/images-na\.ssl-images-amazon\.com\/images\/.\/.+?\.).+\.(.+)^/,"$1$2"))&&void 0!==w?w:null===(z=document.querySelector("#imgTagWrapperId>img"))||void 0===z?void 0:z.src)&&void 0!==v?v:"",xa=Math.round(180*function(b){if(b){var a=new Image;a.src=b;return a.height/a.width}}(f)),ya="https://www.amazon.co.jp/dp/"+document.querySelector("input[name='ASIN'], input[name='ASIN.0']").value,Da=null!==(A=null!==(B=null!==(C=null!==(D=/\u30a2\u30f3\u30bd\u30ed\u30b8\u30fc/.test(d)?"\u591a\u6570":null)&&void 0!==D?D:null===(E=document.querySelector(".authorNameColumn"))||void 0===E?void 0:null===(F=E.textContent)||void 0===F?void 0:F.replace(/[\r\n]/g,""))&&void 0!==C?C:null===(G=document.querySelector("#bylineInfo_feature_div>.a-section.a-spacing-none>.a-link-normal[href]"))||void 0===G?void 0:G.textContent)&&void 0!==B?B:null===(H=document.querySelector(".author.notFaded>.a-link-normal"))||void 0===H?void 0:H.textContent)&&void 0!==A?A:"",za=null!==(I=null!==(J=null===(K=Array.from(document.querySelectorAll(".content>ul>li")))||void 0===K?void 0:null===(L=K.filter(function(b){var a;return"\u51fa\u7248\u793e:"===(null===(a=b.childNodes)||void 0===a?void 0:a[0].innerText)}))||void 0===L?void 0:null===(M=L[0])||void 0===M?void 0:null===(N=M.childNodes)||void 0===N?void 0:null===(O=N[1])||void 0===O?void 0:null===(P=O.textContent)||void 0===P?void 0:null===(Q=P.match(/^\s(.+)\s\((.+)\)$/))||void 0===Q?void 0:Q[1])&&void 0!==J?J:null===(R=document.querySelector("#bylineInfo_feature_div>.a-section.a-spacing-none>.a-link-normal[href]"))||void 0===R?void 0:R.textContent)&&void 0!==I?I:"",Aa=null!==(S=null!==(T=null===(U=document.querySelector(".a-section.a-spacing-small.a-padding-small"))||void 0===U?void 0:null===(V=U.textContent)||void 0===V?void 0:V.replace(/--\u3053\u306e\u30c6\u30ad\u30b9\u30c8\u306f.+/,"").replace(/[\r\n]/g,"").replace(/$/,"&br;\uff08\u516c\u5f0f\u3042\u3089\u3059\u3058\u3088\u308a\uff09"))&&void 0!==T?T:null===(W=document.querySelector("#bookDesc_iframe"))||void 0===W?void 0:null===(X=W.contentWindow)||void 0===X?void 0:null===(Y=X.document)||void 0===Y?void 0:null===(Z=Y.querySelector("#iframeContent"))||void 0===Z?void 0:null===(aa=Z.textContent)||void 0===aa?void 0:aa.replace(/\s+/g,"").replace(/$/,"&br;\uff08\u516c\u5f0f\u3042\u3089\u3059\u3058\u3088\u308a\uff09"))&&void 0!==S?S:"",Ea=null!==(ba=null===(ca=document.querySelector("#reviewFeatureGroup>.a-size-small.a-color-secondary"))||void 0===ca?void 0:null===(da=ca.childNodes)||void 0===da?void 0:null===(ea=da[2])||void 0===ea?void 0:null===(fa=ea.textContent)||void 0===fa?void 0:null===(ha=fa.match(/\((\d+)\u518a\)/))||void 0===ha?void 0:ha[1])&&void 0!==ba?ba:"1",Fa=null!==(ia=null===(ja=document.querySelector("#platformInformation_feature_div"))||void 0===ja?void 0:null===(ka=ja.childNodes)||void 0===ka?void 0:null===(la=ka[2])||void 0===la?void 0:null===(ma=la.textContent)||void 0===ma?void 0:ma.replace(/[\r\n]/g,""))&&void 0!==ia?ia:"",Ga=null!==(na=null===(oa=Array.from(document.querySelectorAll(".content>ul>li")))||void 0===oa?void 0:null===(pa=oa.filter(function(b){var a,Ba;return"\u767a\u58f2\u65e5\uff1a"===(null===(a=b.childNodes)||void 0===a?void 0:null===(Ba=a[0])||void 0===Ba?void 0:Ba.innerText)}))||void 0===pa?void 0:null===(qa=pa[0])||void 0===qa?void 0:null===(ra=qa.childNodes)||void 0===ra?void 0:null===(sa=ra[1])||void 0===sa?void 0:null===(ta=sa.textContent)||void 0===ta?void 0:null===(ua=ta.match(/^\s(.+)$/))||void 0===ua?void 0:null===(va=ua[1])||void 0===va?void 0:va.replace("/","\u5e74").replace("/","\u6708").replace(/$/,"\u65e5"))&&void 0!==na?na:"";c="***&size(15){"+d+"};\n||CENTER:SIZE(15):50|SIZE(15):150|CENTER:SIZE(15):50|SIZE(15):150|CENTER:SIZE(15):50|SIZE(15):150|CENTER:SIZE(15):50|SIZE(15):150|c\n|[[&ref("+f+",180x"+xa+");>"+ya+"]]|\u898b\u6240|>|>|>|>|>|>||\n|~|\u539f\u4f5c\u8005||\u6f2b\u753b\u5bb6|"+Da+"|\u51fa\u7248\u793e|"+za+"|\u73fe\u6cc1|"+Ea+"\u5dfb|\n|~|\u767e\u5408\u5ea6|\uff05|\u5c5e\u6027|>|>||\u63b2\u8f09\u8a8c|"+e+"|\n|~|\u5099\u8003|>|>|>|>|>|>||\n|~|\u6982\u7565|>|>|>|>|>|>|"+Aa+"|\n~\n-------------------------------------------------------------------------------------";e="***&size(15){"+d+"};\n||CENTER:SIZE(15):50|SIZE(15):150|CENTER:SIZE(15):50|SIZE(15):150|CENTER:SIZE(15):50|SIZE(15):150|CENTER:SIZE(15):50|SIZE(15):300|c\n|[[&ref("+f+",180x"+xa+");>"+ya+"]]|\u898b\u6240|>|>|>|>|>|>||\n|~|\u4f5c\u8005|>|>|"+Da+"|\u51fa\u7248\u793e|"+za+"|\u73fe\u6cc1|"+Ea+"\u5dfb|\n|~|\u767e\u5408\u5ea6|\uff05|\u5c5e\u6027|>|>||\uff9a\uff70\uff8d\uff9e\uff99|"+e+"|\n|~|\u5099\u8003|>|>|>|>|>|>||\n|~|\u6982\u7565|>|>|>|>|>|>|"+Aa+"|\n~\n--------------------------------------------------------------------------------------";d="***&size(15){"+d+"};\n||CENTER:SIZE(15):50|SIZE(15):150|CENTER:SIZE(15):70|SIZE(15):150|CENTER:SIZE(15):50|SIZE(15):150|CENTER:SIZE(15):50|SIZE(15):130|c\n|[[&ref("+f+",180x"+xa+");>"+ya+"]]|\u898b\u6240|>|>|>|>|>|>||\n|~|\u539f\u4f5c|\u30b2\u30fc\u30e0|\u88fd\u4f5c\u4f1a\u793e|"+za+"|\u6a5f\u7a2e|"+Fa+"|\u767a\u58f2\u65e5|"+Ga+"|\n|~|\u767e\u5408\u5ea6|\uff05|\u5c5e\u6027|>|>|>|>||\n|~|\u5099\u8003|>|>|>|>|>|>||\n|~|\u6982\u7565|>|>|>|>|>|>|"+Aa+"|\n~\n-------------------------------------------------------------------------------------";document.querySelector(".ja_JP").insertAdjacentHTML("beforebegin",'<h1>\u7d50\u679c</h1>\n <textarea name="_result" readonly rows="10" cols="150">'+c+'</textarea>\n <button id="_copy" ">\u30b3\u30d4\u30fc</button>\n <button id="_manga">\u6f2b\u753b\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306b\u3059\u308b</button>\n <button id="_novel">\u5c0f\u8aac\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306b\u3059\u308b</button>\n <button id="_game">\u30b2\u30fc\u30e0\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306b\u3059\u308b</button>');document.querySelector("#_copy").addEventListener("click",function(){document.querySelector("textarea[name=_result]").select();document.execCommand("copy")});document.querySelector("#_manga").addEventListener("click",{text:c,handleEvent:wa});document.querySelector("#_novel").addEventListener("click",{text:e,handleEvent:wa});document.querySelector("#_game").addEventListener("click",{text:d,handleEvent:wa})}}catch(b){alert("\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u3002\u5bfe\u5fdc\u3057\u306a\u3044\u30da\u30fc\u30b8\u3082\u3057\u304f\u306f\u30da\u30fc\u30b8\u304c\u8aad\u307f\u8fbc\u307f\u4e2d\u3067\u3059\u3002")}})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment