diff --git a/psnineplus.js b/psnineplus.js index 8343421..1baa43d 100644 --- a/psnineplus.js +++ b/psnineplus.js @@ -397,7 +397,7 @@ $('body,html').animate({ scrollTop: document.body.clientHeight, }, - 500); + 500); }).css({ cursor: 'pointer', }); @@ -410,30 +410,29 @@ document.head.appendChild(nightModeStyle); } - /* - 1.游戏列表添加按难度排列按钮 + /* + 1.游戏列表添加按难度排列按钮 2.游戏列表根据已记录的完成度添加染色 3.TODO:游戏列表隐藏已经 100% 的游戏(需要添加用户可见的开关) */ const hdElement = document.querySelector('.hd'); if (hdElement && hdElement.textContent.trim() === '游戏列表') { - const tdElements = document.querySelectorAll('table.list tbody > tr'); // 添加完成度染色 - const platinumBackground = 'background-color: #d0f6ff;background-image: linear-gradient(90deg, #c7fffd 0%, #ffffff 60%);' - const goldBackground = 'background-color: #e5ffe7;background-image: linear-gradient(90deg, #daffde 0%, #ffffff 60%);' - const personalGameCompletions = GM_getValue('personalGameCompletions', []) + const platinumBackground = 'background-color: #d0f6ff;background-image: linear-gradient(90deg, #c7fffd 0%, #ffffff 60%);'; + const goldBackground = 'background-color: #e5ffe7;background-image: linear-gradient(90deg, #daffde 0%, #ffffff 60%);'; + const personalGameCompletions = GM_getValue('personalGameCompletions', []); // 根据已保存的完成度添加染色 tdElements.forEach((tr) => { const gameID = tr.getAttribute('id') || 0; - const thisGameCompletion = personalGameCompletions.find(item => item[0] == gameID); + const thisGameCompletion = personalGameCompletions.find((item) => item[0] === gameID); if (thisGameCompletion) { - if (thisGameCompletion[1] == 100 && thisGameCompletion[2] == true) { tr.setAttribute('style', platinumBackground); } - if (thisGameCompletion[1] == 100 && thisGameCompletion[2] == false) { tr.setAttribute('style', goldBackground); } + if (thisGameCompletion[1] === 100 && thisGameCompletion[2] === true) { tr.setAttribute('style', platinumBackground); } + if (thisGameCompletion[1] === 100 && thisGameCompletion[2] === false) { tr.setAttribute('style', goldBackground); } } - }) + }); // 创建新的 span 元素 const spanElement = document.createElement('span'); @@ -548,35 +547,34 @@ }`, ); - /* + /* 在 LocatStorage 中保存个人游戏完成度函数 添加于 /psnid\/[A-Za-z0-9_-]+\/?$/ 页面,以及该页自动翻页函数内部 */ const savePersonalGameCompletions = (configifneeded) => { - // if GM_setValue && GM_getValue is enabled - 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 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 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 history = GM_getValue('personalGameCompletions', []) + const history = GM_getValue('personalGameCompletions', []); // 用当前覆盖历史 personalGameCompletions.forEach((currentItem) => { - const index = history.findIndex(historyItem => historyItem[0] === currentItem[0]); + const index = history.findIndex((historyItem) => historyItem[0] === currentItem[0]); if (index !== -1) { history[index] = currentItem; } else { @@ -587,20 +585,18 @@ // 保存更新后的历史记录 GM_setValue('personalGameCompletions', history); // console.log(GM_getValue('personalGameCompletions')) - return true - } else { - return false + 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 ( /psnid\/[A-Za-z0-9_-]+\/?$/.test(window.location.href) && $('tbody').length > 2 @@ -635,7 +631,7 @@ gamePageIndex += 1; // 同步更新个人游戏完成度 - savePersonalGameCompletions() + savePersonalGameCompletions(); } else { $('#loadingMessage').text('没有更多游戏了...'); } @@ -962,7 +958,7 @@ .append(` 🔥热门 `); + };color: rgb(255, 255, 255);">🔥热门 `); } }); };