webofscience分区和JIC指数
// ==UserScript==
// @name webofscience分区和JIC指数
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.1.0
// @description try to take over the world!
// @author tfsn20
// @match https://webofscience.clarivate.cn/wos/woscc/summary/*
// @grant GM_getValue
// ==/UserScript==
/* ==UserConfig==
JCI标准:
Q1最大值:
title: Q1最大值
description: 大于该值时,Q1分区会显示深色
type: number
default: 1.5
Q1最小值:
title: Q1最小值
description: 大于该值时但小于Q1最大值时,Q1分区会显示浅色
type: number
default: 1
Q2最大值:
title: Q2最大值
description: 大于该值时,Q2分区会显示深色
type: number
default: 1.2
Q2最小值:
title: Q2最小值
description: 大于该值时但小于Q2最大值时,Q2分区会显示浅色
type: number
default: 1
分区颜色:
Q1分区颜色:
title: Q1分区颜色
description: 格式为r,g,b, 如104, 23, 255
type: textarea
default: 104, 23, 255
Q2分区颜色:
title: Q2分区颜色
description: 格式为r,g,b, 如26, 198, 4
type: textarea
default: 26, 198, 4
light:
title: 每个分区比较浅颜色的透明度,
description: 值越小约颜色越浅
type: number
default: 0.08
weight:
title: 每个分区比较深颜色的透明度,
description: 值越大约颜色越深
type: number
default: 0.8
==/UserConfig== */
const Q1Q2 = {
Q1: {
max: GM_getValue('JCI标准.Q1最大值')==undefined?1.5:GM_getValue('JCI标准.Q1最大值'),
min: GM_getValue('JCI标准.Q1最小值')==undefined?1:GM_getValue('JCI标准.Q1最小值'),
color:GM_getValue('分区颜色.Q1分区颜色')==undefined?'104, 23, 255':GM_getValue('分区颜色.Q1分区颜色')
},
Q2: {
max: GM_getValue('JCI标准.Q2最大值')==undefined?1.2:GM_getValue('JCI标准.Q2最大值'),
min: GM_getValue('JCI标准.Q2最小值')==undefined?1:GM_getValue('JCI标准.Q2最小值'),
color:GM_getValue('分区颜色.Q2分区颜色')==undefined?'26, 198, 4':GM_getValue('分区颜色.Q2分区颜色')
}
}
const light = GM_getValue('分区颜色.light')==undefined?0.08:GM_getValue('分区颜色.light'), weight = GM_getValue('分区颜色.weight')==undefined?0.8:GM_getValue('分区颜色.weight');
const backColor_light = [`(255,255,255,${light})`, `(${Q1Q2.Q1.color},${light})`, `(${Q1Q2.Q2.color},${light})`, `(255,255,255,${light})`, `(255,255,255,${light})`];
const backColor = [`(255,255,255,${weight})`, `(${Q1Q2.Q1.color},${weight})`, `(${Q1Q2.Q2.color},${weight})`, `(255,255,255,${weight})`, `(255,255,255,${weight})`];
const fontColor = '(0,0,0,1)';
console.log((backColor));
const tools = {
sleep: t => new Promise(res => setTimeout(res, t)),// 箭头函数体只有一句,可以省略return
net: {
change: (str, withCookie) => {
str = str.trim(); //去除文本首位\s
let method = str.match(/(.*?)\s/)[1];
let url = str.match(/\s(.*?)\s/)[1];
str = str.replace(/.*?\n/, ''); //去除第一行
let data = /\n\s*\n\s*(.*)$/m.test(str) ? str.slice(str.match(/\n\s*\n\s*(.*)$/m).index).trim() : ''; //获取请求体,没有则返回'', 用slice截取防止请求体含有\n时出错
str = str.replace(new RegExp(data), '').trim(); //去除data
str = str.replace(/^(\s*?)(\S.*)/gm, `$2`); //去除每行行首的\s
str = str.replace(/\sContent-Length:.*/im, ''); //去除Content-Length所在行,不用/^\sContent-Length:./im, 这样做会多一个空白行避免一些问题
str = withCookie ? str : str.replace(/\s*cookie:.*/im, '') //去除cookie所在行,不用/^\s*cookie.*/im, 这样做会多一个空白行
let headers = {}, h = str.match(/(\S*?):\s*(\S.*)/mg);
// GM_log(h)
h.forEach(e => {
let t = e.match(/(\S*?):\s*(.*)/);
headers[t[1]] = t[2].replace(/\s*$/, '');//去除行尾\s,避免一下总没错吧
});
//去除浏览器默认携带的请求头
if (!/origin:/i.test(str)) headers.origin = '';//脚本猫默认有一个拓展origin,这里去掉
if (!/dnt/i.test(str)) headers.dnt = '';
if (!/referer/i.test(str)) headers.referer = '';
//if (!/accept/i.test(str)) headers.accept='';
if (!/user-agent/i.test(str)) headers['user-agent'] = '';
if (!/sec-ch-ua/i.test(str)) headers['sec-ch-ua'] = '';
if (!/sec-ch-ua-mobile/i.test(str)) headers['sec-ch-ua-mobile'] = '';
if (!/sec-ch-ua-platform/i.test(str)) headers['sec-ch-ua-platform'] = '';
if (!/sec-fetch-dest/i.test(str)) headers['sec-fetch-dest'] = '';
if (!/sec-fetch-mode/i.test(str)) headers['sec-fetch-mode'] = '';
if (!/sec-fetch-site/i.test(str)) headers['sec-fetch-site'] = '';
//if (!/accept-language/i.test(str)) headers['accept-language']='';
if (!/accept-encoding/i.test(str)) headers['accept-encoding'] = '';
return { url, method, data, headers }
},
}
};
function scrollToBottomThenTop() {
// A function to scroll to the bottom of the page
function scrollToBottom() {
// Get the total height of the page
const totalHeight = document.documentElement.scrollHeight;
// Get the current scroll position
const currentPosition = window.pageYOffset;
// If current position is already at the bottom, stop the function execution
if (currentPosition + window.innerHeight >= totalHeight) {
// Since we've reached the bottom, we start the scroll to top action
scrollToTop();
return;
}
// Calculate the next scroll position
const nextPosition = currentPosition + window.innerHeight;
// Scroll to the next position
window.scrollTo(0, nextPosition);
// Continue scrolling after a certain delay
setTimeout(scrollToBottom, 100);
}
// A function to scroll to the top of the page
function scrollToTop() {
// If current position is at the top, stop the function execution
if (window.pageYOffset === 0) {
return;
}
// Scroll to a position 100px above the current position every 100ms
const currentPosition = window.pageYOffset;
const nextPosition = Math.max(currentPosition - 800, 0);
// Scroll to the next position
window.scrollTo(0, nextPosition);
// Continue scrolling after a certain delay
setTimeout(scrollToTop, 50);
}
// Start the scrolling process
scrollToBottom();
}
(async () => {
await tools.sleep(3000);
scrollToBottomThenTop();
await tools.sleep(3000);
const blocks = document.querySelectorAll("app-record");
blocks.forEach((e) => {
e['hasInfo'] = Array.from(e.querySelector('div > div > div.data-section > div:nth-child(1) > div.jcr-and-pub-info-section').querySelectorAll('*')).some(node => node.tagName === 'A');
if (e['hasInfo']) {
e['Q'] = (() => {
const text = Array.from(e.getElementsByClassName('min ng-star-inserted')).map(element => element.innerText)
// 初始化一个变量来存储最大的数字
var maxNumber = 0;
// 遍历数组中的每个元素
text.forEach(function (element) {
// 提取字符串中的数字部分,并转换为数字类型
var number = parseInt(element.substring(1));
// 如果提取的数字大于当前的最大数字,则更新最大数字
if (number > maxNumber) {
maxNumber = number;
}
});
return maxNumber
})();
e['JCI'] = (() => {
const text = e.querySelectorAll('div.jif-holder')[1].innerText;
const year = text.substring(0, 4);
const regexp = new RegExp(`(${year})(.*?)(${year - 1})(.*)`)
const jci = text.match(regexp).slice(1);
return [parseFloat(jci[1]) > parseFloat(jci[3]) ? '增加' : '减少', jci[1]];
})();
if (e['Q'] == 1) {
if (e['JCI'][1] >= Q1Q2.Q1.max) {
e.querySelector("div.number-section.font-size-18.ng-star-inserted").style.cssText = `background-color: rgba${backColor[e['Q']]}; color: rgba${fontColor}; z-index: 9999;`;
} else if (e['JCI'][1] >= Q1Q2.Q1.min) {
e.querySelector("div.number-section.font-size-18.ng-star-inserted").style.cssText = `background-color: rgba${backColor_light[e['Q']]}; color: rgba${fontColor}; z-index: 9999;`;
}
}else if(e['Q'] == 2){
if (e['JCI'][1] >= Q1Q2.Q2.max) {
e.querySelector("div.number-section.font-size-18.ng-star-inserted").style.cssText = `background-color: rgba${backColor[e['Q']]}; color: rgba${fontColor}; z-index: 9999;`;
} else if (e['JCI'][1] >= Q1Q2.Q2.min) {
e.querySelector("div.number-section.font-size-18.ng-star-inserted").style.cssText = `background-color: rgba${backColor_light[e['Q']]}; color: rgba${fontColor}; z-index: 9999;`;
}
};
e.querySelector("div.number-section.font-size-18.ng-star-inserted").appendChild(document.createTextNode(e['JCI'][1]));
e.querySelector("div.number-section.font-size-18.ng-star-inserted").appendChild(document.createTextNode(e['JCI'][0] == '增加' ? '↑' : '↓'));
}
});
})();