-
Notifications
You must be signed in to change notification settings - Fork 3
/
youngjump.js
1 lines (1 loc) · 13.3 KB
/
youngjump.js
1
(()=>{"use strict";function e(e=0){return new Promise((t=>setTimeout((()=>t()),e)))}function t(e){return document.querySelector(`#downloader-setting .downloader-helper-${e.replace(/\./g,".downloader-helper-")}`)}function n(e){return new Promise((t=>{const n=new XMLHttpRequest;n.open("GET",e),n.responseType="arraybuffer",n.onload=()=>t(n.response),n.send()}))}function o(e){const t=new DOMMatrix(e.style.transform);return{x:t.m41,y:t.m42,scale:t.m11}}const r=[],a=CanvasRenderingContext2D.prototype.drawImage;function i(){return r}new Set;let s=0,l=0;function d(){l=0}function c(){l=0,s++}function u(){s--,s<0&&(s=0),0===s&&d&&d()}const p=new WeakSet,h=[];function f(e){return h.some((t=>t instanceof RegExp?t.test(e):e.startsWith(t)))}!function(){const e=XMLHttpRequest.prototype.send,t=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(e,n,...o){return f(n)&&p.add(this),t.call(this,e,n,...o)},XMLHttpRequest.prototype.send=function(...t){return p.has(this)||c(),this.addEventListener("readystatechange",(()=>{4===this.readyState&&(p.has(this)||u())})),e.call(this,...t)}}();const g=new Set;window.addEventListener("message",(e=>{const t=e.data;t&&("request-end"===t.type&&g.has(t.requestId)?(g.delete(t.requestId),u()):"request-start"===t.type&&(g.add(t.requestId),c()))}),!1);const w=window.fetch;window.fetch=async function(e,...t){const n="string"==typeof e?e:e instanceof Request?e.url:e.href,o=w.call(this,e,...t);f(n)||(c(),o.finally((()=>u())));const r=await o;return["blob","arrayBuffer","text","json"].forEach((e=>{const t=Response.prototype[e];r[e]=function(){const e=t.call(this);return c(),e.finally((()=>u())),e}})),r},HTMLCanvasElement.prototype.toDataURL||window.bk_toDataURL;var v=Uint8Array,y=Uint16Array,m=Int32Array,b=new v([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),x=new v([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),E=(new v([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),function(e,t){for(var n=new y(31),o=0;o<31;++o)n[o]=t+=1<<e[o-1];var r=new m(n[30]);for(o=1;o<30;++o)for(var a=n[o];a<n[o+1];++a)r[a]=a-n[o]<<5|o;return{b:n,r}}),L=E(b,2),k=L.b,C=L.r;k[28]=258,C[258]=28;for(var S=E(x,0),q=(S.b,S.r,new y(32768)),M=0;M<32768;++M){var R=(43690&M)>>1|(21845&M)<<1;R=(61680&(R=(52428&R)>>2|(13107&R)<<2))>>4|(3855&R)<<4,q[M]=((65280&R)>>8|(255&R)<<8)>>1}var I=new v(288);for(M=0;M<144;++M)I[M]=8;for(M=144;M<256;++M)I[M]=9;for(M=256;M<280;++M)I[M]=7;for(M=280;M<288;++M)I[M]=8;var T=new v(32);for(M=0;M<32;++M)T[M]=5;var A=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],D=function(e,t,n){var o=new Error(t||A[e]);if(o.code=e,Error.captureStackTrace&&Error.captureStackTrace(o,D),!n)throw o;return o},H=new v(0),P=function(){for(var e=new Int32Array(256),t=0;t<256;++t){for(var n=t,o=9;--o;)n=(1&n&&-306674912)^n>>>1;e[t]=n}return e}(),U=function(e,t,n){for(;n;++t)e[t]=n,n>>>=8},z="undefined"!=typeof TextEncoder&&new TextEncoder,B="undefined"!=typeof TextDecoder&&new TextDecoder;try{B.decode(H,{stream:!0})}catch(e){}function X(e,t){if(t){for(var n=new v(e.length),o=0;o<e.length;++o)n[o]=e.charCodeAt(o);return n}if(z)return z.encode(e);var r,a,i,s=e.length,l=new v(e.length+(e.length>>1)),d=0,c=function(e){l[d++]=e};for(o=0;o<s;++o){if(d+5>l.length){var u=new v(d+8+(s-o<<1));u.set(l),l=u}var p=e.charCodeAt(o);p<128||t?c(p):p<2048?(c(192|p>>6),c(128|63&p)):p>55295&&p<57344?(c(240|(p=65536+(1047552&p)|1023&e.charCodeAt(++o))>>18),c(128|p>>12&63),c(128|p>>6&63),c(128|63&p)):(c(224|p>>12),c(128|p>>6&63),c(128|63&p))}return r=l,(null==(a=0)||a<0)&&(a=0),(null==(i=d)||i>r.length)&&(i=r.length),new v(r.subarray(a,i))}var W,$=function(e){var t=0;if(e)for(var n in e){var o=e[n].length;o>65535&&D(9),t+=o+4}return t},j=function(e,t,n,o,r,a,i,s){var l=o.length,d=n.extra,c=s&&s.length,u=$(d);U(e,t,null!=i?33639248:67324752),t+=4,null!=i&&(e[t++]=20,e[t++]=n.os),e[t]=20,t+=2,e[t++]=n.flag<<1|(a<0&&8),e[t++]=r&&8,e[t++]=255&n.compression,e[t++]=n.compression>>8;var p=new Date(null==n.mtime?Date.now():n.mtime),h=p.getFullYear()-1980;if((h<0||h>119)&&D(10),U(e,t,h<<25|p.getMonth()+1<<21|p.getDate()<<16|p.getHours()<<11|p.getMinutes()<<5|p.getSeconds()>>1),t+=4,-1!=a&&(U(e,t,n.crc),U(e,t+4,a<0?-a-2:a),U(e,t+8,n.size)),U(e,t+12,l),U(e,t+14,u),t+=16,null!=i&&(U(e,t,c),U(e,t+6,n.attrs),U(e,t+10,i),t+=14),e.set(o,t),t+=l,u)for(var f in d){var g=d[f],w=g.length;U(e,t,+f),U(e,t+2,w),e.set(g,t+4),t+=4+w}return c&&(e.set(s,t),t+=c),t},F=function(){function e(e){var t;this.filename=e,this.c=(t=-1,{p:function(e){for(var n=t,o=0;o<e.length;++o)n=P[255&n^e[o]]^n>>>8;t=n},d:function(){return~t}}),this.size=0,this.compression=0}return e.prototype.process=function(e,t){this.ondata(null,e,t)},e.prototype.push=function(e,t){this.ondata||D(5),this.c.p(e),this.size+=e.length,t&&(this.crc=this.c.d()),this.process(e,t||!1)},e}(),Y=function(){function e(e){this.ondata=e,this.u=[],this.d=1}return e.prototype.add=function(e){var t=this;if(this.ondata||D(5),2&this.d)this.ondata(D(4+8*(1&this.d),0,1),null,!1);else{var n=X(e.filename),o=n.length,r=e.comment,a=r&&X(r),i=o!=e.filename.length||a&&r.length!=a.length,s=o+$(e.extra)+30;o>65535&&this.ondata(D(11,0,1),null,!1);var l=new v(s);j(l,0,e,n,i,-1);var d=[l],c=function(){for(var e=0,n=d;e<n.length;e++){var o=n[e];t.ondata(null,o,!1)}d=[]},u=this.d;this.d=0;var p=this.u.length,h=function(e,t){var n={};for(var o in e)n[o]=e[o];for(var o in t)n[o]=t[o];return n}(e,{f:n,u:i,o:a,t:function(){e.terminate&&e.terminate()},r:function(){if(c(),u){var e=t.u[p+1];e?e.r():t.d=1}u=1}}),f=0;e.ondata=function(n,o,r){if(n)t.ondata(n,o,r),t.terminate();else if(f+=o.length,d.push(o),r){var a=new v(16);U(a,0,134695760),U(a,4,e.crc),U(a,8,f),U(a,12,e.size),d.push(a),h.c=f,h.b=s+f+16,h.crc=e.crc,h.size=e.size,u&&h.r(),u=1}else u&&c()},this.u.push(h)}},e.prototype.end=function(){var e=this;2&this.d?this.ondata(D(4+8*(1&this.d),0,1),null,!0):(this.d?this.e():this.u.push({r:function(){1&e.d&&(e.u.splice(-1,1),e.e())},t:function(){}}),this.d=3)},e.prototype.e=function(){for(var e=0,t=0,n=0,o=0,r=this.u;o<r.length;o++)n+=46+(l=r[o]).f.length+$(l.extra)+(l.o?l.o.length:0);for(var a=new v(n+22),i=0,s=this.u;i<s.length;i++){var l=s[i];j(a,e,l,l.f,l.u,-l.c-2,t,l.o),e+=46+l.f.length+$(l.extra)+(l.o?l.o.length:0),t+=l.b}var d,c,u,p,h;d=a,c=e,u=this.u.length,p=n,h=t,U(d,c,101010256),U(d,c+8,u),U(d,c+10,u),U(d,c+12,p),U(d,c+16,h),this.ondata(null,a,!0),this.d=2},e.prototype.terminate=function(){for(var e=0,t=this.u;e<t.length;e++)t[e].t();this.d=2},e}();function O(e,t){e.addEventListener("mousedown",(e=>e.stopPropagation())),e.addEventListener("click",(n=>{n.stopPropagation(),e.classList.contains("downloader-helper-disabled")||t()}))}"function"==typeof queueMicrotask?queueMicrotask:"function"==typeof setTimeout&&setTimeout,"booklive.jp"===location.host&&(window.onbeforeunload=function(){return"stop the page from reloading!"}),W=["/bib-api/bibUdtCntSetting"],h.push(...W),async function(o,r){!function(){if(location.hash.includes("debugCanvas")){const e=CanvasRenderingContext2D.prototype.drawImage;CanvasRenderingContext2D.prototype.drawImage=function(t,...n){return console.log("drawImage",this,t,n),e.call(this,t,...n)}}}(),await new Promise((e=>{"complete"===document.readyState||"interactive"===document.readyState?setTimeout((()=>e()),0):document.addEventListener("DOMContentLoaded",(()=>e()))}));const a=document.createElement("div");a.innerHTML='<div id="downloader-setting">\n <style>\n #downloader-setting {\n position: fixed;\n z-index: 99999;\n top: 0;\n right: 0;\n padding: 16px;\n margin: 12px;\n background: white;\n border-radius: 8px;\n box-shadow: 0 0 5px lightgray;\n color: black;\n }\n #downloader-setting img {\n width: 220px !important;\n }\n #downloader-setting div {\n padding: 6px 0;\n }\n #downloader-setting .downloader-helper-button,\n #downloader-setting .downloader-helper-checkbox {\n cursor: pointer;\n padding: 10px 15px;\n display: inline-block;\n }\n #downloader-setting .downloader-helper-button {\n border: 1px solid lightgray;\n }\n #downloader-setting .downloader-helper-button.downloader-helper-disabled {\n cursor: default;\n background-color: #E7E7E7;\n color: #BBB;\n }\n #downloader-setting .downloader-helper-checkbox > .downloader-helper-box {\n border: 1px solid grey;\n display: inline-block;\n width: 20px;\n height: 20px;\n margin-right: 8px;\n vertical-align: middle;\n }\n </style>\n <div>Captured images: <span class="downloader-helper-captureNum"></span></div>\n <div>Preview:<br /><img class="downloader-helper-preview" /></div>\n <div class="downloader-helper-buttons">\n <div class="downloader-helper-save-container">\n <div>\n <div class="downloader-helper-button downloader-helper-auto">Auto Download All</div>\n </div>\n <div>\n <div class="downloader-helper-button downloader-helper-auto-limit">Auto With Pages Limit</div>\n </div>\n </div>\n <div class="downloader-helper-l2r-container" style="display: none;">\n <div class="downloader-helper-checkbox downloader-helper-l2r">\n <div class="downloader-helper-box"></div>\n Left to Right\n </div>\n </div>\n <div>\n <div class="downloader-helper-button downloader-helper-download">Save</div>\n </div>\n </div>\n <div class="downloader-helper-auto-working" style="display: none">Automatically Downloading...</div>\n <div class="downloader-helper-progress" style="display:none">\n Compress: <span class="downloader-helper-current"></span> / <span class="downloader-helper-total"></span>\n </div>\n</div>\n',document.body.prepend(a);let d=null;const c=[0,0];async function u(n=1/0){t("buttons").style.display="none",t("auto-working").style.display="block",await async function(t,n){for(;;){if(l>=12||i().length>=n)return;if(await e(1e3),0===s)try{await t()&&(l=0),l++}catch(e){}}}(o,n),t("save-container").style.display="none",t("l2r-container").style.display="none",t("buttons").style.display="block",t("button.download").classList.remove("downloader-helper-disabled"),t("auto-working").style.display="none",document.body.style.pointerEvents=""}document.getElementById("downloader-setting").addEventListener("mousedown",(e=>{d=[e.pageX,e.pageY]})),window.addEventListener("mouseup",(()=>{d=null})),window.addEventListener("mousemove",(e=>{if(d){const t=[e.pageX,e.pageY];c[0]+=t[0]-d[0],c[1]+=t[1]-d[1],document.getElementById("downloader-setting").style.transform=`translate(${c[0]}px, ${c[1]}px)`,d=t}})),O(t("auto"),(()=>u())),O(t("auto-limit"),(()=>{const e=window.prompt("How many pages?","10");null!==e&&u(parseInt(e,10))}));const p=t("l2r");O(p,(()=>{const e=p.querySelector(".box");e.style.background=e.style.background?"":"darkblue"})),O(t("download"),(async()=>{t("button.download").classList.add("downloader-helper-disabled"),t("progress").style.display="inline-block",t("progress .total").textContent=i().length.toString(),t("progress .current").textContent="0";const e=await async function(e,o){return new Promise((o=>{const r=[],a=new Y(((e,t,n)=>{if(!e&&(r.push(t),n)){const e=window.URL.createObjectURL(new Blob(r));o(e)}})),i=`${e.length}`.length;(async()=>{for(let r=0;r<e.length;++r){const s=new F(`${(r+1).toString().padStart(i,"0")}.jpg`);a.add(s),s.push(new Uint8Array(await n(e[r])),!0),o=`${r+1}`,t("progress .current").textContent=o}var o;a.end()})()}))}(i()),o=document.createElement("a");o.href=e,o.download=document.title+".zip",o.click(),t("progress").style.display="none",r&&r(),t("button.download").classList.remove("downloader-helper-disabled")}))}((async()=>{const e=function(){const e=document.getElementById("content");return Array.from(e.querySelectorAll(":scope > div:not(.overswipe)")).find((t=>window.ViewerVersion<="01.6113"||t.style.left?t.offsetLeft+e.offsetLeft===0:0===o(t).x))}().querySelector(".pt-img");if(!e)return;let n=0,i=0;if(e.firstChild?.style.inset){const t=e.firstChild,o=e.querySelector("img");if(!o)return;const r=parseFloat(t.style.inset.split(" ")[2])/100;n=Math.round(o.naturalHeight/(1-r)),i=o.naturalWidth}else Array.from(e.children).forEach((e=>{const t=e.querySelector("img");if(!t)return;const r=o(t).scale;n=Math.round(o(e).y/r)+t.naturalHeight,i=t.naturalWidth}));const s=document.createElement("canvas");s.width=i,s.height=n;const l=s.getContext("2d");Array.from(e.children).forEach((e=>{const t=e.querySelector("img");if(t)if(e.style.inset){const o=parseFloat(e.style.inset.split(" ")[0])/100;l.drawImage(t,0,Math.round(n*o))}else{const n=o(t).scale;l.drawImage(t,0,Math.round(o(e).y/n))}})),async function(e){if(e.startsWith("data:image/png")){const t=await new Promise((t=>{const n=new Image;n.onload=()=>t(n),n.src=e})),n=document.createElement("canvas");n.width=t.naturalWidth,n.height=t.naturalHeight;const o=n.getContext("2d");a.call(o,t,0,0),e=n.toDataURL("image/jpeg",1)}for(let t=0;t<3;++t)if(r[r.length-1-t]===e)return!1;d(),r.push(e),t("captureNum").textContent=`${r.length}`,t("preview").src=e}(s.toDataURL("image/jpeg",1));const c=document.getElementById("content"),u=new PointerEvent("pointerdown",{clientX:19,clientY:474,cancelable:!0,pointerType:"mouse",bubbles:!0});c.dispatchEvent(u);const p=new PointerEvent("pointerup",{clientX:19,clientY:474,cancelable:!0,pointerType:"mouse",bubbles:!0});c.dispatchEvent(p)}))})();