Skip to content

Instantly share code, notes, and snippets.

@neilwong2012
Created April 17, 2018 13:51
Show Gist options
  • Save neilwong2012/e1ab5d491d81807adb359a8a1d41f3f1 to your computer and use it in GitHub Desktop.
Save neilwong2012/e1ab5d491d81807adb359a8a1d41f3f1 to your computer and use it in GitHub Desktop.
steam 优化评分展示脚本
const hideEle = (item) => {
let parentNode = item.parentNode;
let maxLoop = 15;
while(parentNode.tagName !== 'A' && maxLoop > 0) {
parentNode = parentNode.parentNode;
maxLoop--;
}
item.dataset.isCheck = '1'
parentNode.style.display = 'none';
}
const checkFn = () => {
const minRealNum = 1000;
const items = document.querySelectorAll('.search_reviewscore');
items.forEach( item2 => {
if (item2.dataset.isCheck) {
return
}
const item = item2.querySelector('.search_review_summary')
if(!item) {
hideEle(item2);
return
}
const content = item.dataset.tooltipHtml
const contentArr = content.split('<br>')
if(contentArr.length !== 2) {
console.log(content);
return
}
const last = contentArr[1]
const lastArr = last.split(' ')
if(lastArr < 2) {
console.log(content);
return;
}
const num = lastArr[0].replace(',', '')
const rate = lastArr[2].replace('%', '')
const realNum = parseInt(num*rate/100)
if (isNaN(realNum)){
console.log(content);
return;
}
const innerHtml = `${num} x ${rate} = ${parseInt(num*rate/100)}`;
item.innerText = innerHtml;
item.style.width = '200px';
item.style.marginLeft = '-200px';
item.style.backgroundColor = '#000';
item.style.backgroundImage = 'none';
item.style.textAlign = 'left';
item.style.color = '#fff'
item2.dataset.isCheck = '1';
if(realNum < minRealNum) {
hideEle(item)
}
})
}
setInterval( ()=> {
checkFn()
},3000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment