// ==UserScript== // @name Pixiv View Util // @namespace Pixiv View Util // @description 閲覧専用のユーティリティです。(1)各イラストの閲覧ページや作者ごとの画像一覧ページのレイアウトを変更します。(2)pixivサイト内でポップアップ機能を有効化します。this is some utility funcitions for pixiv.(1)change the layout of illust pages and auther's pages. (2)add popup tool. // @author sotoba // @match https://www.pixiv.net/bookmark_new_illust.php* // @match https://www.pixiv.net/discovery* // @match https://www.pixiv.net/bookmark_detail.php?illust_id=* // @match https://www.pixiv.net/bookmark_add.php?id=* // @match https://www.pixiv.net/member_illust.php* // @match https://www.pixiv.net/ranking.php?mode=* // @match https://www.pixiv.net/member.php?id=* // @match https://www.pixiv.net/bookmark.php* // @match https://www.pixiv.net/search.php* // @match https://www.pixiv.net* // @version 0.5.10-20181019 // @homepageURL https://github.com/SotobatoNihu/PixivViewUtil // @license MIT License // @require https://code.jquery.com/jquery-3.2.1.min.js // @require https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.5/jszip.min.js // @resource gearIcon https://svgsilh.com/svg/24277.svg // @grant GM.getValue // @grant GM.setValue // @grant GM.getResourceUrl // @grant GM_getResourceText // @downloadURL none // ==/UserScript== (() => { /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { /******/ configurable: false, /******/ enumerable: true, /******/ get: getter /******/ }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 12); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /** * divやspan,imgなどのHTML要素を作るファクトリ */ Object.defineProperty(exports, "__esModule", { value: true }); class ContainerFactory { constructor() { this.id = ''; this.classname = ''; this.innerHtml = ''; this.innerText = ''; this.cssText = ''; } setId(idString) { this.id = idString; return this; } setClass(classname) { this.classname = classname; return this; } setLeft(x) { } setTop(y) { } setWitdh(w) { this.width = w; return this; } setInnerHtml(elem) { this.innerHtml = elem; return this; } setInnerText(elem) { this.innerText = elem; return this; } createDiv() { const elem = document.createElement('div'); elem.id = this.id; elem.className = this.classname; elem.innerHTML = this.innerHtml; elem.style.cssText = this.cssText; this.init(); return elem; } createImg() { const elem = document.createElement('img'); elem.id = this.id; elem.className = this.classname; elem.style.cssText = this.cssText; this.init(); return elem; } createSpan() { const elem = document.createElement('span'); elem.id = this.id; elem.className = this.classname; elem.innerHTML = this.innerHtml; elem.style.cssText = this.cssText; this.init(); return elem; } appendChild(infoElem) { this.appendChild(infoElem); return this; } setCSS(cssString) { this.cssText = cssString; return this; } init() { this.id = ''; this.classname = ''; this.innerHtml = ''; this.innerText = ''; this.cssText = ''; } } exports.ContainerFactory = ContainerFactory; /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const enum_1 = __webpack_require__(2); /** * 機能の有効/無効等の設定内容 * */ class Setting { constructor() { this.changeIllustPageLayout = true; this.changeMemberPageLayout = true; this.openComment = true; this.popup = true; this.popupScale = 0.7; } async init() { // @ts-ignore await GM.getValue("pixiv_viewutil_setting").then(jsonString => { if (jsonString !== undefined) { const jsonData = JSON.parse(jsonString); this.changeIllustPageLayout = (jsonData.changeIllustPageLayout == null) ? true : jsonData.changeIllustPageLayout; this.changeMemberPageLayout = (jsonData.changeMemberPageLayout == null) ? true : jsonData.changeMemberPageLayout; this.openComment = (jsonData.openComment == null) ? true : jsonData.openComment; this.popup = (jsonData.popup == null) ? true : jsonData.popup; this.popupScale = (jsonData.popupScale == null) ? 0.7 : jsonData.popupScale; } }); } set setStringData(jsonString) { const jsonData = JSON.parse(jsonString); this.changeIllustPageLayout = (jsonData.changeIllustPageLayout == null) ? true : jsonData.changeIllustPageLayout; this.changeMemberPageLayout = (jsonData.changeMemberPageLayout == null) ? true : jsonData.changeMemberPageLayout; this.openComment = (jsonData.openComment == null) ? true : jsonData.openComment; this.popup = (jsonData.popup == null) ? true : jsonData.popup; this.popupScale = (jsonData.popup == null) ? 0.7 : jsonData.popupScale; this.uiComponent = [enum_1.uiComponent.image, enum_1.uiComponent.manga, enum_1.uiComponent.ugoira, enum_1.uiComponent.caption]; } set setData(jsonData) { this.changeIllustPageLayout = (jsonData.changeIllustPageLayout == null) ? true : jsonData.changeIllustPageLayout; this.changeMemberPageLayout = (jsonData.changeMemberPageLayout == null) ? true : jsonData.changeMemberPageLayout; this.openComment = (jsonData.openComment == null) ? true : jsonData.openComment; this.popup = (jsonData.popup == null) ? true : jsonData.popup; this.popupScale = (jsonData.popup == null) ? 0.7 : jsonData.popupScale; } get getJsonString() { const obj = { changeIllustPageLayout: this.changeIllustPageLayout, changeMemberPageLayout: this.changeMemberPageLayout, openComment: this.openComment, popup: this.popup, popupScale: this.popupScale, }; return JSON.stringify(obj); } save() { // @ts-ignore GM.setValue("pixiv_viewutil_setting", this.getJsonString); } } exports.Setting = Setting; /***/ }), /* 2 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /** * 本プロジェクトで使用する各種列挙型 */ Object.defineProperty(exports, "__esModule", { value: true }); var prop; (function (prop) { prop[prop["changeIllustPageLayout"] = 0] = "changeIllustPageLayout"; prop[prop["changeMemberPageLayout"] = 1] = "changeMemberPageLayout"; prop[prop["popup_typeA"] = 2] = "popup_typeA"; prop[prop["popup_typeB"] = 3] = "popup_typeB"; prop[prop["openComment"] = 4] = "openComment"; })(prop = exports.prop || (exports.prop = {})); var uiComponent; (function (uiComponent) { uiComponent[uiComponent["image"] = 0] = "image"; uiComponent[uiComponent["manga"] = 1] = "manga"; uiComponent[uiComponent["ugoira"] = 2] = "ugoira"; uiComponent[uiComponent["caption"] = 3] = "caption"; })(uiComponent = exports.uiComponent || (exports.uiComponent = {})); var pagetype; (function (pagetype) { // my top page pagetype[pagetype["top"] = 0] = "top"; //Works from favourite artists pagetype[pagetype["bookmark_new_illust"] = 1] = "bookmark_new_illust"; //Discovery page pagetype[pagetype["discovery"] = 2] = "discovery"; //Artist works page pagetype[pagetype["member_illust"] = 3] = "member_illust"; //Artist's "top" page pagetype[pagetype["member"] = 4] = "member"; //Bookmark information pagetype[pagetype["bookmark_detail"] = 5] = "bookmark_detail"; //Added new bookmarks pagetype[pagetype["bookmark_add"] = 6] = "bookmark_add"; //Daily rankings pagetype[pagetype["ranking"] = 7] = "ranking"; //Someone's bookmarks page pagetype[pagetype["bookmark_id"] = 8] = "bookmark_id"; //Search page pagetype[pagetype["search"] = 9] = "search"; //Your bookmarks page pagetype[pagetype["bookmark"] = 10] = "bookmark"; pagetype[pagetype["other"] = 11] = "other"; })(pagetype = exports.pagetype || (exports.pagetype = {})); ; /***/ }), /* 3 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const enum_1 = __webpack_require__(2); const Illust_1 = __webpack_require__(10); const Manga_1 = __webpack_require__(9); const Ugoira_1 = __webpack_require__(8); const Caption_1 = __webpack_require__(6); const setting_1 = __webpack_require__(1); const ContainerFactory_1 = __webpack_require__(0); const jsonInterface_1 = __webpack_require__(5); const popupUtil_1 = __webpack_require__(4); /*** * 各種ユーティリティ関数 * ポップアップ機能に関するユーティリティ関数軍が長くなったため * popupUtilと外出しにしている */ class Util { constructor() { //あとで各要素やドキュメントに挿入するCSS文字列 this.outerContainerCSS = ` position:absolute; z-index:10000; background-color:#FFF; border: 1px solid black; max-width:${window.innerWidth}px; max-height:${window.innerHeight}px; `; this.captionContainerCSS = ` white-space:pre-wrap; z-index:10001; position:relative; width:auto; height:auto; display:none; max-width:${window.innerWidth}px; max-height:${window.innerHeight}px; background-color:white; word-wrap:break-word; word-break:break-all; `; this.gearCSS = `width: 25px; height: 25px; color:rgb(173, 173, 173); `; this.modalCSS = `.pixiv-modal { display: none; /* Hidden by default */ position: fixed; /* Stay in place */ z-index:10000; /* Sit on top */ left: 0; top: 0; width: 100%; /* Full width */ height: 100%; /* Full height */ overflow: auto; /* Enable scroll if needed */ background-color: rgb(0,0,0); /* Fallback color */ background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ } /* Modal Content/Box */ #pixiv-modal-content { background-color: #fefefe; margin: 15% auto; /* 15% from the top and centered */ padding: 20px; z-index:10001; border: 1px solid #888; width: 80%; /* Could be more or less, depending on screen size */ } /* The Close Button */ #pixiv-modal-close { color: #aaa; float: right; font-size: 28px; font-weight: bold; } #pixiv-modal-close :hover, #pixiv-modal-close :focus { color: black; text-decoration: none; cursor: pointer; } `; this.pixpediaItemCSS = `.popup-pixpedia-icon{ display: inline-block; margin-left: 2px; width: 15px; height: 14px; vertical-align: -2px; text-decoration: none; background: url(https://s.pximg.net/www/images/inline/pixpedia.png) no-repeat; } .popup-pixpedia-no-icon{ display: inline-block; margin-left: 2px; width: 15px; height: 14px; vertical-align: -2px; text-decoration: none; background: url(https://s.pximg.net/www/images/inline/pixpedia-no-item.png) no-repeat; } `; this.utilIcon = 'pixiv-view-util-gear'; } innerContainerCSS(scale) { return ` border: 5px solid black; background-color:#111; position:relative; width:100%; height:100%; float:left; max-width:${window.innerWidth * scale}px; max-height:${window.innerHeight * scale}px; `; } /** * とりあえずやっておくこと。 * 今いるページのタイプと、設定内容に応じて、レイアウトの修正やポップアップの用意を行う * トップ画面の場合は設定ダイアログも用意する * @param setting * @param page */ async initExecute(setting, page) { if (page.pagetype == enum_1.pagetype.top && document.getElementById(this.utilIcon) === null) { this.setConfigDialog(); } if (setting.popup && (page.isEnable(enum_1.prop.popup_typeA)) || page.isEnable(enum_1.prop.popup_typeB)) { this.setPopup(page, setting); console.log("set popup"); } } /** * 画面読み込み完了時に行うこと。initExecuteと同様 * @param setting * @param page */ onloadExecute(setting, page) { if (page.pagetype === enum_1.pagetype.top && document.getElementById('pixiv-view-util-gear') === null) { this.setConfigDialog(); } if (setting.changeIllustPageLayout && page.isEnable(enum_1.prop.changeIllustPageLayout)) { Util.changeIllustPageLayout(); console.log("layout chainged"); } if (setting.openComment && page.isEnable(enum_1.prop.openComment)) { this.openComment(page); console.log("comment opend"); } if (setting.changeMemberPageLayout && (page.pagetype === enum_1.pagetype.member || page.pagetype === enum_1.pagetype.member_illust)) { this.changeMemberPageLayout(); //読み込みに時間がかかるようなので時差を付ける for (let i = 0; i < 5; i++) { setTimeout(this.changeMemberPageLayout(), 1000 * i); } } } /** * URLに応じてpagetypeを返す * @param url */ static checkPageType(url) { if (url.match('https://www.pixiv.net/bookmark_new_illust.php?')) return enum_1.pagetype.bookmark_new_illust; if (url.match('https://www.pixiv.net/discovery?')) return enum_1.pagetype.discovery; if (url.match('https://www.pixiv.net/member_illust.php?')) return enum_1.pagetype.member_illust; if (url.match('https://www.pixiv.net/member.php?')) return enum_1.pagetype.member; if (url.match('https://www.pixiv.net/bookmark_detail.php?')) return enum_1.pagetype.bookmark_detail; if (url.match('https://www.pixiv.net/bookmark_add.php?')) return enum_1.pagetype.bookmark_add; if (url.match('https://www.pixiv.net/ranking.php?')) return enum_1.pagetype.ranking; if (url.match(/https:\/\/www\.pixiv\.net\/bookmark\.php\?id/)) return enum_1.pagetype.bookmark_id; if (url.match('https://www.pixiv.net/search.php')) return enum_1.pagetype.search; if (url.match('https://www.pixiv.net/bookmark.php?')) return enum_1.pagetype.bookmark; if (url.match('https://www.pixiv.net/')) return enum_1.pagetype.top; else return enum_1.pagetype.other; } ; /** * イラスト閲覧ページのレイアウトを修正する */ static changeIllustPageLayout() { $('figure').before($('figcaption')); } /** * そのページで可能な、本スクリプトが対象とする操作を返す * HTML要素に埋め込まれたURLの構造にはページに応じて2パターンあり、かつてはポップアップ機能はパターンごとに * 区別し実行していたためその名残でタイプA/Bが残っている * @param type */ static getAllowedFuncList(type) { switch (type) { case enum_1.pagetype.top: return [enum_1.prop.popup_typeB]; case enum_1.pagetype.bookmark_new_illust: return [enum_1.prop.popup_typeA]; case enum_1.pagetype.discovery: return [enum_1.prop.popup_typeA]; case enum_1.pagetype.member_illust: return [enum_1.prop.popup_typeB, enum_1.prop.changeIllustPageLayout, enum_1.prop.openComment]; case enum_1.pagetype.member: return [enum_1.prop.popup_typeB, enum_1.prop.changeMemberPageLayout]; case enum_1.pagetype.bookmark_detail: return [enum_1.prop.popup_typeB]; case enum_1.pagetype.bookmark_add: return [enum_1.prop.popup_typeB]; case enum_1.pagetype.bookmark_id: return [enum_1.prop.popup_typeB]; case enum_1.pagetype.search: return [enum_1.prop.popup_typeA]; case enum_1.pagetype.ranking: return [enum_1.prop.popup_typeB]; case enum_1.pagetype.bookmark: return [enum_1.prop.popup_typeB]; default: return []; } } /** * コメントを開く * @param page */ openComment(page) { if (page.getURL.indexOf('mode=medium') > 0) { let elem = $("article"); elem.find("[aria-expanded='false']").click(); var observer = new MutationObserver(function (MutationRecords, MutationObserver) { elem.find("[aria-expanded='false']").click(); }); observer.observe(document, { childList: true, subtree: true, }); } } /** * ポップアップ機能の用意を行う * @param page * @param setting */ setPopup(page, setting) { const popupUtil = new popupUtil_1.PopupUtil(); //IDやCSSなどをセットしたHTML要素を作成 const factory = new ContainerFactory_1.ContainerFactory(); //ポップアップの外枠となるouterContainer const outerContainer = factory .setId(Util.outerContainerID) .setClass(Util.popupClass) .setCSS(this.outerContainerCSS) .createDiv(); const innerContainer = factory .setId(Util.innerContainerID) .setClass(Util.popupClass) .setCSS(this.innerContainerCSS(setting.popupScale)) .createDiv(); const captionContainer = factory .setId(Util.captionContainerID) .setClass(Util.popupClass) .setCSS(this.captionContainerCSS) .createDiv(); outerContainer.appendChild(captionContainer); outerContainer.appendChild(innerContainer); document.body.appendChild(outerContainer); //ドキュメントにCSSを登録 const style = document.createElement('style'); style.textContent = this.pixpediaItemCSS; document.getElementsByTagName('head')[0].appendChild(style); // イラスト&漫画のクリックイベントを登録する $('body').on('mouseenter', 'a[href*="member_illust.php?mode=medium&illust_id="]', function () { //クリック対象とhrefがある要素の入れ子関係は2パターン以上あるため注意 const thumb = $(this).find('.non-trim-thumb'); const clickElem = thumb.length > 0 ? thumb[0] : this; //イラストの本来のクリックによる遷移を抑制 $(this).attr('onclick', 'console.log();return false;'); //漫画の本来のクリックによる遷移を抑制 $(this).find('.non-trim-thumb').attr('onclick', 'console.log();return false;'); const hrefElem = this; const url = this.getAttribute("href"); //イラストIDを取得 const matches = url.match(/(.)+illust_id=([0-9]+)(&.+)?/); const illustID = Number(matches[2]); //ポップアップを実行 $(clickElem).on('click', async function (e) { outerContainer.style.display = 'block'; //イラストIDを元にJSONを入手 await fetch(`https://www.pixiv.net/ajax/illust/${illustID}`, { method: 'GET', mode: 'cors', keepalive: true }).then(function (response) { if (response.ok) { return response.json(); } }).then(async function (json) { //pixivJsonオブジェクトに格納 const pixivJson = new jsonInterface_1.PixivJson(json); //漫画のポップアップを実行 if (Util.isManga(pixivJson)) { const manga = new Manga_1.Manga(pixivJson); manga.setInnerContainer(innerContainer); manga.setClassName(Util.popupClass); manga.popup($(hrefElem).hasClass("on")); // popupUtil.popupManga(innerContainer,Util.popupClass); outerContainer.style.width = innerContainer.style.maxWidth; outerContainer.style.height = innerContainer.style.maxHeight; } else if (Util.isIllust(pixivJson)) { const illust = new Illust_1.Illust(page, innerContainer, pixivJson); //イラストのポップアップを実行 illust.setInnerContainer(innerContainer); illust.setClassName(Util.popupClass); illust.popup($(hrefElem).hasClass("on")); illust.resize(outerContainer, setting.popupScale); } else { //うごイラのポップアップを実行 //うごイラのメタ情報のJSONを入手 await fetch(`https://www.pixiv.net/ajax/illust/${pixivJson.body.illustId}/ugoira_meta`) .then(function (response) { return response.json(); }).then(async (metajson) => { const ugoira = new Ugoira_1.Ugoira(pixivJson, new jsonInterface_1.PixivJson(metajson)); ugoira.setInnerContainer(innerContainer); //ugoira.setClassName(Util.popupClass) await ugoira.set().then(() => { ugoira.resize(outerContainer, setting.popupScale); ugoira.popup(); }); }); } //キャプションのポップアップを実行 const caption = new Caption_1.Caption(pixivJson); caption.setCaptionContainer(captionContainer); caption.setInnerContainer(innerContainer); caption.setClassName(Util.popupClass); //manga.set caption.popup(); caption.adjust(outerContainer); Util.addMouseMove(outerContainer); }); }); }); window.onresize = function () { outerContainer.style.maxWidth = `${window.innerWidth * setting.popupScale}px`; }; } isIllust(json) { return json.body.illustType === 0; } isManga(json) { return json.body.illustType === 1 || (json.body.pageCount && Number(json.body.pageCount) > 1); } isUgoira(json) { return json.body.illustType === 2; } static getUserID(json) { return json.body.tags.authorId; } static getPageNum(json) { return Number(json.body.pageCount); } /** * 設定ダイアログを用意する */ async setConfigDialog() { const iconID = this.utilIcon; const iconElem = document.getElementById(this.utilIcon); if (iconElem === null) { await this.setIconElem(iconID); await this.setModal(iconID); } } /** * 設定アイコンをトップページにセットする * @param iconID */ async setIconElem(iconID) { // @ts-ignore const gearIcon = await GM_getResourceText('gearIcon'); const factory = new ContainerFactory_1.ContainerFactory(); const gearElem = factory .setId(iconID) .setCSS(this.gearCSS) .setInnerHtml(gearIcon) .createDiv(); gearElem.className = 'trigger'; const svgTag = gearElem.getElementsByTagName('svg')[0]; const gTag = gearElem.getElementsByTagName('g')[0]; svgTag.setAttribute('width', '25'); svgTag.setAttribute('height', '25'); gTag.setAttribute('fill', '#BECAD8'); const liElem = document.createElement('li'); liElem.className = 'viewUtil'; liElem.appendChild(gearElem); document.body.getElementsByClassName('notifications')[0].appendChild(liElem); } /** * ダイアログ(モーダル)をセットする * @param iconID */ setModal(iconID) { const setting = new setting_1.Setting; const iconElem = document.getElementById(iconID); const modal1 = document.createElement('div'); modal1.innerHTML = `
OK

Setting:

Modify the illust page's layout
Modify the author page's layout
Use popup function
`; document.body.appendChild(modal1); // 各modalクラスのcssを追加 const style = document.createElement('style'); style.textContent = this.modalCSS; document.getElementsByTagName('head')[0].appendChild(style); //各種クリックイベントを追加 const modal = document.getElementById('myModal'); const closeButton = document.getElementById('pixiv-modal-close'); iconElem.onclick = () => modal.style.display = 'block'; const elem1 = document.getElementsByName('pixivutil-setting1')[0]; const elem2 = document.getElementsByName('pixivutil-setting2')[0]; const elem3 = document.getElementsByName('pixivutil-setting3')[0]; setting.init().then(() => { // @ts-ignore if (setting.changeIllustPageLayout && !elem1.checked) elem1.checked = true; // @ts-ignore if (setting.changeMemberPageLayout && !elem2.checked) elem2.checked = true; // @ts-ignore if (setting.popup && !elem3.checked) elem3.checked = true; }); /** * モーダルを閉じたときに設定を保存 */ closeButton.onclick = () => { modal.style.display = 'none'; // @ts-ignore setting.changeIllustPageLayout = elem1.checked; // @ts-ignore setting.changeMemberPageLayout = elem2.checked; // @ts-ignore setting.popup = elem3.checked; setting.save(); }; //modal画面の余白をクリックした場合 window.onclick = function (event) { if (event.target == modal) { modal.style.display = "none"; } }; } changeMemberPageLayout() { // TODO もっと良い方法 const h2Elems = document.getElementsByTagName('h2'); if (typeof h2Elems !== 'undefined') { for (const h2elem of h2Elems) { if (h2elem.innerText.startsWith('イラスト')) { const illustElem = h2elem.parentElement.parentElement; const header = document.getElementsByTagName('header')[0]; const parent = header.parentNode; parent.insertBefore(illustElem, header.nextSibling); break; } } } } static isIllust(pixivJson) { return pixivJson.body.illustType === 0; } static isManga(pixivJson) { return pixivJson.body.illustType === 1 || (pixivJson.body.pageCount && Number(pixivJson.body.pageCount) > 1); } static isUgoira(pixivJson) { return pixivJson.body.illustType === 2; } static addMouseMove(elm) { let pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0; let dragging = false; const elementDrag = (e) => { dragging = true; e = e || window.event; e.preventDefault(); // calculate the new cursor position: pos1 = pos3 - e.clientX; pos2 = pos4 - e.clientY; pos3 = e.clientX; pos4 = e.clientY; // set the element's new position: elm.style.top = (elm.offsetTop - pos2) + "px"; elm.style.left = (elm.offsetLeft - pos1) + "px"; }; const closeDragElement = () => { // stop moving when mouse button is released: document.onmouseup = null; document.onmousemove = null; if (!dragging) { this.cleanContainer(elm); } dragging = false; }; const dragMouseDown = (e) => { e = e || window.event; e.preventDefault(); // get the mouse cursor position at startup: pos3 = e.clientX; pos4 = e.clientY; document.onmouseup = closeDragElement; // call a function whenever the cursor moves: document.onmousemove = elementDrag; }; elm.onmousedown = dragMouseDown; elm.onmouseleave = () => { this.cleanContainer(elm); }; } static cleanContainer(outerContainer) { const innerContainer = document.getElementById(this.innerContainerID); const captionContainer = document.getElementById(this.captionContainerID); innerContainer.innerText = ''; captionContainer.innerText = ''; outerContainer.style.display = 'none'; } } Util.innerContainerID = 'popup-inner-container'; Util.outerContainerID = 'popup-outer-container'; Util.captionContainerID = 'popup-caption-container'; Util.popupClass = 'popup-util'; exports.Util = Util; /***/ }), /* 4 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * ポップアップ機能用のユーティリティツール群 * */ class PopupUtil { } exports.PopupUtil = PopupUtil; /***/ }), /* 5 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /** * Jsonをパースするときに使用する各種Json用クラス * http://json2ts.com/で自動生成 * */ Object.defineProperty(exports, "__esModule", { value: true }); class PixivJson { constructor(json) { Object.assign(this, json); } } exports.PixivJson = PixivJson; /***/ }), /* 6 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ContainerFactory_1 = __webpack_require__(0); /** * html上のページごとのイラスト情報を管理する */ class Caption { constructor(pixivJson) { this.captionContainerID = 'popup-caption-container'; this.captionDescriptionID = 'popup-caption-text'; this.captionTagID = 'popup-caption-tag'; this.captionDateID = 'popup-caption-date'; this.captionLikeID = 'popup-caption-like'; this.captionBookmarkID = 'popup-caption-bookmark'; this.captionViewID = 'popup-caption-view'; this.captionInfoID = 'popup-caption-infomation'; this.likeIcon = ``; this.bookmarkIcon = ``; this.viewIcon = ``; this.captionContainerCSS = ` white-space:pre-wrap; z-index:10001; position:relative; width:auto; height:auto; max-width:${window.innerWidth}px; max-height:${window.innerHeight}px; background-color:white; word-wrap:break-word; word-break:break-all; `; this.descriptionContainerCSS = `font-size: normal; width: auto; height:auto; overflow-y:scroll;`; this.infoContainerCSS = ` background-color:white; font-size:xx-small; width: auto; color:rgb(173, 173, 173); line-height=1;`; this.pixivJson = pixivJson; } /** * キャプションをポップアップする * テキスト、タグ、その他情報(ブックマーク等)を,それぞれelementを用意しコンテナとして箱詰めし、innerContainerに付与する * @param innerContainer * @param json */ popup() { const captionContainer = this.captionContainer; const innerContainer = this.innerContainer; const json = this.pixivJson; //既存のキャプションコンテナがあれば破棄 captionContainer.innerText = ''; //テキストコンテナを作成 const factory = new ContainerFactory_1.ContainerFactory(); const descriptionElem = factory.setId(this.captionDescriptionID) .setClass(this.className) .setCSS(this.descriptionContainerCSS) .setInnerHtml(json.body.description) .createDiv(); const tagElem = factory.setId(this.captionTagID) .setClass(this.className) .createDiv(); tagElem.appendChild(this.getTagHtml(json)); //投稿日 const date = new Date(json.body.createDate); const dateString = `upload:${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()} ${date.getHours()}:${String(date.getMinutes()).padStart(2, "0")}`; const dateElem = factory.setId(this.captionDateID).setInnerHtml(dateString).createDiv(); //like数 const likeString = `${this.likeIcon} ${json.body.likeCount} `; const likeElem = factory.setId(this.captionLikeID).setClass(this.className).setInnerHtml(likeString).createSpan(); //ブックマーク数 const bookmarkString = `${this.bookmarkIcon} ${json.body.bookmarkCount} `; const bookmarkElem = factory.setId(this.captionBookmarkID).setClass(this.className).setInnerHtml(bookmarkString).createSpan(); //閲覧数 const viewString = `${this.viewIcon}${json.body.viewCount}`; const viewElem = factory.setId(this.captionViewID).setClass(this.className).setInnerHtml(viewString).createSpan(); //infoコンテナに各elementを詰める const infoElem = factory .setId(this.captionInfoID) .setClass(this.className) .setCSS(this.infoContainerCSS) .createDiv(); infoElem.appendChild(dateElem); infoElem.appendChild(likeElem); infoElem.appendChild(bookmarkElem); infoElem.appendChild(viewElem); //キャプション用コンテナにテキストコンテナとinfoコンテナを詰める captionContainer.appendChild(descriptionElem); captionContainer.appendChild(tagElem); captionContainer.appendChild(infoElem); this.descriptionElem = descriptionElem; this.tagElem = tagElem; this.infoElem = infoElem; captionContainer.style.display = 'block'; } /** * タグ情報を格納したHTMLelementを作成する */ getTagHtml(json) { let outerTagElem = document.createElement('ul'); // @ts-ignore outerTagElem.style.paddingInlineStart = '0px'; //outerTagElem.setAttribute('align','left') for (const tagJson of json.body.tags.tags) { let iconElem = document.createElement('a'); iconElem.className = `${tagJson.romaji || tagJson.locked ? "popup-pixpedia-icon" : "popup-pixpedia-no-icon"}`; iconElem.setAttribute('href', `https://dic.pixiv.net/a/${tagJson.tag}`); let innerTagElem = document.createElement('li'); innerTagElem.innerHTML = ` ${tagJson.locked ? "" : ""}${tagJson.tag}`; innerTagElem.style.cssText = 'display: inline-block;'; innerTagElem.appendChild(iconElem); outerTagElem.appendChild(innerTagElem); } return outerTagElem; } setInnerContainer(innerContainer) { this.innerContainer = innerContainer; } setClassName(className) { this.className = className; } adjust(outerContainer) { //画面の表示調節を行う // const innerContainer: HTMLElement=document.getElementById(this.innerContainerID) // const outerContainer: HTMLElement=document.getElementById(this.outerContainerID) // const captionContainer=document.getElementById(this.captionContainerID) /// const descriptionContainer:HTMLElement=document.getElementById(this.captionDescriptionID) // const tagContainer:HTMLElement=document.getElementById(this.captionTagID) // const infoContainer:HTMLElement=document.getElementById(this.captionInfoID) if (this.descriptionElem.clientHeight > 100) { this.descriptionElem.style.height = `${100}px`; } const offset = this.getOffset(outerContainer); outerContainer.style.left = `${offset.left}px`; outerContainer.style.top = `${offset.top}px`; this.captionContainer.style.width = `${outerContainer.offsetWidth + 10}px`; } /** * 大きさがあるHTMLelementを引数に、それが画面の中央に表示されるようになるelementのtop・leftの値を返す * @param elem */ getOffset(elem) { const w_height = $(window).height(); const w_width = $(window).width(); const el_height = $(elem).height(); const el_width = $(elem).width(); const scroll_height = $(window).scrollTop(); const position_h = scroll_height + (w_height - el_height) / 2; const position_w = (w_width - el_width) / 2; return { top: Math.round(position_h), left: Math.round(position_w) }; } adjustCaption() { } setCaptionContainer(captionContainer) { this.captionContainer = captionContainer; } } exports.Caption = Caption; /***/ }), /* 7 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class Frame { constructor() { //imageElement配列 this.imgArray = []; //imageElementのsrc文字列の配列 this.imgStringArray = []; //フレーム情報(ミリ秒単位の変更間隔)の配列 this.frameArray = []; } pushDelay(delay) { this.frameArray.push(delay); } pushImgString(imgString) { this.imgStringArray.push(imgString); } } exports.Frame = Frame; /***/ }), /* 8 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Frame_1 = __webpack_require__(7); const ContainerFactory_1 = __webpack_require__(0); /** * うごイラ管理用オブジェクト */ class Ugoira { constructor(pixivJson, ugoiraMetaJson) { this.ugoiraContainerID = 'popup-ugoira'; this.pixivJson = pixivJson; this.ugoiraMetaJson = ugoiraMetaJson; } async set() { const innerContainer = this.innerContainer; let finished = false; const factory = new ContainerFactory_1.ContainerFactory(); innerContainer.textContent = null; const canvas = document.createElement('canvas'); canvas.id = this.ugoiraContainerID; canvas.className = this.className; this.ugoiraContainer = canvas; innerContainer.appendChild(canvas); let myHeaders = new Headers(); myHeaders.append("Accept-Encoding", "gzip, deflate, br"); myHeaders.append("Connection", 'keep-alive'); myHeaders.append("HOST", "www.pixiv.net"); const myInit = { method: 'GET', headers: myHeaders, mode: 'same-origin', credentials: 'same-origin', cache: 'default' }; // @ts-ignore let zip = new JSZip(); //const ugoira = new Ugoira() const frames = this.ugoiraMetaJson.body.frames; // const ImgElem: HTMLImageElement = document.createElement('img') const frameData = new Frame_1.Frame(); const zipData = await fetch(this.ugoiraMetaJson.body.src, { method: 'GET', headers: myHeaders, mode: 'cors', keepalive: true }).then(response => { if (response.ok) { return response.blob(); } }).then(async (zipData) => { await zip.loadAsync(zipData, { base64: true }); }).then(async () => { for (let frame of frames) { frameData.pushDelay(frame.delay); //let frameArray:number[] = Ugoira.frameArray // frameArray.push(frame.delay) await zip.file(frame.file) .async("base64", function updateCallback(metadata) { console.log("progression: " + metadata.percent.toFixed(2) + " %"); if (metadata.percent === 100) { finished = true; } }) .then(function success(content) { // pushImgString(`data:image/jpeg;base64,${content}`) frameData.pushImgString(`data:image/jpeg;base64,${content}`); //Ugoira.imgStringArray.push(`data:image/jpeg;base64,${content}`) }, function error(e) { console.log("download error."); }); } }).then(() => { this.frameData = frameData; }); } /* static pushImgElem(elem: HTMLImageElement) { Util.imgArray.push(elem) } */ /* static pushImgString(s: string) { this.imgStringArray.push(s) } static pushFrame(num: number) { this.frameArray.push(num) } get getImgArray() { return this.imgArray } static getImgStringArray() { return this.imgStringArray } get getFrameArray() { return Ugoira.frameArray } get getFrameNum(): number { return Ugoira.imgArray.length } //フレーム情報の合計 get getIntervalSum(): number { return Ugoira.frameArray.length > 1 ? Ugoira.frameArray.reduce((x, y) => x + y) : 0 } */ setInnerContainer(innerContainer) { this.innerContainer = innerContainer; } /* setClassName(className: string) { this.ugoiraContainer.className = className } */ /* private resize(width: number, height: number,scale:number) { let newHeight:number = height let newWidth:number = width if (height > window.innerHeight * scale || width > window.innerWidth * scale) { const heightScale =height / Number(window.innerHeight * scale) const widthScale = width / Number(window.innerWidth * scale) if (heightScale > widthScale) { newHeight /= heightScale newWidth /= heightScale } else { newHeight /= widthScale newWidth /=widthScale } } return {width: Math.round(newWidth), height: Math.round(newHeight)} } */ resize(outerContainer, scale) { const oldWidth = this.pixivJson.body.width; const oldHeight = this.pixivJson.body.height; let newWidth = oldHeight; let newHeight = oldWidth; if (oldHeight > window.innerHeight * scale || oldWidth > window.innerWidth * scale) { const heightScale = oldHeight / Number(window.innerHeight * scale); const widthScale = oldWidth / Number(window.innerWidth * scale); if (heightScale > widthScale) { newHeight /= heightScale; newWidth /= heightScale; } else { newHeight /= widthScale; newWidth /= widthScale; } } this.ugoiraContainer.width = newWidth; this.ugoiraContainer.height = newHeight; outerContainer.style.width = `${Math.round(newWidth)}px`; outerContainer.style.height = `${Math.round(newHeight)}px`; } popup() { const frameArray = this.frameData.frameArray; const stringArray = this.frameData.imgStringArray; let index = 0; const counter = () => { index += 1; index = index === stringArray.length ? 0 : index; const img = new Image(); img.src = stringArray[index]; const context = this.ugoiraContainer.getContext('2d'); //座標(10, 10)の位置にイメージを表示 context.drawImage(img, 0, 0, this.ugoiraContainer.clientWidth, this.ugoiraContainer.clientHeight); setTimeout(counter, frameArray[index]); }; counter(); } } //imageElement配列 Ugoira.imgArray = []; //imageElementのsrc文字列の配列 Ugoira.imgStringArray = []; exports.Ugoira = Ugoira; /***/ }), /* 9 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ContainerFactory_1 = __webpack_require__(0); /** * html上のページごとの漫画情報を管理する */ class Manga { constructor(pixivJson) { this.mangaContainerID = 'popup-manga'; this.pageNum = 0; //elementのcss this.mangaContainerCSS = ` background-color:black; overflow-x:auto; white-space:nowrap; width: auto; height:auto; left: 0; top: 0; `; this.pixivJson = pixivJson; this.pageNum = this.getPageNum(pixivJson); this.imgArray = new Array(this.pageNum); const factory = new ContainerFactory_1.ContainerFactory(); this.mangaContainer = factory.setId(this.mangaContainerID) .setClass(this.className) .setCSS(this.mangaContainerCSS) .createDiv(); this.DELTASCALE = ('mozInnerScreenX' in window) ? 70 : 4; } /** * 漫画をポップアップする * @param innerContainer * @param hrefElem * @param json * @param count */ popup(hasClass) { this.innerContainer.innerHTML = ''; const firstPageURL = this.getImgUrl(); //各ページをセット this.initImgArray(this.mangaContainer, firstPageURL); this.innerContainer.style.backgroundColor = (hasClass) ? "rgb(255, 64, 96)" : "rgb(34, 34, 34)"; this.innerContainer.appendChild(this.mangaContainer); this.setScrool(this.mangaContainer, this.innerContainer, this.DELTASCALE); } /** * imgエレメントの配列を作成し漫画の各ページを格納 * @param innerContainer * @param mangaContainer * @param manga * @param primaryLink * @param pageNum */ initImgArray(mangaContainer, firstPageURL) { for (let i = 0; i < this.pageNum; i++) { const imgElem = document.createElement('img'); imgElem.src = firstPageURL.replace('p0', 'p' + i); imgElem.style.maxWidth = this.innerContainer.style.maxWidth; imgElem.style.maxHeight = this.innerContainer.style.maxHeight; imgElem.style.height = this.innerContainer.style.maxHeight; imgElem.style.width = 'auto'; this.imgArray.push(imgElem); mangaContainer.appendChild(imgElem); } } /** * mangaコンテナ上でスクロール機能を実現 * @param innerContainer * @param mangaContainer * @param manga */ setScrool(mangaContainer, innerContainer, deltaScale) { this.mangaContainer.onwheel = function (e) { if (e.deltaY < 0 && (innerContainer.getBoundingClientRect().top < 0)) { innerContainer.scrollIntoView({ block: "start", behavior: "smooth" }); //aligning to top screen side on scrollUp if needed } else if (e.deltaY > 0 && (innerContainer.getBoundingClientRect().bottom > document.documentElement.clientHeight)) { innerContainer.scrollIntoView({ block: "end", behavior: "smooth" }); //aligning to bottom screen side on scrollDown if needed } let scrlLft = mangaContainer.scrollLeft; if ((scrlLft > 0 && e.deltaY < 0) || ((scrlLft < (mangaContainer.scrollWidth - mangaContainer.clientWidth)) && e.deltaY > 0)) { e.preventDefault(); mangaContainer.scrollLeft += e.deltaY * deltaScale; // TODO - find better value for opera/chrome } }; } /** * 画像のURLを取得 * @param json */ getImgUrl() { //url = url.replace(/\/...x...\//, '/600x600/'); //both feed and artist works case | TODO: '1200x1200' variant return this.pixivJson.body.urls.regular.replace(/\/...x...\//, '/600x600/'); } setInnerContainer(innerContainer) { this.innerContainer = innerContainer; } getPageNum(pixivJson) { return Number(pixivJson.body.pageCount); } setClassName(className) { this.mangaContainer.className = className; } } exports.Manga = Manga; /***/ }), /* 10 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ContainerFactory_1 = __webpack_require__(0); /** * html上のページごとのイラスト情報を管理する */ class Illust { constructor(page, innerContainer, json) { this.illustContainerID = 'popup-img'; this.illustContainerCSS = `width: 100%; height:100%; display:none; left: 0; top: 0; background-size: contain; background-position:center; background-repeat:no-repeat; `; this.pixivJson = json; //中身を綺麗にする innerContainer.innerHTML = ''; const factory = new ContainerFactory_1.ContainerFactory(); this.illustContainer = factory.setId(this.className) .setClass(this.className) .setCSS(this.illustContainerCSS) .createDiv(); innerContainer.appendChild(this.illustContainer); this.illustContainer.style.backgroundImage = `url(${json.body.urls.regular})`; } /** * イラストをポップアップする * 外枠であるinnerContainerに、その他情報を元に画像elementをはめ込む * * @param page * @param innerContainer * @param elem * @param json */ popup(hasClass) { this.innerContainer.style.backgroundColor = (hasClass) ? "rgb(255, 64, 96)" : "rgb(34, 34, 34)"; this.illustContainer.style.display = 'block'; //大きすぎる場合はリサイズする } resize(outerContainer, scale) { const oldWidth = this.pixivJson.body.width; const oldHeight = this.pixivJson.body.height; let newWidth = oldHeight; let newHeight = oldWidth; if (oldHeight > window.innerHeight * scale || oldWidth > window.innerWidth * scale) { const heightScale = oldHeight / Number(window.innerHeight * scale); const widthScale = oldWidth / Number(window.innerWidth * scale); if (heightScale > widthScale) { newHeight /= heightScale; newWidth /= heightScale; } else { newHeight /= widthScale; newWidth /= widthScale; } } outerContainer.style.width = `${Math.round(newWidth)}px`; outerContainer.style.height = `${Math.round(newHeight)}px`; } setInnerContainer(innerContainer) { this.innerContainer = innerContainer; } getPageNum(pixivJson) { return Number(pixivJson.body.pageCount); } setClassName(className) { this.className = className; } } exports.Illust = Illust; /***/ }), /* 11 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const util_1 = __webpack_require__(3); /** * 現在いるページを管理するページオブジェクト */ class Page { constructor(url) { this.URL = url; this.pagetype = util_1.Util.checkPageType(url); this.siteImgMaxWidth = 500; //this.pagetype === prop.popup_typeA ? 200 : 150 this.alloedFunclist = util_1.Util.getAllowedFuncList(this.pagetype); this.imgSelector = 'a[href*="member_illust.php?mode=medium&illust_id="]'; this.mangaSelector = 'a[href*="member_illust.php?mode=medium&illust_id="] > div:nth-child(2) '; } set setURL(url) { this.URL = url; this.pagetype = util_1.Util.checkPageType(url); } get getURL() { return this.URL; } get getFunclist() { return this.alloedFunclist; } isEnable(elem) { return this.alloedFunclist.indexOf(elem) > -1; } get getPagetype() { return this.pagetype; } } exports.Page = Page; /***/ }), /* 12 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const page_1 = __webpack_require__(11); const util_1 = __webpack_require__(3); const setting_1 = __webpack_require__(1); 'use strict'; /** * メイン関数 */ const page = new page_1.Page(document.URL); const util = new util_1.Util(); const setting = new setting_1.Setting(); setting.init().then(() => { util.initExecute(setting, page); }); window.onload = () => { console.log("pagetype:" + page.pagetype.toString()); //レイアウトを変更しコメントを開く util.onloadExecute(setting, page); const links = document.getElementsByTagName('a'); for (const link of links) { link.addEventListener('click', () => { util.onloadExecute(setting, new page_1.Page(document.URL)); }); } setting.save(); }; /***/ }) /******/ ]); } )();