// ==UserScript== // @name Patch for the unrobust data processing code in the comment section of the CCW extension details page // @namespace Violentmonkey Scripts // @match https://assets.ccw.site/extension/* // @grant none // @version 1.2 // @license AGPL-3.0 // @author xiaochen004hao // @icon https://m.ccw.site/community/images/logo-ccw.png // @require https://code.jquery.com/jquery-3.6.0.min.js // @run-at document-start // @description 2026/5/22 // ==/UserScript== "use strict"; (() => { const TARGET_PATH = '/comment/page_by_topic'; const SPECIAL_SCORE = '-247111583'; function patchData(json) { if (json && json.body && Array.isArray(json.body.data)) { json.body.data.forEach(item => { if (item && typeof item.content === 'string') { if (!item.content.includes('-评分:')) { item.content = `-评分: ${SPECIAL_SCORE}\n${item.content}`; } } }); } return json; } const rawOpen = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function (method, url) { this._url = url; return rawOpen.apply(this, arguments); }; const rawSend = XMLHttpRequest.prototype.send; XMLHttpRequest.prototype.send = function () { if (this._url && this._url.includes(TARGET_PATH)) { this.addEventListener('readystatechange', function () { if (this.readyState === 4 && this.status === 200) { try { const json = JSON.parse(this.responseText); const patchedJson = patchData(json); const patchedText = JSON.stringify(patchedJson); Object.defineProperty(this, 'responseText', { value: patchedText, writable: true }); Object.defineProperty(this, 'response', { value: this.responseType === 'json' ? patchedJson : patchedText, writable: true }); } catch (err) { } } }); } return rawSend.apply(this, arguments); }; function patchDOM() { $('.c-rating-text').each(function () { const $this = $(this); if ($this.text().trim() === `${SPECIAL_SCORE}.0` && !$this.data('patched')) { $this.data('patched', true); $this.text('此用户尝试使页面报错,已拦截'); $this.css({ 'color': '#ff4d4f', 'font-weight': 'bold' }); const $stars = $this.prevAll('div').filter(function () { return $(this).css('width') === '17px' || $(this).find('svg').length > 0; }); if ($stars.length > 0) { const $keepStar = $stars.eq(0); $stars.slice(1).remove(); const warningSVG = ` { const observer = new MutationObserver(patchDOM); observer.observe(document.body, { childList: true, subtree: true }); }); })();