// ==UserScript== // @name 睢宁OJ题目正确率统计 // @namespace https://scriptcat.org/ // @version 2.1 // @description 在Contest题目表格后添加正确率列,按规则显示颜色和文字(全加粗),优化列宽避免换行 // @author sulang // @match *://www.jkcxsn.cn/contest.php?cid=* // @grant none // @run-at document-end // ==/UserScript== (function() { 'use strict'; // 找到目标表格 const table = document.querySelector('.ui.selectable.celled.table'); if (!table) return; const thead = table.querySelector('thead tr'); const tbody = table.querySelector('tbody'); // 1. 在表头添加"正确率"列(设置基础宽度和不换行样式) const th = document.createElement('th'); th.className = 'center aligned'; th.textContent = '正确率'; // 设置表头样式:不换行 + 最小宽度 + 自动适配 th.style = ` white-space: nowrap; min-width: 150px; width: auto; padding: 0.92857143em 1em; text-align: center; `; thead.appendChild(th); // 定义正确率样式和文本规则(全加粗) const getRateConfig = (correct, submit) => { let text = ''; let color = ''; if (submit === 0) { // 无人提交 text = '0% [咋没人做呢]'; color = '#000000'; // 黑色 } else if (correct === 0) { // 有人提交但无人正确 text = '0% [无人能及]'; color = '#b71c1c'; // 红色加深 } else { // 计算正确率并按区间分类 const rateValue = (correct / submit) * 100; text = rateValue.toFixed(2) + '%'; if (rateValue >= 80) { color = '#21ba45'; // 绿色 } else if (rateValue >= 60) { color = '#fbbd08'; // 黄色 } else if (rateValue >= 40) { color = '#f2711c'; // 橙色 } else { color = '#db2828'; // 红色 } } return { text: text, style: ` color: ${color}; font-weight: bold; white-space: nowrap; /* 强制不换行 */ text-align: center; padding: 0.92857143em 1em; ` }; }; // 2. 遍历每一行,计算并添加正确率 const rows = tbody.querySelectorAll('tr'); rows.forEach(row => { const cells = row.querySelectorAll('td'); if (cells.length < 5) return; // 确保有"正确"和"提交量"列 // 获取正确数和提交量(转数字,处理空值) const correct = parseInt(cells[3].textContent.trim()) || 0; const submit = parseInt(cells[4].textContent.trim()) || 0; // 获取样式和文本配置 const rateConfig = getRateConfig(correct, submit); // 创建正确率单元格 const td = document.createElement('td'); td.textContent = rateConfig.text; td.style = rateConfig.style; // 应用颜色+加粗+不换行样式 row.appendChild(td); }); // 3. 优化整个表格的布局,避免列宽挤压 table.style.tableLayout = 'auto'; table.style.width = '100%'; })();