From 09a9addf9d28e1de450fa08e6f6d044aeb37e545 Mon Sep 17 00:00:00 2001 From: CrazyboyQCD Date: Wed, 13 Sep 2023 23:19:29 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=90=9C=E7=B4=A2url=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "Pixiv \345\242\236\345\274\272.user.js" | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git "a/Pixiv \345\242\236\345\274\272.user.js" "b/Pixiv \345\242\236\345\274\272.user.js" index eb43c8d..3e7a02c 100644 --- "a/Pixiv \345\242\236\345\274\272.user.js" +++ "b/Pixiv \345\242\236\345\274\272.user.js" @@ -391,7 +391,7 @@ jQuery($ => { const idSearch = true; const otherSearch = false; const initSearch = option => { - const options = $.extend({ $form: null, placeholder: '', url: '', searchType: idSearch }, option); + const options = $.extend({ $form: null, placeholder: '', urlhandler: (url) => { return '' }, searchType: idSearch }, option); if (!options.$form) { error('搜索UID和PID 初始化失败, form元素获取失败'); @@ -425,11 +425,10 @@ jQuery($ => { $input.val(''); }); }; - initSearch({$form: $form, placeholder: 'UID', url: 'https://www.pixiv.net/users/', searchType: idSearch }); - initSearch({$form: $form, placeholder: 'PID', url: 'https://www.pixiv.net/artworks/', searchType: idSearch }); // TODO UI错乱: https://www.pixiv.net/stacc/mdnk - // TODO 无法精确搜索到作者, https://www.pixiv.net/search_user.php?nick=%E3%83%A1%E3%83%87%E3%82%A3%E3%83%B3%E3%82%AD - initSearch({$form, placeholder: i18n('author'), url: "https://www.pixiv.net/search_user.php?nick=", searchType: otherSearch }); + initSearch({ $form, placeholder: 'UID', urlhandler: (url) => `https://www.pixiv.net/users/${url}`, searchType: idSearch }); + initSearch({ $form, placeholder: 'PID', urlhandler: (url) => `https://www.pixiv.net/artworks/${url}`, searchType: idSearch }); + initSearch({ $form, placeholder: i18n('author'), urlhandler: (url) => `https://www.pixiv.net/search_user.php?nick=${url}&s_mode=s_usr`, searchType: otherSearch }) })($form); // 4. 搜索条件 ($form => { @@ -1139,7 +1138,7 @@ jQuery($ => { for (let j = 0; j < _len; j++) { const v = observers[i][1][j]; if (!(v[2])()) { - if ([0] !== null) { + if (v[0] !== null) { v[0].disconnect(); v[0] = null; } From bd675795784ed3ed270475cb2600c21188ec0c11 Mon Sep 17 00:00:00 2001 From: CrazyboyQCD Date: Wed, 13 Sep 2023 23:41:44 +0800 Subject: [PATCH 2/7] =?UTF-8?q?UI=E6=B7=B7=E4=B9=B1=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "Pixiv \345\242\236\345\274\272.user.js" | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git "a/Pixiv \345\242\236\345\274\272.user.js" "b/Pixiv \345\242\236\345\274\272.user.js" index 3e7a02c..bb9ad32 100644 --- "a/Pixiv \345\242\236\345\274\272.user.js" +++ "b/Pixiv \345\242\236\345\274\272.user.js" @@ -384,7 +384,7 @@ jQuery($ => { log("搜索增强 初始化"); // 2. 修改父级grid布局 - $form.parent().parent().css('grid-template-columns', '1fr minmax(100px, auto) minmax(100px, auto) 2fr 2fr 1fr 2fr'); + $form.parent().parent().css('grid-template-columns', '1fr minmax(0px, 219px) minmax(0px, 219px) minmax(0px, 538px) minmax(0px, 538px) minmax(0px, 219px) 2fr'); // 3. 搜索UID,PID和作者 ($form => { @@ -425,7 +425,6 @@ jQuery($ => { $input.val(''); }); }; - // TODO UI错乱: https://www.pixiv.net/stacc/mdnk initSearch({ $form, placeholder: 'UID', urlhandler: (url) => `https://www.pixiv.net/users/${url}`, searchType: idSearch }); initSearch({ $form, placeholder: 'PID', urlhandler: (url) => `https://www.pixiv.net/artworks/${url}`, searchType: idSearch }); initSearch({ $form, placeholder: i18n('author'), urlhandler: (url) => `https://www.pixiv.net/search_user.php?nick=${url}&s_mode=s_usr`, searchType: otherSearch }) From b2c3f50eab215b2094357a7ff98b1469a2d93b12 Mon Sep 17 00:00:00 2001 From: CrazyboyQCD Date: Sat, 16 Sep 2023 15:04:54 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=81=AB=E7=8B=90?= =?UTF-8?q?=E4=B8=8D=E6=98=BE=E7=A4=BA=E4=B8=AA=E4=BA=BA=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "Pixiv \345\242\236\345\274\272.user.js" | 40 +++++++++++++----------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git "a/Pixiv \345\242\236\345\274\272.user.js" "b/Pixiv \345\242\236\345\274\272.user.js" index bb9ad32..77f4d27 100644 --- "a/Pixiv \345\242\236\345\274\272.user.js" +++ "b/Pixiv \345\242\236\345\274\272.user.js" @@ -143,8 +143,7 @@ jQuery($ => { }; } else { options = $.extend({ - callback: () => { - }, + callback: () => { }, node: document.getElementsByTagName('body')[0], option: { childList: true, subtree: true } }, option); @@ -187,7 +186,7 @@ jQuery($ => { load_origin: 'load_origin', ad_disable: 'ad_disable', search_enhance: 'search_enhance', - download_able: 'download_able', + download_enable: 'download_enable', artist_info: 'artist_info', comment_load: 'comment_load', artwork_tag: 'artwork_tag', @@ -200,7 +199,7 @@ jQuery($ => { load_origin: 'load_origin', ad_disable: 'ad_disable', search_enhance: 'search_enhance', - download_able: 'download_able', + download_enable: 'download_enable', artist_info: 'artist_info', comment_load: 'comment_load', artwork_tag: 'artwork_tag', @@ -225,7 +224,7 @@ jQuery($ => { load_origin: '加载原图', ad_disable: '屏蔽广告', search_enhance: '搜索增强', - download_able: '开启下载', + download_enable: '开启下载', artist_info: '显示作者信息', comment_load: '加载评论', artwork_tag: '作品标记', @@ -250,7 +249,7 @@ jQuery($ => { load_origin: '加載原圖', ad_disable: '屏蔽廣告', search_enhance: '搜索增強', - download_able: '開啟下載', + download_enable: '開啟下載', artist_info: '顯示作者信息', comment_load: '加載評論', artwork_tag: '作品標記', @@ -291,7 +290,7 @@ jQuery($ => { const menu = [ ['ad_disable', true], ['search_enhance', true], - ['download_able', true], + ['download_enable', true], ['artist_info', true], ['comment_load', true], ['artwork_tag', true], @@ -314,7 +313,7 @@ jQuery($ => { return Object.freeze({ ad_disable: menu[0][1], search_enhance: menu[1][1], - download_able: menu[2][1], + download_enable: menu[2][1], artist_info: menu[3][1], comment_load: menu[4][1], artwork_tag: menu[5][1], @@ -475,7 +474,7 @@ jQuery($ => { }) , () => true], // 4. 单张图片替换为原图格式. 追加下载按钮, 下载gif图、gif的帧压缩包、多图 - ['download_able', null, async () => { + ['download_enable', null, async () => { // 1. 初始化方法 const initDownloadBtn = option => { // 下载按钮, 复制分享按钮并旋转180度 @@ -495,7 +494,6 @@ jQuery($ => { return $downloadButtonContainer; }; // 单图显示图片尺寸 https://www.pixiv.net/artworks/109953681 - // TODO 多图显示图片尺寸异常 https://www.pixiv.net/artworks/65424837 const addImgSize = async option => { // 从 $img 获取图片大小, after 到 $img const options = $.extend({ @@ -543,13 +541,12 @@ jQuery($ => { const lib = { png: "image/png", jpg: "image/jpeg", gif: "image/gif" }; return lib[suffix] || `mimeType[${suffix}] not found`; }; - const getDownloadName = (name) => { - name = name.replace('{pid}', illust().illustId); - name = name.replace('{uid}', illust().userId); - name = name.replace('{pname}', illust().illustTitle); - name = name.replace('{uname}', illust().userName); - return name; - }; + const getDownloadName = (name = '') => + name.replace('{pid}', illust().illustId) + .replace('{uid}', illust().userId) + .replace('{pname}', illust().illustTitle) + .replace('{uname}', illust().userName); + ; const isMoreMode = () => illust().pageCount > 1; const isGifMode = () => illust().illustType === 2; const isSingleMode = () => (illust().illustType === 0 || illust().illustType === 1) && illust().pageCount === 1; @@ -1092,7 +1089,12 @@ jQuery($ => { } } // 页面跳转不触发脚本重载时,用监听器关闭ob避免页面卡死和cpu占用飙升 - window.navigation.addEventListener('navigate', () => { + const onpushstate = history.onpushstate; + history.onpushstate = () => { + if (typeof onpushstate === 'function') { + onpushstate(); + } + log(location.href) for (let i = 0; i < len; i++) { // 功能设置没开启,关闭对应ob if (!config[observers[i][0]]) { @@ -1151,7 +1153,7 @@ jQuery($ => { } } } - }); + }; // 9. 单页排序 (() => { if (!isSearchPage() || true) { From 01d9d3ec9d4148a27b5d37a2892fda280f902bc5 Mon Sep 17 00:00:00 2001 From: CrazyboyQCD Date: Sat, 16 Sep 2023 20:25:34 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E8=8F=9C=E5=8D=95=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=A1=86=E5=8A=9F=E8=83=BD=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "Pixiv \345\242\236\345\274\272.user.js" | 233 +++++++++++++++++------ 1 file changed, 179 insertions(+), 54 deletions(-) diff --git "a/Pixiv \345\242\236\345\274\272.user.js" "b/Pixiv \345\242\236\345\274\272.user.js" index 77f4d27..362bfbc 100644 --- "a/Pixiv \345\242\236\345\274\272.user.js" +++ "b/Pixiv \345\242\236\345\274\272.user.js" @@ -183,10 +183,13 @@ jQuery($ => { // ============================ i18n 国际化 =============================== const i18nLib = { ja: { + settings: '設定', load_origin: 'load_origin', ad_disable: 'ad_disable', - search_enhance: 'search_enhance', download_enable: 'download_enable', + search_enhance_UID: 'search_enhance(UID)', + search_enhance_PID: 'search_enhance(PID)', + search_enhance_Author: 'search_enhance(Author)', artist_info: 'artist_info', comment_load: 'comment_load', artwork_tag: 'artwork_tag', @@ -196,10 +199,13 @@ jQuery($ => { author: '創作家', }, en: { + settings: 'Settings', load_origin: 'load_origin', ad_disable: 'ad_disable', - search_enhance: 'search_enhance', download_enable: 'download_enable', + search_enhance_UID: 'search_enhance(UID)', + search_enhance_PID: 'search_enhance(PID)', + search_enhance_Author: 'search_enhance(Author)', artist_info: 'artist_info', comment_load: 'comment_load', artwork_tag: 'artwork_tag', @@ -221,10 +227,13 @@ jQuery($ => { }, ko: {}, zh: { + settings: '设置', load_origin: '加载原图', ad_disable: '屏蔽广告', - search_enhance: '搜索增强', download_enable: '开启下载', + search_enhance_UID: '搜索增强(UID)', + search_enhance_PID: '搜索增强(PID)', + search_enhance_Author: '搜索增强(作者)', artist_info: '显示作者信息', comment_load: '加载评论', artwork_tag: '作品标记', @@ -246,10 +255,13 @@ jQuery($ => { }, 'zh-cn': {}, 'zh-tw': { + settings: '設置', load_origin: '加載原圖', ad_disable: '屏蔽廣告', - search_enhance: '搜索增強', download_enable: '開啟下載', + search_enhance_UID: '搜索增強(UID)', + search_enhance_PID: '搜索增強(PID)', + search_enhance_Author: '搜索增強(作者)', artist_info: '顯示作者信息', comment_load: '加載評論', artwork_tag: '作品標記', @@ -278,50 +290,133 @@ jQuery($ => { // ============================ 功能配置 ============================== - let menuId = []; - const registerMenu = () => { - // 用于刷新设置 - if (menuId.length) { - const len = menuId.length; - for (let i = 0; i < len; i++) { - GM_unregisterMenuCommand(menuId[i]); + const settingNames = [ + 'ad_disable', + 'download_enable', + 'search_enhance_UID', + 'search_enhance_PID', + 'search_enhance_Author', + 'artist_info', + 'comment_load', + 'artwork_tag', + 'redirect_cancel', + 'load_origin' + ]; + + const initConfig = () => { + const config = {}; + for (const k of settingNames) { + let enable = GM_getValue(k) + if (enable === null || enable === undefined) { + GM.setValue(k, true); + enable = true; } + config[k] = enable; } - const menu = [ - ['ad_disable', true], - ['search_enhance', true], - ['download_enable', true], - ['artist_info', true], - ['comment_load', true], - ['artwork_tag', true], - ['redirect_cancel', true], - ['load_origin', true] - ]; - const len = menu.length; - for (let i = 0; i < len; i++) { - const item = menu[i][0]; - menu[i][1] = GM_getValue(item); - if (menu[i][1] === null || menu[i][1] === undefined) { - GM_setValue(item, true); - menu[i][1] = true; + return config; + } + const config = initConfig(); + const settingsPanel = () => { + var $panel = $(` + +
+
+
+

${i18n('settings')}

+
+ +
+
+
+
+
+
+ `) + const $items_wrap = $panel.find('#pixiv-plus-settings-items-wrap'); + for (const name of settingNames) { + $items_wrap.append($(` +
+ + +
+ `)) } - return Object.freeze({ - ad_disable: menu[0][1], - search_enhance: menu[1][1], - download_enable: menu[2][1], - artist_info: menu[3][1], - comment_load: menu[4][1], - artwork_tag: menu[5][1], - redirect_cancel: menu[6][1], - load_origin: menu[7][1], + $panel.find('input[type="checkbox"]').each(function () { + const $checkbox = $(this); + const name = $checkbox.attr('name'); + GM.getValue(name, true).then(value => { + $checkbox.prop('checked', value); + }); + $checkbox.on('change', () => { + const checked = $checkbox.prop('checked'); + $checkbox.prop(checked, checked); + GM.setValue(name, checked); + config[name] = checked; + }); }); - }; - const config = registerMenu(); + $('body').append($panel); + $('#pixiv-plus-settings-close-button').on('click', () => $panel.remove()); + } + GM_registerMenuCommand(`${i18n('settings')}`, () => settingsPanel()); // ============================ url 页面判断 ============================== const isArtworkPage = () => /.+artworks\/\d+.*/.test(location.href); @@ -371,7 +466,7 @@ jQuery($ => { }); }, () => true], // 2/3. 搜索增强 - ['search_enhance', null, () => + [['search_enhance_UID', 'search_enhance_PID', 'search_enhance_Author'], null, () => observerFactory((mutations, observer) => { for (let i = 0, len = mutations.length; i < len; i++) { const mutation = mutations[i]; @@ -382,10 +477,7 @@ jQuery($ => { } log("搜索增强 初始化"); - // 2. 修改父级grid布局 - $form.parent().parent().css('grid-template-columns', '1fr minmax(0px, 219px) minmax(0px, 219px) minmax(0px, 538px) minmax(0px, 538px) minmax(0px, 219px) 2fr'); - - // 3. 搜索UID,PID和作者 + // 2. 搜索UID,PID和作者 ($form => { const idSearch = true; const otherSearch = false; @@ -424,9 +516,43 @@ jQuery($ => { $input.val(''); }); }; - initSearch({ $form, placeholder: 'UID', urlhandler: (url) => `https://www.pixiv.net/users/${url}`, searchType: idSearch }); - initSearch({ $form, placeholder: 'PID', urlhandler: (url) => `https://www.pixiv.net/artworks/${url}`, searchType: idSearch }); - initSearch({ $form, placeholder: i18n('author'), urlhandler: (url) => `https://www.pixiv.net/search_user.php?nick=${url}&s_mode=s_usr`, searchType: otherSearch }) + // 按设置加入搜索框 + const searchers = [ + [() => initSearch({ $form, placeholder: 'UID', urlhandler: (url) => `https://www.pixiv.net/users/${url}`, searchType: idSearch }), () => config['search_enhance_UID']], + [() => initSearch({ $form, placeholder: 'PID', urlhandler: (url) => `https://www.pixiv.net/artworks/${url}`, searchType: idSearch }), () => config['search_enhance_PID']], + [() => initSearch({ $form, placeholder: i18n('author'), urlhandler: (url) => `https://www.pixiv.net/search_user.php?nick=${url}&s_mode=s_usr`, searchType: otherSearch }), () => config['search_enhance_Author']]]; + // 统计加入的搜索框 + let cnt = 0; + for (const searcher of searchers) { + if ((searcher[1])()) { + (searcher[0])(); + cnt++; + } + } + // 3. 修改父级grid布局 + // 分类设置布局 + const $parent = $form.parent().parent(); + switch (cnt) { + case 0: { + $parent.css('grid-template-columns', '1fr minmax(0px, 800px) minmax(0px, 350px) 2fr'); + break; + } + case 1: { + $parent.css('grid-template-columns', '1fr minmax(0px, 600px) minmax(0px, 600px) minmax(0px, 250px) 2fr'); + break; + } + case 2: { + $parent.css('grid-template-columns', '1fr minmax(0px, 243px) minmax(0px, 586px) minmax(0px, 586px) minmax(0px, 243px) 2fr'); + break; + } + case 3: { + $parent.css('grid-template-columns', '1fr minmax(0px, 219px) minmax(0px, 219px) minmax(0px, 538px) minmax(0px, 538px) minmax(0px, 219px) 2fr'); + break; + } + default: { + break; + } + } })($form); // 4. 搜索条件 ($form => { @@ -1078,7 +1204,7 @@ jQuery($ => { const len = observers.length; // 初始化ob for (let i = 0; i < len; i++) { - if (config[observers[i][0]] && observers[i][1] === null) { + if ((((typeof observers[i][0] === 'Array' && observers[i][0].some(v => config[v])) || !config[observers[i][0]]) || config[observers[i][0]]) && observers[i][1] === null) { const _observer = (observers[i][2])(); // 有一个ob组特殊处理 if (_observer instanceof Promise) { @@ -1094,10 +1220,9 @@ jQuery($ => { if (typeof onpushstate === 'function') { onpushstate(); } - log(location.href) for (let i = 0; i < len; i++) { // 功能设置没开启,关闭对应ob - if (!config[observers[i][0]]) { + if ((typeof observers[i][0] === 'Array' && !observers[i][0].some(v => config[v])) || !config[observers[i][0]]) { // ob已创建 if (observers[i][1] !== null) { // ob组处理 From d27d94e9d9da24b362f7c838ca4e27ca3a3976df Mon Sep 17 00:00:00 2001 From: CrazyboyQCD Date: Mon, 18 Sep 2023 22:49:29 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "Pixiv \345\242\236\345\274\272.user.js" | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git "a/Pixiv \345\242\236\345\274\272.user.js" "b/Pixiv \345\242\236\345\274\272.user.js" index 362bfbc..b34c711 100644 --- "a/Pixiv \345\242\236\345\274\272.user.js" +++ "b/Pixiv \345\242\236\345\274\272.user.js" @@ -317,7 +317,7 @@ jQuery($ => { } const config = initConfig(); const settingsPanel = () => { - var $panel = $(` + const $panel = $(`