// ==UserScript== // @name NGA Fast View Post Fix // @name:zh-CN NGA “快速浏览这个帖子” 修复 // @description 修复论坛“快速浏览这个帖子”功能,并可在“快速浏览这个帖子”时点赞,以及点赞后更新实时点赞数 // @namespace https://greasyfork.org/users/263018 // @version 1.1.1 // @author snyssss // @license MIT // @match *://bbs.nga.cn/* // @match *://ngabbs.com/* // @match *://nga.178.com/* // @require https://update.greasyfork.icu/scripts/486070/1378387/NGA%20Library.js // @grant GM_setValue // @grant GM_getValue // @grant GM_registerMenuCommand // @noframes // @downloadURL https://update.greasyfork.icu/scripts/482017/NGA%20Fast%20View%20Post%20Fix.user.js // @updateURL https://update.greasyfork.icu/scripts/482017/NGA%20Fast%20View%20Post%20Fix.meta.js // ==/UserScript== ((ui, ubbcode) => { if (!ui) return; if (!ubbcode) return; // KEY const USER_AGENT_KEY = "USER_AGENT"; const IS_SHOW_SCORE_KEY = "IS_SHOW_SCORE"; const IS_SHOW_SCORE_RESULT_KEY = "IS_SHOW_SCORE_RESULT_KEY"; // User Agent const USER_AGENT = (() => { const data = GM_getValue(USER_AGENT_KEY) || "Nga_Official"; GM_registerMenuCommand(`修改UA:${data}`, () => { const value = prompt("修改UA", data); if (value) { GM_setValue(USER_AGENT_KEY, value); location.reload(); } }); return data; })(); // 是否显示评分 const showScore = (() => { const data = GM_getValue(IS_SHOW_SCORE_KEY) || false; GM_registerMenuCommand(`显示评分:${data ? "是" : "否"}`, () => { GM_setValue(IS_SHOW_SCORE_KEY, !data); location.reload(); }); return data; })(); // 是否显示评分结果 const showScoreResult = (() => { const data = GM_getValue(IS_SHOW_SCORE_RESULT_KEY) || false; GM_registerMenuCommand(`显示评分结果:${data ? "是" : "否"}`, () => { GM_setValue(IS_SHOW_SCORE_RESULT_KEY, !data); location.reload(); }); return data; })(); // 简单的统一请求 const request = (url, config = {}) => fetch(url, { headers: { "X-User-Agent": USER_AGENT, }, ...config, }); // 获取帖子信息 const getPostInfo = async (tid, pid) => { const url = `/read.php?tid=${tid}&pid=${pid}`; const data = await new Promise((resolve) => request(url) .then((res) => res.blob()) .then((res) => { // 读取内容 const reader = new FileReader(); reader.onload = () => { const parser = new DOMParser(); const doc = parser.parseFromString(reader.result, "text/html"); // 验证帖子正常 const verify = doc.querySelector("#m_posts"); if (verify === null) { throw new Error(); } // 取得顶楼 UID const uid = (() => { const ele = doc.querySelector("#postauthor0"); if (ele) { const res = ele.getAttribute("href").match(/uid=((-?)(\S+))/); if (res) { return res[1]; } } return 0; })(); // 取得顶楼标题 const subject = doc.querySelector("#postsubject0").innerHTML; // 取得顶楼内容 const content = doc.querySelector("#postcontent0").innerHTML; // 取得用户信息 const user = (() => { const text = Tools.searchPair(reader.result, `"${uid}":`); if (text) { try { return JSON.parse(text); } catch { return null; } } return null; })(); // 取得额外信息 const extra = (() => { const content = reader.result.substring( reader.result.indexOf(`commonui.postArg.proc( 0,`) ); const text = Tools.searchPair( content, `commonui.postArg.proc`, `(`, `)` ); if (text) { return text; } return null; })(); // 返回结果 resolve({ subject, content, user, extra, }); }; reader.readAsText(res, "GBK"); }) .catch(() => { resolve(null); }) ); return data; }; // 快速浏览 const fastViewPost = (() => { const window = ui.createCommmonWindow(); const container = document.createElement("DIV"); container.className = `fastViewPost`; container.innerHTML = `