油猴脚本:实现吾爱破解论坛评分可视化
本帖最后由 lccccccc 于 2024-2-24 08:39 编辑上一篇传送门:<https://www.52pojie.cn/thread-1891841-1-1.html>
有人说可以使用油猴脚本实现,好的,现在安排一个
抱歉,今天(2023/2/23)下午4点的时候发的代码有点问题,请替换为下面给出的代码的这个代码;现在的代码已经修改好了,没有问题了。为您带来了困扰,实在抱歉
这是修改好的代码:
// ==UserScript==
// @name 52_评分可视化
// @version 2024-02-19
// @description吾爱破解论坛评分可视化By: lccccccc @52pojie.cn
// @author lccccccc @52pojie.cn
// @match http*://www.52pojie.cn*
// @icon https://down.52pojie.cn/Logo/%E5%90%BE%E7%88%B1%E7%A0%B4%E8%A7%A3.ico
// @grant none
// ==/UserScript==
var CSS_TEXT = `
div._52view-background_div{
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
z-index: 300;
background-color: #00000050;
}
div._52view-background_div>div.tipsBoxWait{
position: relative;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
/*padding: 5px;*/
background-color: #fff;
border: 3px #0ff solid;
width: 80%;
max-height: 80%;
overflow: auto;
}
table._52view_table {
/*table-layout: fixed;*/
overflow: auto;
height: 100%; /* 设置固定高度 */
width: 100%;
}
table._52view_table>thead tr th {
position:sticky;
top:0;
}
table._52view_table>*>tr>td{
border: 1px #000 solid;
padding: 5px 2px;
text-align: center;
}
table._52view_table>thead>tr {
position: sticky;
top: 0; /* 首行永远固定在头部*/
background-color: #eaf4ff; /*设置表头背景色*/
}
p._52view_close {
z-index: 302;
position: absolute;
top: 5px;
right: 5px;
}
`;
function _52view_cancel(del_eve = 0) {
try{
document.getElementById("_52view_background_div").remove();
if(del_eve==1){
document.removeEventListener('keydown', KeyEvent);
}
} catch {}
}
function KeyEvent(e) {
if (e.keyCode == 27) {
_52view_cancel(1);
}
}
function isMouseInsideElement(event, element) {
try{
var rect = element.getBoundingClientRect();
return (
event.clientX >= rect.left &&
event.clientX <= rect.right &&
event.clientY >= rect.top &&
event.clientY <= rect.bottom
);
} catch {}
}
function _52view_(link) {
var background_div = document.createElement('div');
background_div.id = "_52view_background_div";
background_div.classList.add("_52view-background_div");
var tipsBoxWait = document.createElement('div');
tipsBoxWait.innerHTML = "<p><img src=\"https://static.52pojie.cn/static/image/common/loading.gif\" class=\"vm\" style=\"margin: 5px;\">请稍后 <span style=\"color: #f00;\">[<a href=\"javascript:;\" style=\"text-align: right; color: #f00;\" id=\"_52view_cancel\">取消</a>]</sapn></p>";
tipsBoxWait.classList.add("tipsBoxWait");
background_div.appendChild(tipsBoxWait);
document.body.appendChild(background_div);
document.getElementById('_52view_cancel').addEventListener('click', () => { _52view_cancel() });
var xhr = new XMLHttpRequest();
xhr.open('GET', link + '&infloat=yes&handlekey=viewratings&inajax=1&ajaxtarget=fwin_content_viewratings');
xhr.onload = function() {
if (xhr.status === 200) {
var parser0 = new DOMParser();
var doc0 = parser0.parseFromString(xhr.responseText, 'text/html');
var elements = doc0.getElementsByTagName('root');
// 按理来说只有一个root
var elementValue = elements.innerHTML;
var parser = new DOMParser();
var doc = parser.parseFromString(elementValue, 'text/html');
var tr = doc.querySelectorAll('table>tbody>tr');
var scores = {};
var items = new Set();
var users = new Set();
for (var i = 0; i < tr.length; i++) {
var td = tr.querySelectorAll('td');
var uname = td.querySelectorAll('a').textContent;
items.add(td.textContent.split(/[-+]/).trim())
users.add(uname);
if (!scores) {
scores = [.textContent],
td.querySelectorAll('a').href,
td.textContent,
td.textContent]
} else {
scores.push(td.textContent);
}
}
items = [...items];
users = [...users];
var table = document.createElement('table'), thead, tbody, theadTr, thead2;
table.style.cssText = "border: 1px #000 solid;";
table.classList.add('_52view_table');
table.appendChild(thead = document.createElement('thead'));
table.appendChild(tbody = document.createElement('tbody'));
thead.appendChild(theadTr = document.createElement('tr'));
var createChild = (tag, text) => {
var ele = document.createElement(tag);
ele.innerText = text;
return ele;
}
var createChildHTML = (tag, html) => {
var ele = document.createElement(tag);
ele.innerHTML = html;
return ele;
}
theadTr.appendChild(createChild('td', `用户 (${users.length})`));
var theadTr_Items_Nums = [], Sums = [];
for (var x = 0; x < items.length; x++) {
theadTr_Items_Nums.push(0);
}
for (var x2 = 0; x2 < users.length; x2++) {
Sums.push(0);
}
for (var i0 = 0; i0 < users.length; i0++) {
var tr0 = document.createElement('tr');
tr0.appendChild(createChildHTML('td', `<a href="${scores]}">${users}</a>`));
for (var j = 0; j < items.length; j++) {
var flag = false;
for (var k = 0; k < scores].length; k++) {
if (scores].match(items)) {
var score = scores].replace(items, '').trim().split(' ').trim();
theadTr_Items_Nums += parseInt(score);
tr0.appendChild(createChildHTML('td', `<p style="color: ${score > 0 ? '#f00' : '#888'}">${score}</p>`));
flag = true;
break;
}
}
if (!flag) {
tr0.appendChild(createChild('td', ''));
}
}
tr0.appendChild(createChild('td', scores]));
tr0.appendChild(createChild('td', scores]));
tbody.appendChild(tr0);
scores];
}
for (var z = 0; z < items.length; z++) {
theadTr.appendChild(createChildHTML('td', `${items} <span style="color: ${theadTr_Items_Nums > 0 ? '#f00' : '#888'};">${theadTr_Items_Nums > 0 ? '+' : ''}${theadTr_Items_Nums}</span>`));
}
theadTr.appendChild(createChild('td', '理由'));
var lastTdInTheadTr = createChild('td', '时间');
theadTr.appendChild(lastTdInTheadTr);
document.querySelectorAll("div._52view-background_div>div.tipsBoxWait>p").remove()
var cancel = document.createElement('a');
cancel.innerText = '';
cancel.href = 'javascript:;';
cancel.title = "关闭对话框";
cancel.style.cssText = "position: absolute; right: 5px; color: #f00;";
cancel.addEventListener('click', () => { _52view_cancel() });
lastTdInTheadTr.appendChild(cancel);
document.querySelectorAll("div._52view-background_div>div.tipsBoxWait").appendChild(table);
document.addEventListener('keydown', KeyEvent);
document.querySelectorAll("div._52view-background_div").addEventListener("click", (e) => {
if (!isMouseInsideElement(e, document.querySelectorAll("div._52view-background_div>div.tipsBoxWait"))) {
_52view_cancel();
}
});
}
else {
alert('油猴脚本 52_评分可视化: 出错了 (请求错误)');
}
}
xhr.onerror = function() {
background_div.remove();
alert('油猴脚本 52_评分可视化: 出错了 (处理错误 或 网络异常)');
}
xhr.send();
}
(function () {
'use strict';
var pageUrl = window.location.href;
if (pageUrl.match('52pojie.cn') != null) {
var style = document.createElement('style');
style.innerText = CSS_TEXT;
document.head.appendChild(style);
var all = document.querySelectorAll('p.ratc');
for (var i = 0; i < all.length; i++) {
const link = all.querySelectorAll('a').href;
var new_a = document.createElement('a');
new_a.href = 'javascript:;';
new_a.innerText = '可视化所有评分';
new_a.classList.add('xi2');
new_a.addEventListener('click', () => {
_52view_(link);
})
all.appendChild(new_a);
}
}
})();
这次更新还把一些建议加上了:
1. Esc关闭对话框
2. 点击对话框以外的空白区域关闭对话框
我找了个论坛的帖子测试了一下,没问题,一切正常:
好了,就是这些了。这些源代码仅供学习和交流,请勿他用。
应该是我的油猴版本问题,match网址匹配不了,稍微改了一下能匹配,且运行正常。// @match https://www.52pojie.cn/thread* lccccccc 发表于 2024-2-24 08:42
现在的代码应该没问题了。
(为什么刚才代码里有 [ u r l ] 符号!现在我改过来了。看来是论坛编辑器的 b ...
昨天的代码没问题呢,运行正常,今天的更新了也正常。
就是我用的win11+firefox 123.0 (64 位) + 篡改猴5.0.1版本,不能匹配http*://www.52pojie.cn*,打开贴子时 没有已启用的脚本,稍微改了下匹配网址就可以了。 爬虫,计算,绘图 厉害了我的哥,感谢分享,赞 感谢分享{:1_919:} 这就很直观了,学习学习。 这就很直观了,学习学习。 学习了,谢谢分享。 可以试试效果 用油猴这个确实方便多了 油猴支持ES6+语法吗?