From 8f71e37e85257d8a46a9aaf04d5e94f99fd9e063 Mon Sep 17 00:00:00 2001 From: kaikaiiiiiii Date: Tue, 30 Jul 2024 04:43:03 +0800 Subject: [PATCH 01/13] bug fix: incorrectly record other users' game completion as self. --- package.json | 4 ++-- psnineplus.js | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 7b9ccaa..efb1939 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "psnine-enhanced-version", - "version": "1.0.24", + "version": "1.0.27", "description": "数折价格走势图,显示人民币价格,奖杯统计和筛选,发帖字数统计和即时预览,楼主高亮,自动翻页,屏蔽黑名单用户发言,被@用户的发言内容显示等多项功能优化P9体验", "main": "night-mode-css.js", "scripts": { @@ -22,4 +22,4 @@ "eslint-config-airbnb-base": "^14.2.1", "eslint-plugin-import": "^2.22.1" } -} +} \ No newline at end of file diff --git a/psnineplus.js b/psnineplus.js index cbdd68a..7763df0 100644 --- a/psnineplus.js +++ b/psnineplus.js @@ -1,7 +1,7 @@ // ==UserScript== // @name PSN中文网功能增强 // @namespace https://swsoyee.github.io -// @version 1.0.26 +// @version 1.0.27 // @description 数折价格走势图,显示人民币价格,奖杯统计和筛选,发帖字数统计和即时预览,楼主高亮,自动翻页,屏蔽黑名单用户发言,被@用户的发言内容显示等多项功能优化P9体验 // eslint-disable-next-line max-len // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAMAAAAp4XiDAAAAMFBMVEVHcEw0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNuEOyNSAAAAD3RSTlMAQMAQ4PCApCBQcDBg0JD74B98AAABN0lEQVRIx+2WQRaDIAxECSACWLn/bdsCIkNQ2XXT2bTyHEx+glGIv4STU3KNRccp6dNh4qTM4VDLrGVRxbLGaa3ZQSVQulVJl5JFlh3cLdNyk/xe2IXz4DqYLhZ4mWtHd4/SLY/QQwKmWmGcmUfHb4O1mu8BIPGw4Hg1TEvySQGWoBcItgxndmsbhtJd6baukIKnt525W4anygNECVc1UD8uVbRNbumZNl6UmkagHeRJfX0BdM5NXgA+ZKESpiJ9tRFftZEvue2cS6cKOrGk/IOLTLUcaXuZHrZDq3FB2IonOBCHIy8Bs1Zzo1MxVH+m8fQ+nFeCQM3MWwEsWsy8e8Di7meA5Bb5MDYCt4SnUbP3lv1xOuWuOi3j5kJ5tPiZKahbi54anNRaaG7YElFKQBHR/9PjN3oD6fkt9WKF9rgAAAAASUVORK5CYII= @@ -402,7 +402,7 @@ $('body,html').animate({ scrollTop: document.body.clientHeight, }, - 500); + 500); }).css({ cursor: 'pointer', }); @@ -724,7 +724,15 @@ const savePersonalGameCompletions = (configifneeded) => { // if GM_setValue && GM_getValue is enabled - const thisFeatureEnabled = (configifneeded || true) && (typeof GM_setValue === 'function' && typeof GM_getValue === 'function'); + let thisFeatureEnabled = (configifneeded || true) && (typeof GM_setValue === 'function' && typeof GM_getValue === 'function'); + const myHomePage = document.querySelectorAll('ul.r li.dropdown ul li a')[0].href; + thisFeatureEnabled = thisFeatureEnabled && window.location.href.includes(myHomePage); + + // 2024.07.30 bug fix: 错误地保存他人的游戏完成度。已经修复,但用户端的旧数据需要清除 + const lasttime = GM_getValue('personalGameCompletionsLastUpdated', 0); + if (lasttime === 0) { GM_setValue('personalGameCompletions', []); } + + GM_setValue('personalGameCompletions', []); if (thisFeatureEnabled) { // 获得当前页的游戏完成度 @@ -740,7 +748,8 @@ }); // 读取已保存的历史 - const history = GM_getValue('personalGameCompletions', []); + + let history = GM_getValue('personalGameCompletions', []); // 用当前覆盖历史 personalGameCompletions.forEach((currentItem) => { @@ -754,7 +763,8 @@ // 保存更新后的历史记录 GM_setValue('personalGameCompletions', history); - // console.log(GM_getValue('personalGameCompletions')) + GM_setValue('personalGameCompletionsLastUpdated', new Date().getTime()); + console.log(history) return true; } return false; @@ -764,6 +774,7 @@ if ( /psnid\/[A-Za-z0-9_-]+\/?$/.test(window.location.href) || /psnid\/[A-Za-z0-9_-]+\/psngame\/?/.test(window.location.href) ) { + savePersonalGameCompletions(); } @@ -1128,7 +1139,7 @@ .append(` 🔥热门 `); + };color: rgb(255, 255, 255);">🔥热门 `); } }); }; From 25e3f34951568003985e76ea7cd38bd9794beb71 Mon Sep 17 00:00:00 2001 From: kaikaiiiiiii Date: Tue, 30 Jul 2024 04:49:55 +0800 Subject: [PATCH 02/13] clear --- psnineplus.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/psnineplus.js b/psnineplus.js index 7763df0..4523b38 100644 --- a/psnineplus.js +++ b/psnineplus.js @@ -732,8 +732,6 @@ const lasttime = GM_getValue('personalGameCompletionsLastUpdated', 0); if (lasttime === 0) { GM_setValue('personalGameCompletions', []); } - GM_setValue('personalGameCompletions', []); - if (thisFeatureEnabled) { // 获得当前页的游戏完成度 const tdElements = document.querySelectorAll('table.list tbody > tr'); @@ -748,7 +746,6 @@ }); // 读取已保存的历史 - let history = GM_getValue('personalGameCompletions', []); // 用当前覆盖历史 @@ -764,7 +761,6 @@ // 保存更新后的历史记录 GM_setValue('personalGameCompletions', history); GM_setValue('personalGameCompletionsLastUpdated', new Date().getTime()); - console.log(history) return true; } return false; @@ -774,7 +770,6 @@ if ( /psnid\/[A-Za-z0-9_-]+\/?$/.test(window.location.href) || /psnid\/[A-Za-z0-9_-]+\/psngame\/?/.test(window.location.href) ) { - savePersonalGameCompletions(); } From b02e72c79e0d792c218c32e6d568bddf75d8af4a Mon Sep 17 00:00:00 2001 From: kaikaiiiiiii Date: Tue, 30 Jul 2024 05:31:19 +0800 Subject: [PATCH 03/13] lint --- psnineplus.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/psnineplus.js b/psnineplus.js index 4523b38..7ab05a6 100644 --- a/psnineplus.js +++ b/psnineplus.js @@ -402,7 +402,7 @@ $('body,html').animate({ scrollTop: document.body.clientHeight, }, - 500); + 500); }).css({ cursor: 'pointer', }); @@ -746,7 +746,7 @@ }); // 读取已保存的历史 - let history = GM_getValue('personalGameCompletions', []); + const history = GM_getValue('personalGameCompletions', []); // 用当前覆盖历史 personalGameCompletions.forEach((currentItem) => { @@ -1134,7 +1134,7 @@ .append(` 🔥热门 `); + };color: rgb(255, 255, 255);">🔥热门 `); } }); }; From 23f3762ec9834368fec45f1409534f9a31583eea Mon Sep 17 00:00:00 2001 From: kaikaiiiiiii Date: Tue, 30 Jul 2024 08:38:37 +0800 Subject: [PATCH 04/13] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E6=B8=B8=E6=88=8F?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E6=94=B9=E4=B8=BA=E5=90=8E=E5=8F=B0=20ajax?= =?UTF-8?q?=20=E5=BC=82=E6=AD=A5=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- psnineplus.js | 169 +++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 133 insertions(+), 38 deletions(-) diff --git a/package.json b/package.json index efb1939..9f8c8c9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "psnine-enhanced-version", - "version": "1.0.27", + "version": "1.0.28", "description": "数折价格走势图,显示人民币价格,奖杯统计和筛选,发帖字数统计和即时预览,楼主高亮,自动翻页,屏蔽黑名单用户发言,被@用户的发言内容显示等多项功能优化P9体验", "main": "night-mode-css.js", "scripts": { diff --git a/psnineplus.js b/psnineplus.js index 7ab05a6..2e653b1 100644 --- a/psnineplus.js +++ b/psnineplus.js @@ -1,7 +1,7 @@ // ==UserScript== // @name PSN中文网功能增强 // @namespace https://swsoyee.github.io -// @version 1.0.27 +// @version 1.0.28 // @description 数折价格走势图,显示人民币价格,奖杯统计和筛选,发帖字数统计和即时预览,楼主高亮,自动翻页,屏蔽黑名单用户发言,被@用户的发言内容显示等多项功能优化P9体验 // eslint-disable-next-line max-len // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAMAAAAp4XiDAAAAMFBMVEVHcEw0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNuEOyNSAAAAD3RSTlMAQMAQ4PCApCBQcDBg0JD74B98AAABN0lEQVRIx+2WQRaDIAxECSACWLn/bdsCIkNQ2XXT2bTyHEx+glGIv4STU3KNRccp6dNh4qTM4VDLrGVRxbLGaa3ZQSVQulVJl5JFlh3cLdNyk/xe2IXz4DqYLhZ4mWtHd4/SLY/QQwKmWmGcmUfHb4O1mu8BIPGw4Hg1TEvySQGWoBcItgxndmsbhtJd6baukIKnt525W4anygNECVc1UD8uVbRNbumZNl6UmkagHeRJfX0BdM5NXgA+ZKESpiJ9tRFftZEvue2cS6cKOrGk/IOLTLUcaXuZHrZDq3FB2IonOBCHIy8Bs1Zzo1MxVH+m8fQ+nFeCQM3MWwEsWsy8e8Di7meA5Bb5MDYCt4SnUbP3lv1xOuWuOi3j5kJ5tPiZKahbi54anNRaaG7YElFKQBHR/9PjN3oD6fkt9WKF9rgAAAAASUVORK5CYII= @@ -402,7 +402,7 @@ $('body,html').animate({ scrollTop: document.body.clientHeight, }, - 500); + 500); }).css({ cursor: 'pointer', }); @@ -722,55 +722,150 @@ 添加于 /psnid\/[A-Za-z0-9_-]+\/?$/ 页面,以及该页自动翻页函数内部 */ - const savePersonalGameCompletions = (configifneeded) => { - // if GM_setValue && GM_getValue is enabled + const bgGetMyGameCompletion = (configifneeded) => { + + console.log('run bgGetMyGameCompletion') let thisFeatureEnabled = (configifneeded || true) && (typeof GM_setValue === 'function' && typeof GM_getValue === 'function'); const myHomePage = document.querySelectorAll('ul.r li.dropdown ul li a')[0].href; - thisFeatureEnabled = thisFeatureEnabled && window.location.href.includes(myHomePage); + const myUserId = myHomePage.match(/\/psnid\/([A-Za-z0-9_-]+)/)[1]; - // 2024.07.30 bug fix: 错误地保存他人的游戏完成度。已经修复,但用户端的旧数据需要清除 const lasttime = GM_getValue('personalGameCompletionsLastUpdated', 0); + + // 2024.07.30 bug fix: 错误地保存他人的游戏完成度。已经修复,但用户端的旧数据需要清除 if (lasttime === 0) { GM_setValue('personalGameCompletions', []); } + // 小于一小时不执行 + // if (new Date().getTime() - lasttime < 3600 * 1000) { return false } + if (new Date().getTime() - lasttime < 1) { return false } + + let gameCompletionHistory = GM_getValue('personalGameCompletions', []); + gameCompletionHistory = []; + if (thisFeatureEnabled) { - // 获得当前页的游戏完成度 - const tdElements = document.querySelectorAll('table.list tbody > tr'); - const personalGameCompletions = Array.from(tdElements).map((tr) => { - const completionElement = tr.querySelector('div.progress > div'); - const completion = completionElement ? parseFloat(completionElement.textContent) : 0; - const platinumElement = tr.querySelector('span.text-platinum'); - const platinum = platinumElement ? platinumElement.textContent === '白1' : false; - const gameIDElement = tr.querySelector('a'); - const gameID = gameIDElement.href.match(/\/psngame\/(\d+)/)[1]; - return [gameID, completion, platinum]; - }); - // 读取已保存的历史 - const history = GM_getValue('personalGameCompletions', []); + const loadGameCompletions = (userid, pageid) => { + console.log(`https://psnine.com/psnid/${userid}/psngame?page=${pageid}`) + + $.ajax({ + type: 'GET', + url: `https://psnine.com/psnid/${userid}/psngame?page=${pageid}`, + dataType: 'html', + async: true, + success: (data, status) => { + if (status === 'success') { + + // 读取当前页奖杯完成数据 + const page = document.createElement('html'); + page.innerHTML = data; + const tdElements = document.querySelectorAll('table.list tbody > tr'); + const thisPageCompletions = Array.from(tdElements).map((tr) => { + const completionElement = tr.querySelector('div.progress > div'); + const completion = completionElement ? parseFloat(completionElement.textContent) : 0; + const platinumElement = tr.querySelector('span.text-platinum'); + const platinum = platinumElement ? platinumElement.textContent === '白1' : false; + const gameIDElement = tr.querySelector('a'); + const gameID = gameIDElement.href.match(/\/psngame\/(\d+)/)[1]; + return [gameID, completion, platinum]; + }); - // 用当前覆盖历史 - personalGameCompletions.forEach((currentItem) => { - const index = history.findIndex((historyItem) => historyItem[0] === currentItem[0]); - if (index !== -1) { - history[index] = currentItem; - } else { - history.push(currentItem); - } - }); + console.log(thisPageCompletions); + // 合并更新历史数据,并确定是否加载下一页 + let loadNext = true; + let comblineflag = false; + + // 1. 合并数据,并当整页数据都没有变化时,不加载下一页 + thisPageCompletions.forEach((completion) => { + const index = gameCompletionHistory.findIndex((historyItem) => historyItem[0] === completion[0]); + if (index !== -1) { + if (gameCompletionHistory[index][1] !== completion[1]) { + comblineflag = true; + gameCompletionHistory[index] = completion; + } + } else { + gameCompletionHistory.push(completion); + comblineflag = true; + } + }) + + // 如果最后一页,则停止 + const totalPageEle = page.querySelectorAll('.page > ul > li > a') + const totalPage = parseInt(totalPageEle[totalPageEle.length - 1].innerText, 10); + if (pageid === totalPage) { loadNext = false } + + // 保存数据 + console.log(gameCompletionHistory); + GM_setValue('personalGameCompletions', gameCompletionHistory); + GM_setValue('personalGameCompletionsLastUpdated', new Date().getTime()); + console.log(loadNext, comblineflag) + + // 执行下一页 + if (loadNext && comblineflag) { + setTimeout(() => { loadGameCompletions(userid, pageid + 1) }, 5000); + } - // 保存更新后的历史记录 - GM_setValue('personalGameCompletions', history); - GM_setValue('personalGameCompletionsLastUpdated', new Date().getTime()); - return true; + } + }, + error: (e) => { console.log('loadGameCompletions error', e) }, + }) + } + + loadGameCompletions(myUserId, 1); } - return false; - }; + + } + + bgGetMyGameCompletion(true); + + + // const savePersonalGameCompletions = (configifneeded) => { + // // if GM_setValue && GM_getValue is enabled + // let thisFeatureEnabled = (configifneeded || true) && (typeof GM_setValue === 'function' && typeof GM_getValue === 'function'); + // const myHomePage = document.querySelectorAll('ul.r li.dropdown ul li a')[0].href; + // thisFeatureEnabled = thisFeatureEnabled && window.location.href.includes(myHomePage); + + // // 2024.07.30 bug fix: 错误地保存他人的游戏完成度。已经修复,但用户端的旧数据需要清除 + // const lasttime = GM_getValue('personalGameCompletionsLastUpdated', 0); + // if (lasttime === 0) { GM_setValue('personalGameCompletions', []); } + + // if (thisFeatureEnabled) { + // // 获得当前页的游戏完成度 + // const tdElements = document.querySelectorAll('table.list tbody > tr'); + // const personalGameCompletions = Array.from(tdElements).map((tr) => { + // const completionElement = tr.querySelector('div.progress > div'); + // const completion = completionElement ? parseFloat(completionElement.textContent) : 0; + // const platinumElement = tr.querySelector('span.text-platinum'); + // const platinum = platinumElement ? platinumElement.textContent === '白1' : false; + // const gameIDElement = tr.querySelector('a'); + // const gameID = gameIDElement.href.match(/\/psngame\/(\d+)/)[1]; + // return [gameID, completion, platinum]; + // }); + + // // 读取已保存的历史 + // const history = GM_getValue('personalGameCompletions', []); + + // // 用当前覆盖历史 + // personalGameCompletions.forEach((currentItem) => { + // const index = history.findIndex((historyItem) => historyItem[0] === currentItem[0]); + // if (index !== -1) { + // history[index] = currentItem; + // } else { + // history.push(currentItem); + // } + // }); + + // // 保存更新后的历史记录 + // GM_setValue('personalGameCompletions', history); + // GM_setValue('personalGameCompletionsLastUpdated', new Date().getTime()); + // return true; + // } + // return false; + // }; // 在个人页面或个人游戏列表页更新数据 if ( /psnid\/[A-Za-z0-9_-]+\/?$/.test(window.location.href) || /psnid\/[A-Za-z0-9_-]+\/psngame\/?/.test(window.location.href) ) { - savePersonalGameCompletions(); + // savePersonalGameCompletions(); } if ( @@ -807,7 +902,7 @@ gamePageIndex += 1; // 同步更新个人游戏完成度 - savePersonalGameCompletions(); + // savePersonalGameCompletions(); } else { $('#loadingMessage').text('没有更多游戏了...'); } @@ -1134,7 +1229,7 @@ .append(` 🔥热门 `); + };color: rgb(255, 255, 255);">🔥热门 `); } }); }; From ca4f7b5162e17e7cb479ae038eeb9605d0b53aa8 Mon Sep 17 00:00:00 2001 From: kaikaiiiiiii Date: Tue, 30 Jul 2024 08:43:08 +0800 Subject: [PATCH 05/13] bug fix --- psnineplus.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/psnineplus.js b/psnineplus.js index 2e653b1..53c0e25 100644 --- a/psnineplus.js +++ b/psnineplus.js @@ -757,7 +757,7 @@ // 读取当前页奖杯完成数据 const page = document.createElement('html'); page.innerHTML = data; - const tdElements = document.querySelectorAll('table.list tbody > tr'); + const tdElements = page.querySelectorAll('table.list tbody > tr'); const thisPageCompletions = Array.from(tdElements).map((tr) => { const completionElement = tr.querySelector('div.progress > div'); const completion = completionElement ? parseFloat(completionElement.textContent) : 0; @@ -789,7 +789,8 @@ // 如果最后一页,则停止 const totalPageEle = page.querySelectorAll('.page > ul > li > a') - const totalPage = parseInt(totalPageEle[totalPageEle.length - 1].innerText, 10); + const totalPage = parseInt(totalPageEle[totalPageEle.length - 2].innerText); + console.log(totalPage, pageid) if (pageid === totalPage) { loadNext = false } // 保存数据 @@ -809,7 +810,7 @@ }) } - loadGameCompletions(myUserId, 1); + loadGameCompletions(myUserId, 15); } } From d7f638c28b2acbeaea57fd1d0727a39740a48d0b Mon Sep 17 00:00:00 2001 From: kaikaiiiiiii Date: Tue, 30 Jul 2024 08:44:20 +0800 Subject: [PATCH 06/13] =?UTF-8?q?=E6=94=B9=E5=9B=9E=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=EF=BC=8C=E5=90=8E=E4=B8=80=E6=AC=A1=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=A6=86=E7=9B=96=E4=BA=86=E5=89=8D=E6=AC=A1=20bug=20fix=20?= =?UTF-8?q?=E7=9A=84=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- psnineplus.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9f8c8c9..efb1939 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "psnine-enhanced-version", - "version": "1.0.28", + "version": "1.0.27", "description": "数折价格走势图,显示人民币价格,奖杯统计和筛选,发帖字数统计和即时预览,楼主高亮,自动翻页,屏蔽黑名单用户发言,被@用户的发言内容显示等多项功能优化P9体验", "main": "night-mode-css.js", "scripts": { diff --git a/psnineplus.js b/psnineplus.js index 53c0e25..0c6eaa3 100644 --- a/psnineplus.js +++ b/psnineplus.js @@ -1,7 +1,7 @@ // ==UserScript== // @name PSN中文网功能增强 // @namespace https://swsoyee.github.io -// @version 1.0.28 +// @version 1.0.27 // @description 数折价格走势图,显示人民币价格,奖杯统计和筛选,发帖字数统计和即时预览,楼主高亮,自动翻页,屏蔽黑名单用户发言,被@用户的发言内容显示等多项功能优化P9体验 // eslint-disable-next-line max-len // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAMAAAAp4XiDAAAAMFBMVEVHcEw0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNuEOyNSAAAAD3RSTlMAQMAQ4PCApCBQcDBg0JD74B98AAABN0lEQVRIx+2WQRaDIAxECSACWLn/bdsCIkNQ2XXT2bTyHEx+glGIv4STU3KNRccp6dNh4qTM4VDLrGVRxbLGaa3ZQSVQulVJl5JFlh3cLdNyk/xe2IXz4DqYLhZ4mWtHd4/SLY/QQwKmWmGcmUfHb4O1mu8BIPGw4Hg1TEvySQGWoBcItgxndmsbhtJd6baukIKnt525W4anygNECVc1UD8uVbRNbumZNl6UmkagHeRJfX0BdM5NXgA+ZKESpiJ9tRFftZEvue2cS6cKOrGk/IOLTLUcaXuZHrZDq3FB2IonOBCHIy8Bs1Zzo1MxVH+m8fQ+nFeCQM3MWwEsWsy8e8Di7meA5Bb5MDYCt4SnUbP3lv1xOuWuOi3j5kJ5tPiZKahbi54anNRaaG7YElFKQBHR/9PjN3oD6fkt9WKF9rgAAAAASUVORK5CYII= From 65c380b02f8ccae4ade0a8949445d7e4e2c9cea6 Mon Sep 17 00:00:00 2001 From: kaikaiiiiiii Date: Tue, 30 Jul 2024 09:07:44 +0800 Subject: [PATCH 07/13] clear --- psnineplus.js | 109 ++++++++++---------------------------------------- 1 file changed, 21 insertions(+), 88 deletions(-) diff --git a/psnineplus.js b/psnineplus.js index 0c6eaa3..7f61518 100644 --- a/psnineplus.js +++ b/psnineplus.js @@ -718,33 +718,29 @@ ); /* - 在 LocatStorage 中保存个人游戏完成度函数 - 添加于 /psnid\/[A-Za-z0-9_-]+\/?$/ 页面,以及该页自动翻页函数内部 + 在 LocatStorage 中保存个人游戏完成度函数,为避免过多的重复请求,设置了两个结束条件: + 一:更新时间超过一小时 + 二:遇到和已知条目的进度一样时停止,利用更新奖杯一定在前的特性 */ const bgGetMyGameCompletion = (configifneeded) => { - console.log('run bgGetMyGameCompletion') let thisFeatureEnabled = (configifneeded || true) && (typeof GM_setValue === 'function' && typeof GM_getValue === 'function'); - const myHomePage = document.querySelectorAll('ul.r li.dropdown ul li a')[0].href; - const myUserId = myHomePage.match(/\/psnid\/([A-Za-z0-9_-]+)/)[1]; - - const lasttime = GM_getValue('personalGameCompletionsLastUpdated', 0); + if (thisFeatureEnabled) { + const myHomePage = document.querySelectorAll('ul.r li.dropdown ul li a')[0].href; + const myUserId = myHomePage.match(/\/psnid\/([A-Za-z0-9_-]+)/)[1]; - // 2024.07.30 bug fix: 错误地保存他人的游戏完成度。已经修复,但用户端的旧数据需要清除 - if (lasttime === 0) { GM_setValue('personalGameCompletions', []); } + const lasttime = GM_getValue('personalGameCompletionsLastUpdated', 0); - // 小于一小时不执行 - // if (new Date().getTime() - lasttime < 3600 * 1000) { return false } - if (new Date().getTime() - lasttime < 1) { return false } + // 2024.07.30 bug fix: 错误地保存他人的游戏完成度。已经修复,但用户端的旧数据需要清除 + if (lasttime < new Date('2024-07-30 9:00 GMT+0800').getTime()) { GM_setValue('personalGameCompletions', []); } - let gameCompletionHistory = GM_getValue('personalGameCompletions', []); - gameCompletionHistory = []; + // 小于一小时不执行 + if (new Date().getTime() - lasttime < 3600 * 1000) { return false } - if (thisFeatureEnabled) { + let gameCompletionHistory = GM_getValue('personalGameCompletions', []); const loadGameCompletions = (userid, pageid) => { - console.log(`https://psnine.com/psnid/${userid}/psngame?page=${pageid}`) $.ajax({ type: 'GET', @@ -752,6 +748,7 @@ dataType: 'html', async: true, success: (data, status) => { + if (status === 'success') { // 读取当前页奖杯完成数据 @@ -768,107 +765,46 @@ return [gameID, completion, platinum]; }); - console.log(thisPageCompletions); - // 合并更新历史数据,并确定是否加载下一页 - let loadNext = true; - let comblineflag = false; - - // 1. 合并数据,并当整页数据都没有变化时,不加载下一页 + // 合并数据,遇到和已知条目的进度一样时标记 + let sameItemAppeared = false; thisPageCompletions.forEach((completion) => { const index = gameCompletionHistory.findIndex((historyItem) => historyItem[0] === completion[0]); if (index !== -1) { - if (gameCompletionHistory[index][1] !== completion[1]) { - comblineflag = true; + if (gameCompletionHistory[index][1] === completion[1]) { + sameItemAppeared = true; gameCompletionHistory[index] = completion; } } else { gameCompletionHistory.push(completion); - comblineflag = true; } }) - // 如果最后一页,则停止 + // 如果最后一页,则停止 + let loadNext = true; const totalPageEle = page.querySelectorAll('.page > ul > li > a') const totalPage = parseInt(totalPageEle[totalPageEle.length - 2].innerText); - console.log(totalPage, pageid) if (pageid === totalPage) { loadNext = false } // 保存数据 - console.log(gameCompletionHistory); GM_setValue('personalGameCompletions', gameCompletionHistory); GM_setValue('personalGameCompletionsLastUpdated', new Date().getTime()); - console.log(loadNext, comblineflag) // 执行下一页 - if (loadNext && comblineflag) { + if (loadNext && !sameItemAppeared) { setTimeout(() => { loadGameCompletions(userid, pageid + 1) }, 5000); } - } }, error: (e) => { console.log('loadGameCompletions error', e) }, }) } - - loadGameCompletions(myUserId, 15); + loadGameCompletions(myUserId, 1); } - } bgGetMyGameCompletion(true); - // const savePersonalGameCompletions = (configifneeded) => { - // // if GM_setValue && GM_getValue is enabled - // let thisFeatureEnabled = (configifneeded || true) && (typeof GM_setValue === 'function' && typeof GM_getValue === 'function'); - // const myHomePage = document.querySelectorAll('ul.r li.dropdown ul li a')[0].href; - // thisFeatureEnabled = thisFeatureEnabled && window.location.href.includes(myHomePage); - - // // 2024.07.30 bug fix: 错误地保存他人的游戏完成度。已经修复,但用户端的旧数据需要清除 - // const lasttime = GM_getValue('personalGameCompletionsLastUpdated', 0); - // if (lasttime === 0) { GM_setValue('personalGameCompletions', []); } - - // if (thisFeatureEnabled) { - // // 获得当前页的游戏完成度 - // const tdElements = document.querySelectorAll('table.list tbody > tr'); - // const personalGameCompletions = Array.from(tdElements).map((tr) => { - // const completionElement = tr.querySelector('div.progress > div'); - // const completion = completionElement ? parseFloat(completionElement.textContent) : 0; - // const platinumElement = tr.querySelector('span.text-platinum'); - // const platinum = platinumElement ? platinumElement.textContent === '白1' : false; - // const gameIDElement = tr.querySelector('a'); - // const gameID = gameIDElement.href.match(/\/psngame\/(\d+)/)[1]; - // return [gameID, completion, platinum]; - // }); - - // // 读取已保存的历史 - // const history = GM_getValue('personalGameCompletions', []); - - // // 用当前覆盖历史 - // personalGameCompletions.forEach((currentItem) => { - // const index = history.findIndex((historyItem) => historyItem[0] === currentItem[0]); - // if (index !== -1) { - // history[index] = currentItem; - // } else { - // history.push(currentItem); - // } - // }); - - // // 保存更新后的历史记录 - // GM_setValue('personalGameCompletions', history); - // GM_setValue('personalGameCompletionsLastUpdated', new Date().getTime()); - // return true; - // } - // return false; - // }; - - // 在个人页面或个人游戏列表页更新数据 - if ( - /psnid\/[A-Za-z0-9_-]+\/?$/.test(window.location.href) || /psnid\/[A-Za-z0-9_-]+\/psngame\/?/.test(window.location.href) - ) { - // savePersonalGameCompletions(); - } - if ( /psnid\/[A-Za-z0-9_-]+\/?$/.test(window.location.href) && $('tbody').length > 2 @@ -901,9 +837,6 @@ $('tbody > tr:last').after(nextGameContent); isbool2 = true; gamePageIndex += 1; - - // 同步更新个人游戏完成度 - // savePersonalGameCompletions(); } else { $('#loadingMessage').text('没有更多游戏了...'); } From bb9df66e09c3317c669aa18758f77fefc6062e9a Mon Sep 17 00:00:00 2001 From: kaikaiiiiiii Date: Tue, 30 Jul 2024 09:10:21 +0800 Subject: [PATCH 08/13] lint --- psnineplus.js | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/psnineplus.js b/psnineplus.js index 7f61518..d9834da 100644 --- a/psnineplus.js +++ b/psnineplus.js @@ -402,7 +402,7 @@ $('body,html').animate({ scrollTop: document.body.clientHeight, }, - 500); + 500); }).css({ cursor: 'pointer', }); @@ -724,8 +724,7 @@ */ const bgGetMyGameCompletion = (configifneeded) => { - - let thisFeatureEnabled = (configifneeded || true) && (typeof GM_setValue === 'function' && typeof GM_getValue === 'function'); + const thisFeatureEnabled = (configifneeded || true) && (typeof GM_setValue === 'function' && typeof GM_getValue === 'function'); if (thisFeatureEnabled) { const myHomePage = document.querySelectorAll('ul.r li.dropdown ul li a')[0].href; const myUserId = myHomePage.match(/\/psnid\/([A-Za-z0-9_-]+)/)[1]; @@ -736,21 +735,18 @@ if (lasttime < new Date('2024-07-30 9:00 GMT+0800').getTime()) { GM_setValue('personalGameCompletions', []); } // 小于一小时不执行 - if (new Date().getTime() - lasttime < 3600 * 1000) { return false } + if (new Date().getTime() - lasttime < 3600 * 1000) { return false; } - let gameCompletionHistory = GM_getValue('personalGameCompletions', []); + const gameCompletionHistory = GM_getValue('personalGameCompletions', []); const loadGameCompletions = (userid, pageid) => { - $.ajax({ type: 'GET', url: `https://psnine.com/psnid/${userid}/psngame?page=${pageid}`, dataType: 'html', async: true, success: (data, status) => { - if (status === 'success') { - // 读取当前页奖杯完成数据 const page = document.createElement('html'); page.innerHTML = data; @@ -777,13 +773,13 @@ } else { gameCompletionHistory.push(completion); } - }) + }); // 如果最后一页,则停止 let loadNext = true; - const totalPageEle = page.querySelectorAll('.page > ul > li > a') - const totalPage = parseInt(totalPageEle[totalPageEle.length - 2].innerText); - if (pageid === totalPage) { loadNext = false } + const totalPageEle = page.querySelectorAll('.page > ul > li > a'); + const totalPage = parseInt(totalPageEle[totalPageEle.length - 2].innerText, 10); + if (pageid === totalPage) { loadNext = false; } // 保存数据 GM_setValue('personalGameCompletions', gameCompletionHistory); @@ -791,20 +787,20 @@ // 执行下一页 if (loadNext && !sameItemAppeared) { - setTimeout(() => { loadGameCompletions(userid, pageid + 1) }, 5000); + setTimeout(() => { loadGameCompletions(userid, pageid + 1); }, 5000); } } }, - error: (e) => { console.log('loadGameCompletions error', e) }, - }) - } + error: (e) => { console.log('loadGameCompletions error', e); }, + }); + }; loadGameCompletions(myUserId, 1); } - } + return true; + }; bgGetMyGameCompletion(true); - if ( /psnid\/[A-Za-z0-9_-]+\/?$/.test(window.location.href) && $('tbody').length > 2 @@ -1163,7 +1159,7 @@ .append(` 🔥热门 `); + };color: rgb(255, 255, 255);">🔥热门 `); } }); }; From b62c411fdb0c4eac7da2126de7fafa3ee6afa6e8 Mon Sep 17 00:00:00 2001 From: kaikaiiiiiii Date: Tue, 30 Jul 2024 17:48:34 +0800 Subject: [PATCH 09/13] =?UTF-8?q?=E9=87=8D=E5=86=99=20ajax=20=E7=9A=84?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- psnineplus.js | 233 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 157 insertions(+), 76 deletions(-) diff --git a/psnineplus.js b/psnineplus.js index d9834da..6298619 100644 --- a/psnineplus.js +++ b/psnineplus.js @@ -402,7 +402,7 @@ $('body,html').animate({ scrollTop: document.body.clientHeight, }, - 500); + 500); }).css({ cursor: 'pointer', }); @@ -611,10 +611,8 @@ // 页面加载时执行约战监测功能 if (cacheBattleInfo.lastUpdate && new Date().getTime() - cacheBattleInfo.lastUpdate < settings.BattleInfoUpdateInterval) { updateTopMenuNotice(userBattleMonitors, cacheBattleInfo.list); - console.log('use cached BattleRecuritInfo'); } else { updateBattleRecuritInfo(); - console.log('update BattleRecuritInfo'); } // 在游戏的约战页面添加约战监控按钮 @@ -717,89 +715,172 @@ }`, ); + /* - 在 LocatStorage 中保存个人游戏完成度函数,为避免过多的重复请求,设置了两个结束条件: - 一:更新时间超过一小时 - 二:遇到和已知条目的进度一样时停止,利用更新奖杯一定在前的特性 - */ + 在 LocatStorage 中保存个人游戏完成度函数,为避免过多的页面重复请求,逻辑梳理如下: + + 场景: + 1. 更新的奖杯一定在前,但用户可能会隐藏游戏或解除隐藏,导致内容不再确定。 + 2. 隐藏游戏条目不影响本地已有数据,也不要求本地数据作对应删除,但影响页码数和对应的更新记录 + 3. 由于设置为 Ajax 5 秒翻页,所以存在前几页数据已更新,后几页数据因为用户关闭页面而未更新的情况 + 4. 用户新开坑,可能导致页面数量增长,此时,最后几页也未记录更新时间,但实际是不需要更新的 + + 简化: + 1. 没有时间记录的页面,都需要更新,有时间记录的页面,从前往后更新,遇到已有记录的就停止 + 2. 当用户进行异常操作时,需要自行通过翻页刷新数据 + */ + + // GM_setValue('personalGameCompletions', []); + // console.log(GM_getValue('personalGameCompletions', [])); + // GM_setValue('personalGameCompletionsLastUpdate', []); + + const parseCompletionPage = (content) => { + + // 游戏进度信息 + const tdElements = content.querySelectorAll('table.list tbody > tr'); + const thisPageCompletions = Array.from(tdElements).map((tr) => { + const completionElement = tr.querySelector('div.progress > div'); + const completion = completionElement ? parseFloat(completionElement.textContent) : 0; + const platinumElement = tr.querySelector('span.text-platinum'); + const platinum = platinumElement ? platinumElement.textContent === '白1' : false; + const gameIDElement = tr.querySelector('a'); + const gameID = gameIDElement.href.match(/\/psngame\/(\d+)/)[1]; + return [gameID, completion, platinum]; + }); - const bgGetMyGameCompletion = (configifneeded) => { - const thisFeatureEnabled = (configifneeded || true) && (typeof GM_setValue === 'function' && typeof GM_getValue === 'function'); - if (thisFeatureEnabled) { - const myHomePage = document.querySelectorAll('ul.r li.dropdown ul li a')[0].href; - const myUserId = myHomePage.match(/\/psnid\/([A-Za-z0-9_-]+)/)[1]; - - const lasttime = GM_getValue('personalGameCompletionsLastUpdated', 0); - - // 2024.07.30 bug fix: 错误地保存他人的游戏完成度。已经修复,但用户端的旧数据需要清除 - if (lasttime < new Date('2024-07-30 9:00 GMT+0800').getTime()) { GM_setValue('personalGameCompletions', []); } - - // 小于一小时不执行 - if (new Date().getTime() - lasttime < 3600 * 1000) { return false; } - - const gameCompletionHistory = GM_getValue('personalGameCompletions', []); - - const loadGameCompletions = (userid, pageid) => { - $.ajax({ - type: 'GET', - url: `https://psnine.com/psnid/${userid}/psngame?page=${pageid}`, - dataType: 'html', - async: true, - success: (data, status) => { - if (status === 'success') { - // 读取当前页奖杯完成数据 - const page = document.createElement('html'); - page.innerHTML = data; - const tdElements = page.querySelectorAll('table.list tbody > tr'); - const thisPageCompletions = Array.from(tdElements).map((tr) => { - const completionElement = tr.querySelector('div.progress > div'); - const completion = completionElement ? parseFloat(completionElement.textContent) : 0; - const platinumElement = tr.querySelector('span.text-platinum'); - const platinum = platinumElement ? platinumElement.textContent === '白1' : false; - const gameIDElement = tr.querySelector('a'); - const gameID = gameIDElement.href.match(/\/psngame\/(\d+)/)[1]; - return [gameID, completion, platinum]; - }); + // 获得总页数和总条目数 + let totalPages = totalItems = 0; + const PaginationEle = content.querySelectorAll('.page > ul > li > a'); + if (PaginationEle.length > 2) { + totalPages = parseInt(PaginationEle[PaginationEle.length - 2].innerText, 10); + totalItems = parseInt(PaginationEle[PaginationEle.length - 1].innerText, 10); + } - // 合并数据,遇到和已知条目的进度一样时标记 - let sameItemAppeared = false; - thisPageCompletions.forEach((completion) => { - const index = gameCompletionHistory.findIndex((historyItem) => historyItem[0] === completion[0]); - if (index !== -1) { - if (gameCompletionHistory[index][1] === completion[1]) { - sameItemAppeared = true; - gameCompletionHistory[index] = completion; - } - } else { - gameCompletionHistory.push(completion); - } - }); + return { totalPages, totalItems, thisPageCompletions } + } - // 如果最后一页,则停止 - let loadNext = true; - const totalPageEle = page.querySelectorAll('.page > ul > li > a'); - const totalPage = parseInt(totalPageEle[totalPageEle.length - 2].innerText, 10); - if (pageid === totalPage) { loadNext = false; } + const updateCompletions = (updateList) => { - // 保存数据 - GM_setValue('personalGameCompletions', gameCompletionHistory); - GM_setValue('personalGameCompletionsLastUpdated', new Date().getTime()); + let gameCompletionHistory = GM_getValue('personalGameCompletions', []); + let count = 0 - // 执行下一页 - if (loadNext && !sameItemAppeared) { - setTimeout(() => { loadGameCompletions(userid, pageid + 1); }, 5000); - } + updateList.forEach(completion => { + const index = gameCompletionHistory.findIndex(historyItem => historyItem[0] === completion[0]); + if (index !== -1) { + if (gameCompletionHistory[index][1] !== completion[1]) { + gameCompletionHistory[index] = completion; + count++ + } + } else { + gameCompletionHistory.push(completion); + count++ + } + }); + + GM_setValue('personalGameCompletions', gameCompletionHistory); + + return count + } + + + // 后台更新主函数 + const loadGameCompletions = (userid, startPageID) => { + console.log(`https://psnine.com/psnid/${userid}/psngame?page=${startPageID}`) + $.ajax({ + type: 'GET', + url: `https://psnine.com/psnid/${userid}/psngame?page=${startPageID}`, + dataType: 'html', + async: true, + success: (data, status) => { + if (status === 'success') { + + // 读取历史数据 + const pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []); + + // 读取当前页奖杯完成数据 + const page = document.createElement('html'); + page.innerHTML = data; + let { totalPages, totalItems, thisPageCompletions } = parseCompletionPage(page) + totalPages = totalPages || pagesUpdateTime.length + let addCounts = updateCompletions(thisPageCompletions) + + // 更新页面记录时间 + pagesUpdateTime[startPageID - 1] = new Date().getTime(); + GM_setValue('personalGameCompletionsLastUpdate', pagesUpdateTime); + + // 根据规则计算下一页 + if (addCounts == thisPageCompletions.length && startPageID < totalPages) { + setTimeout(() => { loadGameCompletions(userid, startPageID + 1) }, 5000); + return true + } else { + const fullfilledUpdateTime = pagesUpdateTime.concat(Array(totalPages - pagesUpdateTime.length).fill(0)) + const nextIdx = fullfilledUpdateTime.findIndex(time => { + return time == undefined || time == 0 || time == null + }); + + if (nextIdx !== -1) { + setTimeout(() => { loadGameCompletions(userid, nextIdx + 1) }, 5000); + return true } - }, - error: (e) => { console.log('loadGameCompletions error', e); }, - }); - }; + } + } + }, + error: (e) => { console.log('loadGameCompletions error', e); }, + }); + }; + + // 后台更新频次控制 + const bgUpdateMyGameCompletion = () => { + + // 读取记录的各页更新时间 + let pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []); + + // 2024.07.30 bug fix: 错误地保存他人的游戏完成度 - 已经修复,但用户端的旧数据需要清除 + if (pagesUpdateTime[0] === undefined || pagesUpdateTime[0] < 1722301200000) { // 2024-07-30 9:00 GMT+0800 + GM_setValue('personalGameCompletions', []); + } + + let now = new Date().getTime() + // if (now - pagesUpdateTime[0] > 60 * 60 * 1000) { + if (pagesUpdateTime[0] == undefined || now - pagesUpdateTime[0] > 1) { loadGameCompletions(myUserId, 1); } - return true; + }; - bgGetMyGameCompletion(true); + // 获取个人 ID + const myHomePage = document.querySelectorAll('ul.r li.dropdown ul li a')[0].href; + const myUserId = myHomePage.match(/\/psnid\/([A-Za-z0-9_-]+)/)[1] || "*" + const myGamePageURLRegex = new RegExp(`psnid\/${myUserId}/?(?:psngame(?:\\?page=(\\d+))?|$)`); + // match: https://psnine.com/psnid/kaikaiiiiiiiwu + // match: https://psnine.com/psnid/kaikaiiiiiiiwu/ + // match: https://psnine.com/psnid/kaikaiiiiiiiwu/psngame + // match: https://psnine.com/psnid/kaikaiiiiiiiwu/psngame?page=2 + // dismatch: https://psnine.com/psnid/kaikaiiiiiiiwu/comment + + // 在用户浏览个人页面或个人游戏列表页时,无视 Interval 白嫖一次数据更新 + if (myGamePageURLRegex.test(window.location.href)) { + + let { totalPages, totalItems, thisPageCompletions } = parseCompletionPage(document) + const pageid = window.location.href.match(myGamePageURLRegex)[1] || 1; + + const updateItemCounts = updateCompletions(thisPageCompletions) + + let pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []); + pagesUpdateTime[pageid - 1] = new Date().getTime(); + GM_setValue('personalGameCompletionsLastUpdate', pagesUpdateTime); + + if (updateItemCounts <= totalItems) { + loadGameCompletions(myUserId, 1) + } + } else { + + // 固定更新 + bgUpdateMyGameCompletion(); + } + + + //////////////////////////////////////////////////////////////////////////////// if ( /psnid\/[A-Za-z0-9_-]+\/?$/.test(window.location.href) @@ -1159,7 +1240,7 @@ .append(` 🔥热门 `); + };color: rgb(255, 255, 255);">🔥热门 `); } }); }; From e56b2abf140748e99593b14de4adc5d09cc93634 Mon Sep 17 00:00:00 2001 From: kaikaiiiiiii Date: Tue, 30 Jul 2024 18:20:12 +0800 Subject: [PATCH 10/13] bug fix --- psnineplus.js | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/psnineplus.js b/psnineplus.js index 6298619..5ad72ce 100644 --- a/psnineplus.js +++ b/psnineplus.js @@ -726,12 +726,12 @@ 4. 用户新开坑,可能导致页面数量增长,此时,最后几页也未记录更新时间,但实际是不需要更新的 简化: - 1. 没有时间记录的页面,都需要更新,有时间记录的页面,从前往后更新,遇到已有记录的就停止 + 1. 没有时间记录的页面,都需要更新,有时间记录的页面,从前往后更新,遇到无变化奖杯条目的就停止 2. 当用户进行异常操作时,需要自行通过翻页刷新数据 */ // GM_setValue('personalGameCompletions', []); - // console.log(GM_getValue('personalGameCompletions', [])); + console.log(GM_getValue('personalGameCompletions', [])); // GM_setValue('personalGameCompletionsLastUpdate', []); const parseCompletionPage = (content) => { @@ -762,24 +762,26 @@ const updateCompletions = (updateList) => { let gameCompletionHistory = GM_getValue('personalGameCompletions', []); - let count = 0 + let updateCount = 0 updateList.forEach(completion => { + const index = gameCompletionHistory.findIndex(historyItem => historyItem[0] === completion[0]); if (index !== -1) { if (gameCompletionHistory[index][1] !== completion[1]) { gameCompletionHistory[index] = completion; - count++ + updateCount++ } } else { gameCompletionHistory.push(completion); - count++ + updateCount++ } + }); GM_setValue('personalGameCompletions', gameCompletionHistory); - - return count + let nowRecordsNumber = gameCompletionHistory.length; + return { updateCount, nowRecordsNumber } } @@ -801,15 +803,15 @@ const page = document.createElement('html'); page.innerHTML = data; let { totalPages, totalItems, thisPageCompletions } = parseCompletionPage(page) - totalPages = totalPages || pagesUpdateTime.length - let addCounts = updateCompletions(thisPageCompletions) + totalPages = totalPages || pagesUpdateTime.length || 1 + let { addCounts, totalRecords } = updateCompletions(thisPageCompletions) // 更新页面记录时间 pagesUpdateTime[startPageID - 1] = new Date().getTime(); GM_setValue('personalGameCompletionsLastUpdate', pagesUpdateTime); // 根据规则计算下一页 - if (addCounts == thisPageCompletions.length && startPageID < totalPages) { + if (addCounts == thisPageCompletions.length && startPageID < totalPages - 1) { setTimeout(() => { loadGameCompletions(userid, startPageID + 1) }, 5000); return true } else { @@ -817,11 +819,11 @@ const nextIdx = fullfilledUpdateTime.findIndex(time => { return time == undefined || time == 0 || time == null }); - if (nextIdx !== -1) { setTimeout(() => { loadGameCompletions(userid, nextIdx + 1) }, 5000); return true } + return false } } }, @@ -836,7 +838,7 @@ let pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []); // 2024.07.30 bug fix: 错误地保存他人的游戏完成度 - 已经修复,但用户端的旧数据需要清除 - if (pagesUpdateTime[0] === undefined || pagesUpdateTime[0] < 1722301200000) { // 2024-07-30 9:00 GMT+0800 + if (pagesUpdateTime[0] === undefined || pagesUpdateTime[0] < 1722333600000) { // 2024-07-30 18:00 GMT+0800 GM_setValue('personalGameCompletions', []); } @@ -862,16 +864,17 @@ if (myGamePageURLRegex.test(window.location.href)) { let { totalPages, totalItems, thisPageCompletions } = parseCompletionPage(document) - const pageid = window.location.href.match(myGamePageURLRegex)[1] || 1; + const pageid = parseInt(window.location.href.match(myGamePageURLRegex)[1]) || 1; - const updateItemCounts = updateCompletions(thisPageCompletions) + const { addCounts, totalRecords } = updateCompletions(thisPageCompletions) let pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []); pagesUpdateTime[pageid - 1] = new Date().getTime(); GM_setValue('personalGameCompletionsLastUpdate', pagesUpdateTime); - if (updateItemCounts <= totalItems) { - loadGameCompletions(myUserId, 1) + if (totalRecords < totalItems || totalItems === 0) { + let nextPageID = pageid == 1 ? 2 : 1 + loadGameCompletions(myUserId, nextPageID) } } else { From 8e2ec8358d347aeb71eb8b3cfbd20001f3368f1b Mon Sep 17 00:00:00 2001 From: kaikaiiiiiii Date: Tue, 30 Jul 2024 18:31:53 +0800 Subject: [PATCH 11/13] clear --- psnineplus.js | 52 +++++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/psnineplus.js b/psnineplus.js index 5ad72ce..7aefc92 100644 --- a/psnineplus.js +++ b/psnineplus.js @@ -715,7 +715,6 @@ }`, ); - /* 在 LocatStorage 中保存个人游戏完成度函数,为避免过多的页面重复请求,逻辑梳理如下: @@ -731,7 +730,7 @@ */ // GM_setValue('personalGameCompletions', []); - console.log(GM_getValue('personalGameCompletions', [])); + // console.log(GM_getValue('personalGameCompletions', [])); // GM_setValue('personalGameCompletionsLastUpdate', []); const parseCompletionPage = (content) => { @@ -765,18 +764,14 @@ let updateCount = 0 updateList.forEach(completion => { - const index = gameCompletionHistory.findIndex(historyItem => historyItem[0] === completion[0]); if (index !== -1) { - if (gameCompletionHistory[index][1] !== completion[1]) { - gameCompletionHistory[index] = completion; - updateCount++ - } + if (gameCompletionHistory[index][1] !== completion[1]) { updateCount++ } + gameCompletionHistory[index] = completion; } else { gameCompletionHistory.push(completion); updateCount++ } - }); GM_setValue('personalGameCompletions', gameCompletionHistory); @@ -787,7 +782,7 @@ // 后台更新主函数 const loadGameCompletions = (userid, startPageID) => { - console.log(`https://psnine.com/psnid/${userid}/psngame?page=${startPageID}`) + // console.log(`https://psnine.com/psnid/${userid}/psngame?page=${startPageID}`) $.ajax({ type: 'GET', url: `https://psnine.com/psnid/${userid}/psngame?page=${startPageID}`, @@ -802,9 +797,9 @@ // 读取当前页奖杯完成数据 const page = document.createElement('html'); page.innerHTML = data; - let { totalPages, totalItems, thisPageCompletions } = parseCompletionPage(page) - totalPages = totalPages || pagesUpdateTime.length || 1 - let { addCounts, totalRecords } = updateCompletions(thisPageCompletions) + let { totalPages, totalItems, thisPageCompletions } = parseCompletionPage(page); + totalPages = totalPages || pagesUpdateTime.length || 1; + let { addCounts, totalRecords } = updateCompletions(thisPageCompletions); // 更新页面记录时间 pagesUpdateTime[startPageID - 1] = new Date().getTime(); @@ -825,6 +820,7 @@ } return false } + } }, error: (e) => { console.log('loadGameCompletions error', e); }, @@ -833,21 +829,11 @@ // 后台更新频次控制 const bgUpdateMyGameCompletion = () => { - - // 读取记录的各页更新时间 - let pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []); - - // 2024.07.30 bug fix: 错误地保存他人的游戏完成度 - 已经修复,但用户端的旧数据需要清除 - if (pagesUpdateTime[0] === undefined || pagesUpdateTime[0] < 1722333600000) { // 2024-07-30 18:00 GMT+0800 - GM_setValue('personalGameCompletions', []); - } - - let now = new Date().getTime() - // if (now - pagesUpdateTime[0] > 60 * 60 * 1000) { - if (pagesUpdateTime[0] == undefined || now - pagesUpdateTime[0] > 1) { + const pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []); + const now = new Date().getTime() + if (pagesUpdateTime[0] == undefined || now - pagesUpdateTime[0] > 60 * 60 * 1000) { loadGameCompletions(myUserId, 1); } - }; // 获取个人 ID @@ -860,26 +846,30 @@ // match: https://psnine.com/psnid/kaikaiiiiiiiwu/psngame?page=2 // dismatch: https://psnine.com/psnid/kaikaiiiiiiiwu/comment + // 2024.07.30 bug fix: 错误地保存他人的游戏完成度 - 已经修复,但用户端的旧数据需要清除 + let pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []); + if (pagesUpdateTime[0] === undefined || pagesUpdateTime[0] < 1722333600000) { // 2024-07-30 18:00 GMT+0800 + GM_setValue('personalGameCompletions', []); + } + // 在用户浏览个人页面或个人游戏列表页时,无视 Interval 白嫖一次数据更新 if (myGamePageURLRegex.test(window.location.href)) { - let { totalPages, totalItems, thisPageCompletions } = parseCompletionPage(document) + let pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []); const pageid = parseInt(window.location.href.match(myGamePageURLRegex)[1]) || 1; + const { totalPages, totalItems, thisPageCompletions } = parseCompletionPage(document) const { addCounts, totalRecords } = updateCompletions(thisPageCompletions) - let pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []); pagesUpdateTime[pageid - 1] = new Date().getTime(); GM_setValue('personalGameCompletionsLastUpdate', pagesUpdateTime); - if (totalRecords < totalItems || totalItems === 0) { let nextPageID = pageid == 1 ? 2 : 1 loadGameCompletions(myUserId, nextPageID) } - } else { - // 固定更新 - bgUpdateMyGameCompletion(); + } else { + bgUpdateMyGameCompletion(); // 定时更新 } From 42dd423e322fe56fe2a70edaf33dfd5bc9dde30f Mon Sep 17 00:00:00 2001 From: kaikaiiiiiii Date: Tue, 30 Jul 2024 19:00:36 +0800 Subject: [PATCH 12/13] lint --- psnineplus.js | 121 ++++++++++++++++++++++++-------------------------- 1 file changed, 57 insertions(+), 64 deletions(-) diff --git a/psnineplus.js b/psnineplus.js index 7aefc92..4f2a16d 100644 --- a/psnineplus.js +++ b/psnineplus.js @@ -402,7 +402,7 @@ $('body,html').animate({ scrollTop: document.body.clientHeight, }, - 500); + 500); }).css({ cursor: 'pointer', }); @@ -717,14 +717,14 @@ /* 在 LocatStorage 中保存个人游戏完成度函数,为避免过多的页面重复请求,逻辑梳理如下: - + 场景: - 1. 更新的奖杯一定在前,但用户可能会隐藏游戏或解除隐藏,导致内容不再确定。 + 1. 更新的奖杯一定在前,但用户可能会隐藏游戏或解除隐藏,导致内容不再确定。 2. 隐藏游戏条目不影响本地已有数据,也不要求本地数据作对应删除,但影响页码数和对应的更新记录 3. 由于设置为 Ajax 5 秒翻页,所以存在前几页数据已更新,后几页数据因为用户关闭页面而未更新的情况 4. 用户新开坑,可能导致页面数量增长,此时,最后几页也未记录更新时间,但实际是不需要更新的 - 简化: + 简化: 1. 没有时间记录的页面,都需要更新,有时间记录的页面,从前往后更新,遇到无变化奖杯条目的就停止 2. 当用户进行异常操作时,需要自行通过翻页刷新数据 */ @@ -734,7 +734,6 @@ // GM_setValue('personalGameCompletionsLastUpdate', []); const parseCompletionPage = (content) => { - // 游戏进度信息 const tdElements = content.querySelectorAll('table.list tbody > tr'); const thisPageCompletions = Array.from(tdElements).map((tr) => { @@ -748,37 +747,36 @@ }); // 获得总页数和总条目数 - let totalPages = totalItems = 0; + let totalPages = 0; let + totalItems = 0; const PaginationEle = content.querySelectorAll('.page > ul > li > a'); if (PaginationEle.length > 2) { totalPages = parseInt(PaginationEle[PaginationEle.length - 2].innerText, 10); totalItems = parseInt(PaginationEle[PaginationEle.length - 1].innerText, 10); } - return { totalPages, totalItems, thisPageCompletions } - } + return { totalPages, totalItems, thisPageCompletions }; + }; const updateCompletions = (updateList) => { + const gameCompletionHistory = GM_getValue('personalGameCompletions', []); + let addCounts = 0; - let gameCompletionHistory = GM_getValue('personalGameCompletions', []); - let updateCount = 0 - - updateList.forEach(completion => { - const index = gameCompletionHistory.findIndex(historyItem => historyItem[0] === completion[0]); + updateList.forEach((completion) => { + const index = gameCompletionHistory.findIndex((historyItem) => historyItem[0] === completion[0]); if (index !== -1) { - if (gameCompletionHistory[index][1] !== completion[1]) { updateCount++ } + if (gameCompletionHistory[index][1] !== completion[1]) { addCounts += 1; } gameCompletionHistory[index] = completion; } else { gameCompletionHistory.push(completion); - updateCount++ + addCounts += 1; } }); GM_setValue('personalGameCompletions', gameCompletionHistory); - let nowRecordsNumber = gameCompletionHistory.length; - return { updateCount, nowRecordsNumber } - } - + const totalRecords = gameCompletionHistory.length; + return { addCounts, totalRecords }; + }; // 后台更新主函数 const loadGameCompletions = (userid, startPageID) => { @@ -790,90 +788,85 @@ async: true, success: (data, status) => { if (status === 'success') { - // 读取历史数据 const pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []); + // 2024.07.30 bug fix: 错误地保存他人的游戏完成度 - 已经修复,但用户端的旧数据需要清除 + if (Array.isArray(pagesUpdateTime) === false + || pagesUpdateTime[0] === undefined + || pagesUpdateTime[0] < 1722333600000 // 2024-07-30 18:00 GMT+0800 + ) { + GM_setValue('personalGameCompletions', []); + } // 读取当前页奖杯完成数据 const page = document.createElement('html'); page.innerHTML = data; - let { totalPages, totalItems, thisPageCompletions } = parseCompletionPage(page); - totalPages = totalPages || pagesUpdateTime.length || 1; - let { addCounts, totalRecords } = updateCompletions(thisPageCompletions); + const o = parseCompletionPage(page); + const { thisPageCompletions } = o; + const totalPages = o.totalPages || pagesUpdateTime.length || 1; + const { addCounts } = updateCompletions(thisPageCompletions); // 更新页面记录时间 pagesUpdateTime[startPageID - 1] = new Date().getTime(); GM_setValue('personalGameCompletionsLastUpdate', pagesUpdateTime); // 根据规则计算下一页 - if (addCounts == thisPageCompletions.length && startPageID < totalPages - 1) { - setTimeout(() => { loadGameCompletions(userid, startPageID + 1) }, 5000); - return true - } else { - const fullfilledUpdateTime = pagesUpdateTime.concat(Array(totalPages - pagesUpdateTime.length).fill(0)) - const nextIdx = fullfilledUpdateTime.findIndex(time => { - return time == undefined || time == 0 || time == null - }); - if (nextIdx !== -1) { - setTimeout(() => { loadGameCompletions(userid, nextIdx + 1) }, 5000); - return true - } - return false + if (addCounts === thisPageCompletions.length && startPageID < totalPages - 1) { + setTimeout(() => { loadGameCompletions(userid, startPageID + 1); }, 5000); + return true; } - + const fullfilledUpdateTime = pagesUpdateTime.concat(Array(totalPages - pagesUpdateTime.length).fill(0)); + const nextIdx = fullfilledUpdateTime.findIndex((time) => time === undefined || time === 0 || time === null); + if (nextIdx !== -1) { + setTimeout(() => { loadGameCompletions(userid, nextIdx + 1); }, 5000); + return true; + } + return false; } + return true; }, error: (e) => { console.log('loadGameCompletions error', e); }, }); }; - // 后台更新频次控制 - const bgUpdateMyGameCompletion = () => { - const pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []); - const now = new Date().getTime() - if (pagesUpdateTime[0] == undefined || now - pagesUpdateTime[0] > 60 * 60 * 1000) { - loadGameCompletions(myUserId, 1); - } - }; - // 获取个人 ID const myHomePage = document.querySelectorAll('ul.r li.dropdown ul li a')[0].href; - const myUserId = myHomePage.match(/\/psnid\/([A-Za-z0-9_-]+)/)[1] || "*" - const myGamePageURLRegex = new RegExp(`psnid\/${myUserId}/?(?:psngame(?:\\?page=(\\d+))?|$)`); + const myUserId = myHomePage.match(/\/psnid\/([A-Za-z0-9_-]+)/)[1] || '*'; + const myGamePageURLRegex = new RegExp(`psnid/${myUserId}/?(?:psngame(?:\\?page=(\\d+))?|$)`); // match: https://psnine.com/psnid/kaikaiiiiiiiwu // match: https://psnine.com/psnid/kaikaiiiiiiiwu/ // match: https://psnine.com/psnid/kaikaiiiiiiiwu/psngame // match: https://psnine.com/psnid/kaikaiiiiiiiwu/psngame?page=2 // dismatch: https://psnine.com/psnid/kaikaiiiiiiiwu/comment - // 2024.07.30 bug fix: 错误地保存他人的游戏完成度 - 已经修复,但用户端的旧数据需要清除 - let pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []); - if (pagesUpdateTime[0] === undefined || pagesUpdateTime[0] < 1722333600000) { // 2024-07-30 18:00 GMT+0800 - GM_setValue('personalGameCompletions', []); - } + // 后台更新频次控制 + const bgUpdateMyGameCompletion = () => { + const pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []); + const now = new Date().getTime(); + if (pagesUpdateTime[0] === undefined || now - pagesUpdateTime[0] > 60 * 60 * 1000) { + loadGameCompletions(myUserId, 1); + } + }; // 在用户浏览个人页面或个人游戏列表页时,无视 Interval 白嫖一次数据更新 if (myGamePageURLRegex.test(window.location.href)) { + const pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []); + const pageid = parseInt(window.location.href.match(myGamePageURLRegex)[1], 10) || 1; - let pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []); - const pageid = parseInt(window.location.href.match(myGamePageURLRegex)[1]) || 1; - - const { totalPages, totalItems, thisPageCompletions } = parseCompletionPage(document) - const { addCounts, totalRecords } = updateCompletions(thisPageCompletions) + const { totalItems, thisPageCompletions } = parseCompletionPage(document); + const { totalRecords } = updateCompletions(thisPageCompletions); pagesUpdateTime[pageid - 1] = new Date().getTime(); GM_setValue('personalGameCompletionsLastUpdate', pagesUpdateTime); if (totalRecords < totalItems || totalItems === 0) { - let nextPageID = pageid == 1 ? 2 : 1 - loadGameCompletions(myUserId, nextPageID) + const nextPageID = pageid === 1 ? 2 : 1; + loadGameCompletions(myUserId, nextPageID); } - } else { bgUpdateMyGameCompletion(); // 定时更新 } - - //////////////////////////////////////////////////////////////////////////////// + /// ///////////////////////////////////////////////////////////////////////////// if ( /psnid\/[A-Za-z0-9_-]+\/?$/.test(window.location.href) @@ -1233,7 +1226,7 @@ .append(` 🔥热门 `); + };color: rgb(255, 255, 255);">🔥热门 `); } }); }; From 9f5074ac31b606f9dc935bbeca68c20992d0fcb0 Mon Sep 17 00:00:00 2001 From: kaikaiiiiiii Date: Tue, 30 Jul 2024 19:07:13 +0800 Subject: [PATCH 13/13] rubust --- psnineplus.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/psnineplus.js b/psnineplus.js index 4f2a16d..159dcde 100644 --- a/psnineplus.js +++ b/psnineplus.js @@ -402,7 +402,7 @@ $('body,html').animate({ scrollTop: document.body.clientHeight, }, - 500); + 500); }).css({ cursor: 'pointer', }); @@ -796,6 +796,7 @@ || pagesUpdateTime[0] < 1722333600000 // 2024-07-30 18:00 GMT+0800 ) { GM_setValue('personalGameCompletions', []); + pagesUpdateTime = []; } // 读取当前页奖杯完成数据 @@ -1226,7 +1227,7 @@ .append(` 🔥热门 `); + };color: rgb(255, 255, 255);">🔥热门 `); } }); };