From 96cddc045cb506e9ce19f5d41ae010a7e8f26528 Mon Sep 17 00:00:00 2001 From: Tianyu Wu Date: Wed, 6 Dec 2023 23:54:41 -0500 Subject: [PATCH 1/5] Fixed failed blocking. --- psnineplus.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psnineplus.js b/psnineplus.js index f2174f3..7cf147c 100644 --- a/psnineplus.js +++ b/psnineplus.js @@ -945,7 +945,7 @@ } : (el) => el.parents(parent).remove(); let removed = 0; $(psnnode).each((i, el) => { - psnInfo = psnInfoGetter($(el)); + psnInfo = psnInfoGetter($(el)).trim(); if (userListLowerCase.find(userNameCheckerFinal) !== undefined) { remover($(el)); removed += 1; From 2b565084468f19884f37d6cdcba535c8a2c12c4e Mon Sep 17 00:00:00 2001 From: Tianyu Wu Date: Sun, 7 Apr 2024 15:12:22 -0400 Subject: [PATCH 2/5] [feature] a new function that expands collapsed subcomments --- psnineplus.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/psnineplus.js b/psnineplus.js index 7cf147c..eab06e3 100644 --- a/psnineplus.js +++ b/psnineplus.js @@ -2591,6 +2591,56 @@ }; trophyTipsEnhancement(); + // 奖杯心得及游戏评论页面展开二级评论 + const expandCollapsedSubcomments = () => { + let pageType; + if (/trophy\/\d+\/?$/.test(window.location.href)) pageType = 'trophy tips'; + else if (/psngame\/\d+\/comment\/?$/.test(window.location.href)) pageType = 'game comment'; + else return; + let commentMetas; + switch (pageType) { + case 'trophy tips': + commentMetas = document.querySelectorAll('div.min-inner.mt40 > div.box.mt20 > ul.list > li > div.ml64 > div.meta:not(.pb10)'); + break; + case 'game comment': + commentMetas = document.querySelectorAll('div.min-inner.mt40 > div.box > ul.list > li > div.ml64 > div.meta:not(.pb10)'); + break; + default: + return; + } + const subcommentAlreadyExpanded = (subcommentLink) => Boolean($(subcommentLink).parents('li')[0].querySelector('div.sonlistmark.ml64.mt10 > ul.sonlist > li')); + const subcommentLinks = []; + commentMetas.forEach((commentMeta) => { + const subcommentLink = commentMeta.querySelector('span.r > a:nth-child(2)'); + if (/评论\(\d+\)/.test(subcommentLink.innerText.trim()) && !subcommentAlreadyExpanded(subcommentLink)) subcommentLinks.push(subcommentLink); + }); + if (subcommentLinks.length === 0) return; + let subcommentLinkIndex = 0; + let subcommentLinkClicked = false; + let subcommentLinkFails; + repeatUntilSuccessful(() => { + const subcommentLink = subcommentLinks[subcommentLinkIndex]; + if (!subcommentLinkClicked) { + subcommentLink.click(); + subcommentLinkClicked = true; + subcommentLinkFails = 0; + } + if (subcommentAlreadyExpanded(subcommentLink)) { + subcommentLinkIndex += 1; + subcommentLinkClicked = false; + if (subcommentLinkIndex === subcommentLinks.length) return true; + } else { + subcommentLinkFails += 1; + if (subcommentLinkFails >= 5) { + subcommentLinkIndex += 1; + subcommentLinkClicked = false; + } + } + return false; + }, 200); + }; + expandCollapsedSubcomments(); + // P9时间格式转换函数 function p9TimeTextParser(timestampText) { // returns UTC time let array = null; From 6c3b793aafa3b1fe6f2912b1f2ddfa3f8c3eede4 Mon Sep 17 00:00:00 2001 From: Tianyu Wu Date: Sun, 7 Apr 2024 16:35:27 -0400 Subject: [PATCH 3/5] [improve] changed to lazy-loading for subcomments --- psnineplus.js | 64 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/psnineplus.js b/psnineplus.js index eab06e3..bec7a4a 100644 --- a/psnineplus.js +++ b/psnineplus.js @@ -2615,29 +2615,51 @@ if (/评论\(\d+\)/.test(subcommentLink.innerText.trim()) && !subcommentAlreadyExpanded(subcommentLink)) subcommentLinks.push(subcommentLink); }); if (subcommentLinks.length === 0) return; - let subcommentLinkIndex = 0; - let subcommentLinkClicked = false; - let subcommentLinkFails; - repeatUntilSuccessful(() => { - const subcommentLink = subcommentLinks[subcommentLinkIndex]; - if (!subcommentLinkClicked) { - subcommentLink.click(); - subcommentLinkClicked = true; - subcommentLinkFails = 0; - } - if (subcommentAlreadyExpanded(subcommentLink)) { - subcommentLinkIndex += 1; - subcommentLinkClicked = false; - if (subcommentLinkIndex === subcommentLinks.length) return true; - } else { - subcommentLinkFails += 1; - if (subcommentLinkFails >= 5) { - subcommentLinkIndex += 1; - subcommentLinkClicked = false; + const clickedLinks = []; + const links = []; + let activeIntersectionEvents = 0; + const observer = new IntersectionObserver((entries) => { + entries.forEach((entry) => { + if (entry.isIntersecting) { + const link = entries[0].target; + if (clickedLinks.indexOf(link) < 0 && links.indexOf(link) < 0) links.push(link); } + }); + activeIntersectionEvents += 1; + if (activeIntersectionEvents > 1) { + activeIntersectionEvents -= 1; + return; } - return false; - }, 200); + let linkClickStatus = false; + let linkFails; + repeatUntilSuccessful(() => { + if (links.length === 0) { + activeIntersectionEvents -= 1; + return true; + } + const link = links[0]; + if (!linkClickStatus) { + link.click(); + // console.log(`clicked subcomment link #${subcommentLinks.indexOf(link)}`); + linkClickStatus = true; + linkFails = 0; + } + if (subcommentAlreadyExpanded(link)) { + linkClickStatus = false; + clickedLinks.push(links.shift()); + } else { + linkFails += 1; + if (linkFails % 5 === 0) { + link.click(); + // console.log(`re-clicked subcomment link #${subcommentLinks.indexOf(link)}`); + } + } + return false; + }, 200); + }, { rootMargin: '0px', threshold: [0.5] }); + subcommentLinks.forEach((subcommentLink) => { + observer.observe(subcommentLink); + }); }; expandCollapsedSubcomments(); From a560fd3760c20318734da49a39663c07d1fa170f Mon Sep 17 00:00:00 2001 From: Tianyu Wu Date: Sun, 7 Apr 2024 16:51:39 -0400 Subject: [PATCH 4/5] [chore] added a settings switch for subcomment expansion --- psnineplus.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/psnineplus.js b/psnineplus.js index bec7a4a..e8caa01 100644 --- a/psnineplus.js +++ b/psnineplus.js @@ -86,6 +86,8 @@ referGameVariants: true, // 查询游戏版本优先使用搜索 preferSearchForFindingVariants: false, + // 展开隐藏的子评论 + expandCollapsedSubcomments: true, }; if (window.localStorage) { if (window.localStorage['psnine-night-mode-CSS-settings']) { @@ -2592,7 +2594,8 @@ trophyTipsEnhancement(); // 奖杯心得及游戏评论页面展开二级评论 - const expandCollapsedSubcomments = () => { + const expandCollapsedSubcomments = (on) => { + if (!on) return; let pageType; if (/trophy\/\d+\/?$/.test(window.location.href)) pageType = 'trophy tips'; else if (/psngame\/\d+\/comment\/?$/.test(window.location.href)) pageType = 'game comment'; @@ -2661,7 +2664,7 @@ observer.observe(subcommentLink); }); }; - expandCollapsedSubcomments(); + expandCollapsedSubcomments(settings.expandCollapsedSubcomments); // P9时间格式转换函数 function p9TimeTextParser(timestampText) { // returns UTC time @@ -3363,13 +3366,14 @@ 'fixHTTPLinks', 'referGameVariants', 'preferSearchForFindingVariants', + 'expandCollapsedSubcomments', ]; // 只有true/false或者enum的设置项 $('.header .dropdown ul').append(`
  • 插件设置
  • `); const visiblePageHeight = $(window.top).height(); $('body').append(` -

    PSN中文网功能增强插件设置

    `); +

    PSN中文网功能增强插件设置

    `); // 点击打开设置面板 $('#psnine-enhanced-version-opensetting').on('click', () => { $('.setting-panel-box').addClass('show'); From f4ef6ee3d096bc639cba4948029be945e6af2b74 Mon Sep 17 00:00:00 2001 From: Tianyu Wu Date: Sun, 7 Apr 2024 16:53:25 -0400 Subject: [PATCH 5/5] [fix] hide the subcomment input when auto-expanding; bumped up version number --- package-lock.json | 4 ++-- package.json | 2 +- psnineplus.js | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 39e7b83..1d3c966 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "psnine-enhanced-version", - "version": "1.0.16", + "version": "1.0.18", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "psnine-enhanced-version", - "version": "1.0.16", + "version": "1.0.18", "license": "MIT", "devDependencies": { "eslint": "^7.32.0", diff --git a/package.json b/package.json index c17965a..bf5b6e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "psnine-enhanced-version", - "version": "1.0.16", + "version": "1.0.18", "description": "数折价格走势图,显示人民币价格,奖杯统计和筛选,发帖字数统计和即时预览,楼主高亮,自动翻页,屏蔽黑名单用户发言,被@用户的发言内容显示等多项功能优化P9体验", "main": "night-mode-css.js", "scripts": { diff --git a/psnineplus.js b/psnineplus.js index e8caa01..68243a1 100644 --- a/psnineplus.js +++ b/psnineplus.js @@ -1,7 +1,7 @@ // ==UserScript== // @name PSN中文网功能增强 // @namespace https://swsoyee.github.io -// @version 1.0.16 +// @version 1.0.18 // @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= @@ -2643,6 +2643,7 @@ const link = links[0]; if (!linkClickStatus) { link.click(); + $(link).parents('li')[0].querySelector('div.sonlistmark.ml64.mt10 > form.comson').style = 'display: none'; // console.log(`clicked subcomment link #${subcommentLinks.indexOf(link)}`); linkClickStatus = true; linkFails = 0;