当前页!当前页!当前页!只处理当前页信息。建议打开每页20条记录
当前为
// ==UserScript==
// @name 谷歌学术在当前页按照被引用次数排序
// @namespace http://tampermonkey.net/
// @version 2025.02.12.005
// @description 当前页!当前页!当前页!只处理当前页信息。建议打开每页20条记录
// @author You
// @match https://scholar.google.com/scholar?*
// @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant none
// @license MIT
// ==/UserScript==
(function () {
'use strict';
// Your code here...
/**
* 从节点中提取引用次数和 rimf 值,并计算综合得分
* @param {HTMLElement} node - 要处理的节点
* @returns {number} 综合得分
*/
function getCiteCount(node) {
const citeText = node.querySelector('a[href*="cites"]')?.textContent || "0";
const citeInt = parseInt(citeText.match(/(\d+)/)?.[1], 10) || 0;
const rimf = parseInt(node.querySelector('.rimf')?.getAttribute("val"), 10) || 0;
return citeInt * 1000 + rimf;
}
let sortCount = 0
/**
* 对元素进行排序
*/
function sortElements() {
const gsResCclMid = document.getElementById('gs_res_ccl_mid');
if (!gsResCclMid) {
console.error('未找到 gs_res_ccl_mid 元素');
return;
}
const gsOrElements = [...gsResCclMid.querySelectorAll('.gs_or')]
.map(node => ({ node, citeCount: getCiteCount(node) }));
const gsOrElementsSorted = [...gsOrElements].sort((a, b) => b.citeCount - a.citeCount);
// 检查是否需要重新排序
const needResort = gsOrElements.some((element, index) => element.node !== gsOrElementsSorted[index].node);
if (needResort) {
console.log("重排", ++sortCount)
gsResCclMid.innerHTML = '';
gsResCclMid.append(...gsOrElementsSorted.map(item => item.node)); // 重新添加排序后的节点
setTimeout(sortElements, 1000);
} else {
setTimeout(sortElements, 5000);
}
}
sortElements();
})();