Skip to content

Instantly share code, notes, and snippets.

@helloint
Last active May 3, 2025 02:20
Show Gist options
  • Save helloint/71fa54c4206337f06af18740fbd36bd9 to your computer and use it in GitHub Desktop.
Save helloint/71fa54c4206337f06af18740fbd36bd9 to your computer and use it in GitHub Desktop.
Calcuate papar score on zhixue.com
// ==UserScript==
// @name Calcuate papar score on zhixue.com
// @namespace https://helloint.com
// @version 0.3
// @description Calcuate papar score on zhixue.com
// @downloadURL https://gist.githubusercontent.com/helloint/71fa54c4206337f06af18740fbd36bd9/raw/zhixue-paper-score-calc.user.js
// @author Wayne Mao
// @match https://www.zhixue.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=web.app
// @grant none
// ==/UserScript==
(function() {
var timerId = null;
var displayDiv = null;
function init() {
// 同时监听两个事件(兼容所有浏览器)
window.addEventListener('hashchange', handleHashChange);
window.addEventListener('popstate', handleHashChange); // 处理前进/后退
handleHashChange(); // 初始检查
}
function handleHashChange() {
var shouldShow = window.location.hash.indexOf('original-roll-detail') !== -1;
shouldShow ? startMonitoring() : stopMonitoring();
}
function startMonitoring() {
createDisplayLayer();
if (timerId === null) {
timerId = setInterval(checkScores, 1000);
checkScores(); // 立即执行一次
}
}
function stopMonitoring() {
if (timerId !== null) {
clearInterval(timerId);
timerId = null;
}
hideDisplayLayer();
}
function createDisplayLayer() {
if (displayDiv) return;
displayDiv = document.createElement('div');
displayDiv.id = 'score-display';
displayDiv.style.cssText = 'position:fixed;top:10px;left:50%;transform:translateX(-50%);background:white;color:blue;padding:10px 20px;border:1px solid #ccc;border-radius:5px;z-index:9999;text-align:center';
displayDiv.textContent = '成绩读取中……';
document.body.appendChild(displayDiv);
}
function hideDisplayLayer() {
if (displayDiv) {
displayDiv.style.display = 'none';
}
}
function checkScores() {
var rollTmp = document.getElementById('rollTmp');
if (!rollTmp) {
if (displayDiv) displayDiv.textContent = '未找到成绩容器';
return;
}
var pickLists = rollTmp.getElementsByClassName('pick-list');
var totalDeduction = 0;
var hasScores = false;
for (var i = 0; i < pickLists.length; i++) {
var userScores = pickLists[i].getElementsByClassName('user-score');
for (var j = 0; j < userScores.length; j++) {
var score = parseFloat(userScores[j].textContent.trim());
if (!isNaN(score)) {
totalDeduction += score;
hasScores = true;
}
}
}
if (displayDiv) {
displayDiv.style.display = 'block';
displayDiv.textContent = hasScores ? '总失分:' + totalDeduction : '成绩读取中……';
}
}
init();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment