// ==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.3.7-20181007 // @homepageURL https://github.com/SotobatoNihu/PixivViewUtil // @license MIT License // @require https://code.jquery.com/jquery-3.2.1.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 = 8); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (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["caption"] = 2] = "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 = {})); ; /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const enum_1 = __webpack_require__(0); class Setting { constructor() { this.changeIllustPageLayout = true; this.changeMemberPageLayout = true; this.openComment = true; this.popup = true; } 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; } }); } 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.uiComponent = [enum_1.uiComponent.image, enum_1.uiComponent.manga, 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; } get getJsonString() { const obj = { changeIllustPageLayout: this.changeIllustPageLayout, changeMemberPageLayout: this.changeMemberPageLayout, openComment: this.openComment, popup: this.popup, }; 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 }); class ContainerFactory { constructor() { this.id = ''; this.innerHtml = ''; this.innerText = ''; this.cssText = ''; } setId(idString) { this.id = idString; 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.innerHTML = this.innerHtml; elem.style.cssText = this.cssText; return elem; } createImg() { const elem = document.createElement('img'); elem.id = this.id; elem.style.cssText = this.cssText; return elem; } setVoidHtml() { this.innerHtml = ''; return this; } createSpan() { const elem = document.createElement('span'); elem.id = this.id; elem.innerHTML = this.innerHtml; elem.style.cssText = this.cssText; return elem; } appendChild(infoElem) { this.appendChild(infoElem); return this; } setCSS(cssString) { this.cssText = cssString; return this; } } exports.ContainerFactory = ContainerFactory; /***/ }), /* 3 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const enum_1 = __webpack_require__(0); const popupUtil_1 = __webpack_require__(6); const setting_1 = __webpack_require__(1); const ContainerFactory_1 = __webpack_require__(2); const jsonInterface_1 = __webpack_require__(4); class Util { constructor() { this.outerContainerCSS = ` position:absolute; display:block; z-index:1000; border: 5px solid black; max-width:${window.innerWidth * 0.8}px; background-color:#111; max-width:${window.innerWidth * 0.8}px; max-height:${window.innerHeight * 0.8}px; `; 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; } `; /* async loadSettingData(){ const default_setting = { changeIllustPageLayout: true, changeMemberPageLayout: true, openComment: true, popup: true } // @ts-ignore return await GM.getValue("pixiv_viewutil_setting", JSON.stringify(default_setting)); } async saveSettingData(setting: Setting) { // @ts-ignore await GM.setValue("pixiv_viewutil_setting", setting); } */ } async initExecute(setting, page) { if (page.pagetype == enum_1.pagetype.top && document.getElementById('pixiv-view-util-gear') === null) { this.setConfigScreen(); } if (setting.popup && page.isEnable(enum_1.prop.popup_typeA)) { this.setPopup(page, setting); console.log("set popup typeA"); } else if (setting.popup && page.isEnable(enum_1.prop.popup_typeB)) { this.setPopup(page, setting); console.log("set popup typeB"); } if (setting.changeMemberPageLayout && page.isEnable(enum_1.prop.changeMemberPageLayout)) { const autherElem = document.getElementsByTagName('header')[0].nextElementSibling.children[0].children[0]; //$('header').next().children().children() document.getElementById("root").appendChild(autherElem); console.log("layout chainged"); } } onloadExecute(setting, page) { if (page.pagetype === enum_1.pagetype.top && document.getElementById('pixiv-view-util-gear') === null) { this.setConfigScreen(); } 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_illust) { const autherElem = document.getElementsByTagName('header')[0].nextElementSibling.children[0].children[0]; //$('header').next().children().children() document.getElementById("root").appendChild(autherElem); console.log("layout chainged"); } } // function checkPageType(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')); } static changeMemberPageLayout() { // TODO もっと良い方法 //const tagElem=$('.gm-profile-work-list-tag-list-click') //const illustElem=tagElem.parent().parent().parent().parent() //$('header').next().prepend(illustElem) // $('nav').parent().parent().prepend(illustElem) const h2Elems = $('h2'); for (const h2elem of h2Elems) { if (h2elem.innerText.startsWith("イラスト")) { const illustElem = $(h2elem).parent().parent(); //$('nav').parent().parent().prepend(illustElem) $('header').next().prepend(illustElem); break; } } } 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 []; } } 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, }); } } setPopup(page, setting) { const popupUtil = new popupUtil_1.PopupUtil(); const factory = new ContainerFactory_1.ContainerFactory(); const outerContainer = factory.setId('outerContainer') .setCSS(this.outerContainerCSS) .setVoidHtml() .createDiv(); document.body.appendChild(outerContainer); // イラスト&漫画のクリックイベントを登録する $('body').on('mouseenter', 'a[href*="member_illust.php?mode=medium&illust_id="]', function () { 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"); const matches = url.match(/(.)+illust_id=([0-9]+)(&.+)?/); const illustID = Number(matches[2]); $(clickElem).on('click', function (e) { fetch(`https://www.pixiv.net/ajax/illust/${illustID}`).then(function (response) { return response.json(); }).then(function (json) { const pixivJson = new jsonInterface_1.PixivJson(json); // const mouseX=e.pageX //const mouseY=e.pageY if (!popupUtil.isManga(pixivJson)) { popupUtil.popupImg(page, outerContainer, hrefElem, pixivJson); } else { const pageNum = Util.getPageNum(pixivJson); popupUtil.popupManga(outerContainer, hrefElem, pixivJson, Number(pageNum)); } popupUtil.popupCaption(outerContainer, pixivJson); }); }); }); const deleteAll = () => { const elem = document.getElementById('captionContainer'); if (elem !== null) { elem.parentNode.removeChild(elem); } outerContainer.textContent = null; outerContainer.style.display = 'none'; }; outerContainer.onmouseleave = function () { const elem = document.getElementById('captionContainer').innerHTML; if ($(elem).find('a').length == 0) { deleteAll(); } else { setTimeout(deleteAll(), 1000); } }; window.onresize = function () { outerContainer.style.maxWidth = `${window.innerWidth * 0.8}px`; }; } static getUserID(json) { return json.body.tags.authorId; } static getPageNum(json) { return Number(json.body.pageCount); } async setConfigScreen() { const iconID = 'pixiv-view-util-icon'; const iconElem = document.getElementById(iconID); if (iconElem === null) { await this.setIconElem(iconID); await this.setModal(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); } setModal(iconID) { const setting = new setting_1.Setting; const iconElem = document.getElementById(iconID); const modal1 = document.createElement('div'); modal1.innerHTML = `
Setting: