Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikaiiiiiii committed Jun 29, 2024
1 parent 23d5e47 commit f1c6082
Showing 1 changed file with 28 additions and 32 deletions.
60 changes: 28 additions & 32 deletions psnineplus.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@
$('body,html').animate({
scrollTop: document.body.clientHeight,
},
500);
500);
}).css({
cursor: 'pointer',
});
Expand All @@ -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', []);

Check failure on line 425 in psnineplus.js

View workflow job for this annotation

GitHub Actions / eslint

'GM_getValue' is not defined

// 根据已保存的完成度添加染色
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');
Expand Down Expand Up @@ -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');

Check failure on line 557 in psnineplus.js

View workflow job for this annotation

GitHub Actions / eslint

Identifier 'GM_setValue' is not in camel case

Check failure on line 557 in psnineplus.js

View workflow job for this annotation

GitHub Actions / eslint

Identifier 'GM_getValue' is not in camel case

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', []);

Check failure on line 573 in psnineplus.js

View workflow job for this annotation

GitHub Actions / eslint

'GM_getValue' is not defined

// 用当前覆盖历史
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 {
Expand All @@ -587,20 +585,18 @@
// 保存更新后的历史记录
GM_setValue('personalGameCompletions', history);

Check failure on line 586 in psnineplus.js

View workflow job for this annotation

GitHub Actions / eslint

'GM_setValue' is not defined
// 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
Expand Down Expand Up @@ -635,7 +631,7 @@
gamePageIndex += 1;

// 同步更新个人游戏完成度
savePersonalGameCompletions()
savePersonalGameCompletions();
} else {
$('#loadingMessage').text('没有更多游戏了...');
}
Expand Down Expand Up @@ -962,7 +958,7 @@
.append(`&nbsp;<a class="psnnode" id="hot" style="background-color: ${tagBackgroundColor === 'rgb(43, 43, 43)'
? 'rgb(125 69 67)' // 暗红色
: 'rgb(217, 83, 79)' // 鲜红色
};color: rgb(255, 255, 255);">🔥热门&nbsp;</a>`);
};color: rgb(255, 255, 255);">🔥热门&nbsp;</a>`);
}
});
};
Expand Down

0 comments on commit f1c6082

Please sign in to comment.