NGA Filter

troll must die

目前為 2022-11-01 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name NGA Filter
  3. // @namespace https://greasyfork.org/users/263018
  4. // @version 1.9.2
  5. // @author snyssss
  6. // @description troll must die
  7. // @license MIT
  8.  
  9. // @match *://bbs.nga.cn/*
  10. // @match *://ngabbs.com/*
  11. // @match *://nga.178.com/*
  12.  
  13. // @grant GM_addStyle
  14. // @grant GM_setValue
  15. // @grant GM_getValue
  16. // @grant GM_registerMenuCommand
  17.  
  18. // @noframes
  19. // ==/UserScript==
  20.  
  21. ((n, self) => {
  22. if (n === undefined) return;
  23.  
  24. // KEY
  25. const DATA_KEY = "NGAFilter";
  26. const USER_AGENT_KEY = "USER_AGENT_KEY";
  27.  
  28. // User Agent
  29. const USER_AGENT = (() => {
  30. const data = GM_getValue(USER_AGENT_KEY) || "Nga_Official";
  31.  
  32. GM_registerMenuCommand(`修改UA${data}`, () => {
  33. const value = prompt("修改UA", data);
  34.  
  35. if (value) {
  36. GM_setValue(USER_AGENT_KEY, value);
  37.  
  38. location.reload();
  39. }
  40. });
  41.  
  42. return data;
  43. })();
  44.  
  45. // 简单的统一请求
  46. const request = (url, config = {}) => fetch(url, {
  47. headers: {
  48. "X-User-Agent": USER_AGENT,
  49. },
  50. ...config,
  51. });
  52.  
  53. // 过滤提示
  54. const FILTER_TIPS =
  55. "过滤顺序:用户 &gt; 标记 &gt; 关键字 &gt; 属地<br/>过滤级别:隐藏 &gt; 遮罩 &gt; 标记 &gt; 继承 &gt; 显示<br/>相同类型按最高级别过滤";
  56.  
  57. // 过滤方式
  58. const FILTER_MODE = ["继承", "标记", "遮罩", "隐藏", "显示"];
  59.  
  60. // 切换过滤方式
  61. const switchFilterMode = (value) => {
  62. const next = FILTER_MODE.indexOf(value) + 1;
  63.  
  64. if (next >= FILTER_MODE.length) {
  65. return FILTER_MODE[0];
  66. }
  67.  
  68. return FILTER_MODE[next];
  69. };
  70.  
  71. // 数据
  72. const data = (() => {
  73. const d = {
  74. tags: {},
  75. users: {},
  76. keywords: {},
  77. locations: {},
  78. options: {
  79. filterRegdateLimit: 0,
  80. filterPostnumLimit: 0,
  81. filterReputationLimit: NaN,
  82. filterMode: "隐藏",
  83. },
  84. };
  85.  
  86. const v = GM_getValue(DATA_KEY);
  87.  
  88. if (typeof v !== "object") {
  89. return d;
  90. }
  91.  
  92. return Object.assign(d, v);
  93. })();
  94.  
  95. // 保存数据
  96. const saveData = () => {
  97. GM_setValue(DATA_KEY, data);
  98. };
  99.  
  100. // 增加标记
  101. const addTag = (name) => {
  102. const tag = Object.values(data.tags).find((item) => item.name === name);
  103.  
  104. if (tag) return tag.id;
  105.  
  106. const id =
  107. Math.max(...Object.values(data.tags).map((item) => item.id), 0) + 1;
  108.  
  109. const hash = (() => {
  110. let h = 5381;
  111. for (var i = 0; i < name.length; i++) {
  112. h = ((h << 5) + h + name.charCodeAt(i)) & 0xffffffff;
  113. }
  114. return h;
  115. })();
  116.  
  117. const hex = Math.abs(hash).toString(16) + "000000";
  118.  
  119. const hsv = [
  120. `0x${hex.substring(2, 4)}` / 255,
  121. `0x${hex.substring(2, 4)}` / 255 / 2 + 0.25,
  122. `0x${hex.substring(4, 6)}` / 255 / 2 + 0.25,
  123. ];
  124.  
  125. const rgb = n.hsvToRgb(hsv[0], hsv[1], hsv[2]);
  126.  
  127. const color = ["#", ...rgb].reduce((a, b) => {
  128. return a + ("0" + b.toString(16)).slice(-2);
  129. });
  130.  
  131. data.tags[id] = {
  132. id,
  133. name,
  134. color,
  135. filterMode: FILTER_MODE[0],
  136. };
  137.  
  138. saveData();
  139.  
  140. return id;
  141. };
  142.  
  143. // 增加用户
  144. const addUser = (id, name = null, tags = [], filterMode = FILTER_MODE[0]) => {
  145. if (data.users[id]) return data.users[id];
  146.  
  147. data.users[id] = {
  148. id,
  149. name,
  150. tags,
  151. filterMode,
  152. };
  153.  
  154. saveData();
  155.  
  156. return data.users[id];
  157. };
  158.  
  159. // 增加关键字
  160. const addKeyword = (
  161. keyword,
  162. filterMode = FILTER_MODE[0],
  163. filterLevel = 0
  164. ) => {
  165. const id =
  166. Math.max(...Object.values(data.keywords).map((item) => item.id), 0) + 1;
  167.  
  168. data.keywords[id] = {
  169. id,
  170. keyword,
  171. filterMode,
  172. filterLevel,
  173. };
  174.  
  175. saveData();
  176.  
  177. return id;
  178. };
  179.  
  180. // 增加属地
  181. const addLocation = (keyword, filterMode = FILTER_MODE[0]) => {
  182. const id =
  183. Math.max(...Object.values(data.locations).map((item) => item.id), 0) + 1;
  184.  
  185. data.locations[id] = {
  186. id,
  187. keyword,
  188. filterMode,
  189. };
  190.  
  191. saveData();
  192.  
  193. return id;
  194. };
  195.  
  196. // 旧版本数据迁移
  197. {
  198. const dataKey = "troll_data";
  199. const modeKey = "troll_mode";
  200. const keywordKey = "troll_keyword";
  201.  
  202. if (localStorage.getItem(dataKey)) {
  203. let trollMap = (function () {
  204. try {
  205. return JSON.parse(localStorage.getItem(dataKey)) || {};
  206. } catch (e) {}
  207.  
  208. return {};
  209. })();
  210.  
  211. let filterMode = ~~localStorage.getItem(modeKey);
  212.  
  213. let filterKeyword = localStorage.getItem(keywordKey) || "";
  214.  
  215. // 整理标签
  216. [...new Set(Object.values(trollMap).flat())].forEach((item) =>
  217. addTag(item)
  218. );
  219.  
  220. // 整理用户
  221. Object.keys(trollMap).forEach((item) => {
  222. addUser(
  223. item,
  224. null,
  225. (typeof trollMap[item] === "object" ? trollMap[item] : []).map(
  226. (tag) => addTag(tag)
  227. )
  228. );
  229. });
  230.  
  231. data.options.filterMode = filterMode ? "隐藏" : "标记";
  232. data.options.keyword = filterKeyword;
  233.  
  234. localStorage.removeItem(dataKey);
  235. localStorage.removeItem(modeKey);
  236. localStorage.removeItem(keywordKey);
  237.  
  238. saveData();
  239. }
  240.  
  241. // v1.1.0 -> v1.1.1
  242. {
  243. Object.values(data.users).forEach(({ id, name, tags, enabled }) => {
  244. if (enabled !== undefined) {
  245. data.users[id] = {
  246. id,
  247. name,
  248. tags,
  249. filterMode: enabled ? "继承" : "显示",
  250. };
  251. }
  252. });
  253.  
  254. Object.values(data.tags).forEach(({ id, name, color, enabled }) => {
  255. if (enabled !== undefined) {
  256. data.tags[id] = {
  257. id,
  258. name,
  259. color,
  260. filterMode: enabled ? "继承" : "显示",
  261. };
  262. }
  263. });
  264.  
  265. if (data.options.filterMode === 0) {
  266. data.options.filterMode = "隐藏";
  267. } else if (data.options.filterMode === 1) {
  268. data.options.filterMode = "标记";
  269. }
  270.  
  271. saveData();
  272. }
  273.  
  274. // v1.2.x -> v1.3.0
  275. {
  276. if (data.options.keyword) {
  277. addKeyword(data.options.keyword);
  278.  
  279. delete data.options.keyword;
  280.  
  281. saveData();
  282. }
  283. }
  284. }
  285.  
  286. // 编辑用户标记
  287. const editUser = (() => {
  288. let window;
  289. return (uid, name, callback) => {
  290. if (window === undefined) {
  291. window = n.createCommmonWindow();
  292. }
  293.  
  294. const user = data.users[uid];
  295.  
  296. const content = document.createElement("div");
  297.  
  298. const size = Math.floor((screen.width * 0.8) / 200);
  299.  
  300. const items = Object.values(data.tags).map(
  301. (tag, index) => `
  302. <td class="c1">
  303. <label for="s-tag-${index}" style="display: block; cursor: pointer;">
  304. <b class="block_txt nobr" style="background:${
  305. tag.color
  306. }; color:#fff; margin: 0.1em 0.2em;">${tag.name}</b>
  307. </label>
  308. </td>
  309. <td class="c2" width="1">
  310. <input id="s-tag-${index}" type="checkbox" value="${tag.id}" ${
  311. user && user.tags.find((item) => item === tag.id) && "checked"
  312. }/>
  313. </td>
  314. `
  315. );
  316.  
  317. const rows = [...new Array(Math.ceil(items.length / size))].map(
  318. (item, index) =>
  319. `
  320. <tr class="row${(index % 2) + 1}">
  321. ${items.slice(size * index, size * (index + 1)).join("")}
  322. </tr>
  323. `
  324. );
  325.  
  326. content.className = "w100";
  327. content.innerHTML = `
  328. <div class="filter-table-wrapper" style="width: 80vw;">
  329. <table class="filter-table forumbox">
  330. <tbody>
  331. ${rows.join("")}
  332. </tbody>
  333. </table>
  334. </div>
  335. <div style="margin: 10px 0;">
  336. <input placeholder="一次性添加多个标记用&quot;|&quot;隔开,不会添加重名标记" style="width: -webkit-fill-available;" />
  337. </div>
  338. <div style="margin: 10px 0;">
  339. <span>过滤方式:</span>
  340. <button>${(user && user.filterMode) || FILTER_MODE[0]}</button>
  341. <div class="right_">
  342. <button>删除</button>
  343. <button>保存</button>
  344. </div>
  345. </div>
  346. <div class="silver" style="margin-top: 5px;">${FILTER_TIPS}</div>
  347. `;
  348.  
  349. const actions = content.getElementsByTagName("button");
  350.  
  351. actions[0].onclick = () => {
  352. actions[0].innerText = switchFilterMode(
  353. actions[0].innerText || FILTER_MODE[0]
  354. );
  355. };
  356.  
  357. actions[1].onclick = () => {
  358. if (confirm("是否确认?")) {
  359. delete data.users[uid];
  360.  
  361. saveData();
  362.  
  363. callback && callback();
  364.  
  365. window._.hide();
  366. }
  367. };
  368.  
  369. actions[2].onclick = () => {
  370. if (confirm("是否确认?")) {
  371. const values = [...content.getElementsByTagName("input")];
  372. const newTags = values[values.length - 1].value
  373. .split("|")
  374. .filter((item) => item.length)
  375. .map((item) => addTag(item));
  376. const tags = [
  377. ...new Set(
  378. values
  379. .filter((item) => item.type === "checkbox" && item.checked)
  380. .map((item) => ~~item.value)
  381. .concat(newTags)
  382. ),
  383. ].sort();
  384.  
  385. if (user) {
  386. user.tags = tags;
  387. user.filterMode = actions[0].innerText;
  388. } else {
  389. addUser(uid, name, tags, actions[0].innerText);
  390. }
  391.  
  392. saveData();
  393.  
  394. callback && callback();
  395.  
  396. window._.hide();
  397. }
  398. };
  399.  
  400. if (user === undefined) {
  401. actions[1].style = "display: none;";
  402. }
  403.  
  404. window._.addContent(null);
  405. window._.addTitle(`编辑标记 - ${name ? name : "#" + uid}`);
  406. window._.addContent(content);
  407. window._.show();
  408. };
  409. })();
  410.  
  411. // 猎巫
  412. const witchHunter = (() => {
  413. const key = "WITCH_HUNTER";
  414.  
  415. const data = GM_getValue(key) || {};
  416.  
  417. const add = async (fid, label) => {
  418. if (Object.values(data).find((item) => item.fid === fid)) {
  419. alert("已有相同版面ID");
  420. return;
  421. }
  422.  
  423. const info = await new Promise((resolve) => {
  424. request(`/thread.php?lite=js&fid=${fid}`)
  425. .then((res) => res.blob())
  426. .then((blob) => {
  427. const reader = new FileReader();
  428.  
  429. reader.onload = () => {
  430. const text = reader.result;
  431. const result = JSON.parse(
  432. text.replace("window.script_muti_get_var_store=", "")
  433. );
  434.  
  435. resolve(result.data);
  436. };
  437.  
  438. reader.readAsText(blob, "GBK");
  439. })
  440. .catch(() => {
  441. resolve({});
  442. });
  443. });
  444.  
  445. if (info.__F === undefined) {
  446. alert("版面ID有误");
  447. return;
  448. }
  449.  
  450. const name = info.__F.name;
  451.  
  452. const id = Math.max(...Object.values(data).map((item) => item.id), 0) + 1;
  453.  
  454. const hash = (() => {
  455. let h = 5381;
  456. for (var i = 0; i < label.length; i++) {
  457. h = ((h << 5) + h + label.charCodeAt(i)) & 0xffffffff;
  458. }
  459. return h;
  460. })();
  461.  
  462. const hex = Math.abs(hash).toString(16) + "000000";
  463.  
  464. const hsv = [
  465. `0x${hex.substring(2, 4)}` / 255,
  466. `0x${hex.substring(2, 4)}` / 255 / 2 + 0.25,
  467. `0x${hex.substring(4, 6)}` / 255 / 2 + 0.25,
  468. ];
  469.  
  470. const rgb = n.hsvToRgb(hsv[0], hsv[1], hsv[2]);
  471.  
  472. const color = ["#", ...rgb].reduce((a, b) => {
  473. return a + ("0" + b.toString(16)).slice(-2);
  474. });
  475.  
  476. data[id] = {
  477. id,
  478. fid,
  479. name,
  480. label,
  481. color,
  482. };
  483.  
  484. GM_setValue(key, data);
  485. };
  486.  
  487. const remove = (id) => {
  488. delete data[id];
  489.  
  490. GM_setValue(key, data);
  491. };
  492.  
  493. const run = (uid, element) => {
  494. if (uid < 0) {
  495. return;
  496. }
  497.  
  498. Promise.all(
  499. Object.values(data).map(async (item) => {
  500. const api = `/thread.php?lite=js&fid=${item.fid}&authorid=${uid}`;
  501.  
  502. const verify =
  503. (await new Promise((resolve) => {
  504. request(api)
  505. .then((res) => res.blob())
  506. .then((blob) => {
  507. const reader = new FileReader();
  508.  
  509. reader.onload = () => {
  510. const text = reader.result;
  511. const result = JSON.parse(
  512. text.replace("window.script_muti_get_var_store=", "")
  513. );
  514.  
  515. if (result.error) {
  516. resolve(false);
  517. return;
  518. }
  519.  
  520. resolve(true);
  521. };
  522.  
  523. reader.readAsText(blob, "GBK");
  524. })
  525. .catch(() => {
  526. resolve(false);
  527. });
  528. })) ||
  529. (await new Promise((resolve) => {
  530. request(`${api}&searchpost=1`)
  531. .then((res) => res.blob())
  532. .then((blob) => {
  533. const reader = new FileReader();
  534.  
  535. reader.onload = () => {
  536. const text = reader.result;
  537. const result = JSON.parse(
  538. text.replace("window.script_muti_get_var_store=", "")
  539. );
  540.  
  541. if (result.error) {
  542. resolve(false);
  543. return;
  544. }
  545.  
  546. resolve(true);
  547. };
  548.  
  549. reader.readAsText(blob, "GBK");
  550. })
  551. .catch(() => {
  552. resolve(false);
  553. });
  554. }));
  555.  
  556. if (verify) {
  557. return item;
  558. }
  559. })
  560. )
  561. .then((res) => res.filter((item) => item))
  562. .then((res) => {
  563. res
  564. .filter(
  565. (current, index) =>
  566. res.findIndex((item) => item.label === current.label) === index
  567. )
  568. .forEach((item) => {
  569. element.style.display = "block";
  570. element.innerHTML += `<b class="block_txt nobr" style="background:${item.color}; color:#fff; margin: 0.1em 0.2em;">${item.label}</b>`;
  571. });
  572. });
  573. };
  574.  
  575. return {
  576. add,
  577. remove,
  578. run,
  579. data,
  580. };
  581. })();
  582.  
  583. // 小号过滤和声望过滤
  584. const getFilterModeByUserInfo = async (userInfo, reputation) => {
  585. const filterRegdateLimit = data.options.filterRegdateLimit || 0;
  586.  
  587. const filterPostnumLimit = data.options.filterPostnumLimit || 0;
  588.  
  589. const filterReputationLimit = data.options.filterReputationLimit || NaN;
  590.  
  591. if (userInfo) {
  592. const { regdate, postnum } = userInfo;
  593.  
  594. if (
  595. filterRegdateLimit > 0 &&
  596. regdate * 1000 > new Date() - filterRegdateLimit
  597. ) {
  598. return true;
  599. }
  600.  
  601. if (filterPostnumLimit > 0 && postnum < filterPostnumLimit) {
  602. return true;
  603. }
  604. }
  605.  
  606. if (Number.isNaN(filterReputationLimit) === false) {
  607. if (reputation < filterReputationLimit) {
  608. return true;
  609. }
  610. }
  611.  
  612. return false;
  613. };
  614.  
  615. // 判断过滤方式
  616. const getFilterMode = async (uid, subject, content) => {
  617. let result = -1;
  618.  
  619. const user = data.users[uid];
  620.  
  621. const tags = user ? user.tags.map((tag) => data.tags[tag]) : [];
  622.  
  623. const keywords = Object.values(data.keywords);
  624.  
  625. const locations = Object.values(data.locations);
  626.  
  627. if (uid && uid > 0) {
  628. const userInfo = n.userInfo.users[uid];
  629.  
  630. const reputation = (() => {
  631. const reputations = n.userInfo.reputations;
  632.  
  633. if (reputations) {
  634. for (let fid in reputations) {
  635. return reputations[fid][uid] || 0;
  636. }
  637. }
  638.  
  639. return NaN;
  640. })();
  641.  
  642. if (await getFilterModeByUserInfo(userInfo, reputation)) {
  643. return FILTER_MODE.indexOf("隐藏");
  644. }
  645. }
  646.  
  647. if (user) {
  648. const filterMode = FILTER_MODE.indexOf(user.filterMode);
  649.  
  650. if (filterMode > 0) {
  651. return filterMode;
  652. }
  653.  
  654. result = filterMode;
  655. }
  656.  
  657. if (tags.length) {
  658. const filterMode = (() => {
  659. if (tags.some((tag) => tag.filterMode !== "显示")) {
  660. return tags
  661. .filter((tag) => tag.filterMode !== "显示")
  662. .map((tag) => FILTER_MODE.indexOf(tag.filterMode) || 0)
  663. .sort((a, b) => b - a)[0];
  664. }
  665.  
  666. return FILTER_MODE.indexOf("显示");
  667. })();
  668.  
  669. if (filterMode > 0) {
  670. return filterMode;
  671. }
  672.  
  673. result = filterMode;
  674. }
  675.  
  676. if (keywords.length) {
  677. const filterMode = (() => {
  678. const sR = (() => {
  679. if (subject) {
  680. const r = keywords
  681. .filter((item) => item.keyword && item.filterMode !== "显示")
  682. .filter((item) => (item.filterLevel || 0) >= 0)
  683. .sort(
  684. (a, b) =>
  685. FILTER_MODE.indexOf(b.filterMode) -
  686. FILTER_MODE.indexOf(a.filterMode)
  687. )
  688. .find((item) => subject.search(item.keyword) >= 0);
  689.  
  690. if (r) {
  691. return FILTER_MODE.indexOf(r.filterMode);
  692. }
  693. }
  694.  
  695. return -1;
  696. })();
  697.  
  698. const cR = (() => {
  699. if (content) {
  700. const r = keywords
  701. .filter((item) => item.keyword && item.filterMode !== "显示")
  702. .filter((item) => (item.filterLevel || 0) >= 1)
  703. .sort(
  704. (a, b) =>
  705. FILTER_MODE.indexOf(b.filterMode) -
  706. FILTER_MODE.indexOf(a.filterMode)
  707. )
  708. .find((item) => content.search(item.keyword) >= 0);
  709.  
  710. if (r) {
  711. return FILTER_MODE.indexOf(r.filterMode);
  712. }
  713. }
  714.  
  715. return -1;
  716. })();
  717.  
  718. return Math.max(sR, cR, result);
  719. })();
  720.  
  721. if (filterMode > 0) {
  722. return filterMode;
  723. }
  724.  
  725. result = filterMode;
  726. }
  727.  
  728. if (locations.length) {
  729. const { ipLoc } = await new Promise((resolve) => {
  730. request(`/nuke.php?lite=js&__lib=ucp&__act=get&uid=${uid}`)
  731. .then((res) => res.blob())
  732. .then((blob) => {
  733. const reader = new FileReader();
  734.  
  735. reader.onload = () => {
  736. const text = reader.result;
  737. const result = JSON.parse(
  738. text.replace("window.script_muti_get_var_store=", "")
  739. );
  740.  
  741. resolve(result.data[0]);
  742. };
  743.  
  744. reader.readAsText(blob, "GBK");
  745. })
  746. .catch(() => {
  747. resolve({});
  748. });
  749. });
  750.  
  751. if (ipLoc) {
  752. const filterMode = (() => {
  753. const r = locations
  754. .filter((item) => item.keyword && item.filterMode !== "显示")
  755. .sort(
  756. (a, b) =>
  757. FILTER_MODE.indexOf(b.filterMode) -
  758. FILTER_MODE.indexOf(a.filterMode)
  759. )
  760. .find((item) => ipLoc.search(item.keyword) >= 0);
  761.  
  762. if (r) {
  763. return FILTER_MODE.indexOf(r.filterMode);
  764. }
  765.  
  766. return Math.max(r, result);
  767. })();
  768.  
  769. if (filterMode > 0) {
  770. return filterMode;
  771. }
  772.  
  773. result = filterMode;
  774. }
  775. }
  776.  
  777. return result;
  778. };
  779.  
  780. // 根据 TID 获取过滤方式
  781. const getFilterModeByTopic = async (tid) => {
  782. return await new Promise((resolve, reject) => {
  783. const api = `/read.php?tid=${tid}`;
  784.  
  785. request(api)
  786. .then((res) => res.blob())
  787. .then((blob) => {
  788. const getLastIndex = (content, position) => {
  789. if (position >= 0) {
  790. let nextIndex = position + 1;
  791.  
  792. while (nextIndex < content.length) {
  793. if (content[nextIndex] === "}") {
  794. return nextIndex;
  795. }
  796.  
  797. if (content[nextIndex] === "{") {
  798. nextIndex = getLastIndex(content, nextIndex);
  799.  
  800. if (nextIndex < 0) {
  801. break;
  802. }
  803. }
  804.  
  805. nextIndex = nextIndex + 1;
  806. }
  807. }
  808.  
  809. return -1;
  810. };
  811.  
  812. const reader = new FileReader();
  813.  
  814. reader.onload = async () => {
  815. const parser = new DOMParser();
  816.  
  817. const doc = parser.parseFromString(reader.result, "text/html");
  818.  
  819. const html = doc.body.innerHTML;
  820.  
  821. // 验证帖子正常
  822. const verify = doc.querySelector("#m_posts");
  823.  
  824. if (verify) {
  825. // 取得顶楼 UID
  826. const uid = (() => {
  827. const ele = doc.querySelector("#postauthor0");
  828.  
  829. if (ele) {
  830. const res = ele.getAttribute("href").match(/uid=(\S+)/);
  831.  
  832. if (res) {
  833. return res[1];
  834. }
  835. }
  836.  
  837. return 0;
  838. })();
  839.  
  840. // 取得顶楼标题
  841. const subject = doc.querySelector("#postsubject0").innerHTML;
  842.  
  843. // 取得顶楼内容
  844. const content = doc.querySelector("#postcontent0").innerHTML;
  845.  
  846. if (uid && uid > 0) {
  847. // 取得用户信息
  848. const userInfo = (() => {
  849. // 起始JSON
  850. const str = `"${uid}":{`;
  851.  
  852. // 起始下标
  853. const index = html.indexOf(str) + str.length;
  854.  
  855. // 结尾下标
  856. const lastIndex = getLastIndex(html, index);
  857.  
  858. if (lastIndex >= 0) {
  859. return JSON.parse(`{${html.substring(index, lastIndex)}}`);
  860. }
  861.  
  862. return null;
  863. })();
  864.  
  865. // 取得用户声望
  866. const reputation = (() => {
  867. const reputations = (() => {
  868. // 起始JSON
  869. const str = `"__REPUTATIONS":{`;
  870.  
  871. // 起始下标
  872. const index = html.indexOf(str) + str.length;
  873.  
  874. // 结尾下标
  875. const lastIndex = getLastIndex(html, index);
  876.  
  877. if (lastIndex >= 0) {
  878. return JSON.parse(
  879. `{${html.substring(index, lastIndex)}}`
  880. );
  881. }
  882.  
  883. return null;
  884. })();
  885.  
  886. if (reputations) {
  887. for (let fid in reputations) {
  888. return reputations[fid][uid] || 0;
  889. }
  890. }
  891.  
  892. return NaN;
  893. })();
  894.  
  895. if (await getFilterModeByUserInfo(userInfo, reputation)) {
  896. resolve(FILTER_MODE.indexOf("隐藏"));
  897. }
  898. }
  899.  
  900. resolve(getFilterMode(uid, subject, content));
  901. } else {
  902. reject();
  903. }
  904. };
  905.  
  906. reader.readAsText(blob, "GBK");
  907. })
  908. .catch(() => {
  909. reject();
  910. });
  911. }).catch(() => {
  912. return FILTER_MODE.indexOf("隐藏");
  913. });
  914. };
  915.  
  916. // 处理引用
  917. const handleQuote = async (content) => {
  918. const quotes = content.querySelectorAll(".quote");
  919.  
  920. await Promise.all(
  921. [...quotes].map(async (quote) => {
  922. const uid = (() => {
  923. const ele = quote.querySelector("a[href^='/nuke.php']");
  924.  
  925. if (ele) {
  926. const res = ele.getAttribute("href").match(/uid=(\S+)/);
  927.  
  928. if (res) {
  929. return res[1];
  930. }
  931. }
  932.  
  933. return 0;
  934. })();
  935.  
  936. const filterMode = await new Promise(async (resolve) => {
  937. const mode = await getFilterMode(uid, "", quote.innerText);
  938.  
  939. if (mode === 0) {
  940. resolve(data.options.filterMode);
  941. }
  942.  
  943. if (mode > 0) {
  944. resolve(FILTER_MODE[mode]);
  945. }
  946.  
  947. resolve("");
  948. });
  949.  
  950. if (filterMode === "标记") {
  951. quote.innerHTML = `
  952. <div class="lessernuke" style="background: #81C7D4; border-color: #66BAB7; ">
  953. <span class="crimson">Troll must die.</span>
  954. <a href="javascript:void(0)" onclick="[...document.getElementsByName('troll_${uid}')].forEach(item => item.style.display = '')">点击查看</a>
  955. <div style="display: none;" name="troll_${uid}">
  956. ${quote.innerHTML}
  957. </div>
  958. </div>`;
  959. } else if (filterMode === "遮罩") {
  960. const source = document.createElement("DIV");
  961.  
  962. source.innerHTML = quote.innerHTML;
  963. source.style.display = "none";
  964.  
  965. const caption = document.createElement("CAPTION");
  966.  
  967. caption.className = "filter-mask filter-mask-block";
  968.  
  969. caption.innerHTML = `<span class="crimson">Troll must die.</span>`;
  970. caption.onclick = () => {
  971. quote.removeChild(caption);
  972.  
  973. source.style.display = "";
  974. };
  975.  
  976. quote.innerHTML = "";
  977. quote.appendChild(source);
  978. quote.appendChild(caption);
  979. } else if (filterMode === "隐藏") {
  980. quote.innerHTML = "";
  981. }
  982. })
  983. );
  984. };
  985.  
  986. // 过滤
  987. const reFilter = (() => {
  988. let hasNext = false;
  989. let isRunning = false;
  990.  
  991. const func = async () => {
  992. const tPage = location.pathname === "/thread.php";
  993. const pPage = location.pathname === "/read.php";
  994.  
  995. if (tPage) {
  996. const params = new URLSearchParams(location.search);
  997.  
  998. if (params.has("favor")) {
  999. return;
  1000. }
  1001.  
  1002. if (params.has("authorid")) {
  1003. return;
  1004. }
  1005. }
  1006.  
  1007. if (tPage) {
  1008. const tData = n.topicArg.data;
  1009.  
  1010. await Promise.all(
  1011. Object.values(tData).map(async (item) => {
  1012. if (item.containerC) return;
  1013.  
  1014. const tid = item[8];
  1015.  
  1016. const filterMode = await new Promise(async (resolve) => {
  1017. const mode = await getFilterModeByTopic(tid);
  1018.  
  1019. if (mode === 0) {
  1020. resolve(data.options.filterMode);
  1021. }
  1022.  
  1023. if (mode > 0) {
  1024. resolve(FILTER_MODE[mode]);
  1025. }
  1026.  
  1027. resolve("");
  1028. });
  1029.  
  1030. item.contentC = item[1];
  1031.  
  1032. item.contentB = item.contentB || item.contentC.innerHTML;
  1033.  
  1034. item.containerC =
  1035. item.containerC || item.contentC.parentNode.parentNode;
  1036.  
  1037. item.containerC.style = "";
  1038. item.contentC.style = "";
  1039. item[1].className = item[1].className.replace(" filter-mask", "");
  1040. item[2].className = item[2].className.replace(" filter-mask", "");
  1041.  
  1042. if (filterMode === "标记") {
  1043. item.contentC.style = "text-decoration: line-through;";
  1044. } else if (filterMode === "遮罩") {
  1045. item[1].className += " filter-mask";
  1046. item[2].className += " filter-mask";
  1047. } else if (filterMode === "隐藏") {
  1048. item.containerC.style = "display: none;";
  1049. }
  1050. })
  1051. );
  1052. } else if (pPage) {
  1053. const pData = n.postArg.data;
  1054.  
  1055. await Promise.all(
  1056. Object.values(pData).map(async (item) => {
  1057. if (~~item.pAid === self) return;
  1058. if (item.containerC) return;
  1059.  
  1060. if (typeof item.i === "number") {
  1061. item.actionC =
  1062. item.actionC ||
  1063. (() => {
  1064. const ele = item.uInfoC.querySelector('[name="uid"]');
  1065.  
  1066. ele.onclick = null;
  1067.  
  1068. return ele;
  1069. })();
  1070.  
  1071. item.tagC =
  1072. item.tagC ||
  1073. (() => {
  1074. const tc = document.createElement("div");
  1075.  
  1076. tc.className = "filter-tags";
  1077.  
  1078. item.uInfoC.appendChild(tc);
  1079.  
  1080. return tc;
  1081. })();
  1082. }
  1083.  
  1084. item.pName =
  1085. item.pName ||
  1086. item.uInfoC.getElementsByClassName("author")[0].innerText;
  1087.  
  1088. item.reFilter =
  1089. item.reFilter ||
  1090. (async () => {
  1091. const uid = item.pAid;
  1092.  
  1093. const filterMode = await new Promise(async (resolve) => {
  1094. const mode = await getFilterMode(
  1095. uid,
  1096. item.subjectC.innerText,
  1097. item.contentC.innerText
  1098. );
  1099.  
  1100. if (mode === 0) {
  1101. resolve(data.options.filterMode);
  1102. }
  1103.  
  1104. if (mode > 0) {
  1105. resolve(FILTER_MODE[mode]);
  1106. }
  1107.  
  1108. resolve("");
  1109. });
  1110.  
  1111. item.avatarC =
  1112. item.avatarC ||
  1113. (() => {
  1114. const tc = document.createElement("div");
  1115.  
  1116. const avatar = document.getElementById(
  1117. `posteravatar${item.i}`
  1118. );
  1119.  
  1120. if (avatar) {
  1121. avatar.parentNode.insertBefore(tc, avatar.nextSibling);
  1122.  
  1123. tc.appendChild(avatar);
  1124. }
  1125.  
  1126. return tc;
  1127. })();
  1128.  
  1129. item.contentB = item.contentB || item.contentC.innerHTML;
  1130.  
  1131. item.containerC =
  1132. item.containerC ||
  1133. (() => {
  1134. let temp = item.contentC;
  1135.  
  1136. if (item.i >= 0) {
  1137. while (temp.nodeName !== "TBODY") {
  1138. temp = temp.parentNode;
  1139. }
  1140. } else {
  1141. while (temp.nodeName !== "DIV") {
  1142. temp = temp.parentNode;
  1143. }
  1144. }
  1145.  
  1146. return temp;
  1147. })();
  1148.  
  1149. item.avatarC.style.display = "";
  1150. item.containerC.style.display = "";
  1151. item.contentC.innerHTML = item.contentB;
  1152.  
  1153. if (item.actionC) {
  1154. item.actionC.style = "background: #aaa;";
  1155. }
  1156.  
  1157. if (filterMode === "标记") {
  1158. item.avatarC.style.display = "none";
  1159. item.contentC.innerHTML = `
  1160. <div class="lessernuke" style="background: #81C7D4; border-color: #66BAB7; ">
  1161. <span class="crimson">Troll must die.</span>
  1162. <a href="javascript:void(0)" onclick="[...document.getElementsByName('troll_${uid}')].forEach(item => item.style.display = '')">点击查看</a>
  1163. <div style="display: none;" name="troll_${uid}">
  1164. ${item.contentB}
  1165. </div>
  1166. </div>`;
  1167.  
  1168. if (item.actionC && data.users[uid]) {
  1169. item.actionC.style = "background: #cb4042;";
  1170. }
  1171. } else if (filterMode === "遮罩") {
  1172. const caption = document.createElement("CAPTION");
  1173.  
  1174. if (item.i >= 0) {
  1175. caption.className = "filter-mask filter-mask-block";
  1176. } else {
  1177. caption.className = "filter-mask filter-mask-block left";
  1178. caption.style = "width: 47%;";
  1179. }
  1180.  
  1181. caption.innerHTML = `<span class="crimson">Troll must die.</span>`;
  1182. caption.onclick = () => {
  1183. item.containerC.parentNode.removeChild(caption);
  1184. item.containerC.style.display = "";
  1185. };
  1186.  
  1187. item.containerC.parentNode.insertBefore(
  1188. caption,
  1189. item.containerC
  1190. );
  1191. item.containerC.style.display = "none";
  1192.  
  1193. if (item.actionC && data.users[uid]) {
  1194. item.actionC.style = "background: #cb4042;";
  1195. }
  1196. } else if (filterMode === "隐藏") {
  1197. item.containerC.style.display = "none";
  1198. } else {
  1199. await handleQuote(item.contentC);
  1200. }
  1201.  
  1202. if (item.tagC) {
  1203. const tags = data.users[uid]
  1204. ? data.users[uid].tags.map((tag) => data.tags[tag]) || []
  1205. : [];
  1206.  
  1207. item.tagC.style.display = tags.length ? "" : "none";
  1208. item.tagC.innerHTML = tags
  1209. .map(
  1210. (tag) =>
  1211. `<b class="block_txt nobr" style="background:${tag.color}; color:#fff; margin: 0.1em 0.2em;">${tag.name}</b>`
  1212. )
  1213. .join("");
  1214.  
  1215. witchHunter.run(uid, item.tagC);
  1216. }
  1217. });
  1218.  
  1219. if (item.actionC) {
  1220. item.actionC.onclick =
  1221. item.actionC.onclick ||
  1222. ((e) => {
  1223. if (item.pAid < 0) return;
  1224.  
  1225. const user = data.users[item.pAid];
  1226.  
  1227. if (e.ctrlKey === false) {
  1228. editUser(item.pAid, item.pName, item.reFilter);
  1229. } else {
  1230. if (user) {
  1231. delete data.users[user.id];
  1232. } else {
  1233. addUser(item.pAid, item.pName);
  1234. }
  1235.  
  1236. saveData();
  1237. item.reFilter();
  1238. }
  1239. });
  1240. }
  1241.  
  1242. await item.reFilter();
  1243. })
  1244. );
  1245. }
  1246. };
  1247.  
  1248. const execute = () =>
  1249. func().finally(() => {
  1250. if (hasNext) {
  1251. hasNext = false;
  1252.  
  1253. execute();
  1254. } else {
  1255. isRunning = false;
  1256. }
  1257. });
  1258.  
  1259. return async () => {
  1260. if (isRunning) {
  1261. hasNext = true;
  1262. } else {
  1263. isRunning = true;
  1264.  
  1265. await execute();
  1266. }
  1267. };
  1268. })();
  1269.  
  1270. // STYLE
  1271. GM_addStyle(`
  1272. .filter-table-wrapper {
  1273. max-height: 80vh;
  1274. overflow-y: auto;
  1275. }
  1276. .filter-table {
  1277. margin: 0;
  1278. }
  1279. .filter-table th,
  1280. .filter-table td {
  1281. position: relative;
  1282. white-space: nowrap;
  1283. }
  1284. .filter-table th {
  1285. position: sticky;
  1286. top: 2px;
  1287. z-index: 1;
  1288. }
  1289. .filter-table input:not([type]), .filter-table input[type="text"] {
  1290. margin: 0;
  1291. box-sizing: border-box;
  1292. height: 100%;
  1293. width: 100%;
  1294. }
  1295. .filter-input-wrapper {
  1296. position: absolute;
  1297. top: 6px;
  1298. right: 6px;
  1299. bottom: 6px;
  1300. left: 6px;
  1301. }
  1302. .filter-text-ellipsis {
  1303. display: flex;
  1304. }
  1305. .filter-text-ellipsis > * {
  1306. flex: 1;
  1307. width: 1px;
  1308. overflow: hidden;
  1309. text-overflow: ellipsis;
  1310. }
  1311. .filter-button-group {
  1312. margin: -.1em -.2em;
  1313. }
  1314. .filter-tags {
  1315. margin: 2px -0.2em 0;
  1316. text-align: left;
  1317. }
  1318. .filter-mask {
  1319. margin: 1px;
  1320. color: #81C7D4;
  1321. background: #81C7D4;
  1322. }
  1323. .filter-mask-block {
  1324. display: block;
  1325. border: 1px solid #66BAB7;
  1326. text-align: center !important;
  1327. }
  1328. .filter-input-wrapper {
  1329. position: absolute;
  1330. top: 6px;
  1331. right: 6px;
  1332. bottom: 6px;
  1333. left: 6px;
  1334. }
  1335. `);
  1336.  
  1337. // UI
  1338. const u = (() => {
  1339. const modules = {};
  1340.  
  1341. const tabContainer = (() => {
  1342. const c = document.createElement("div");
  1343.  
  1344. c.className = "w100";
  1345. c.innerHTML = `
  1346. <div class="right_" style="margin-bottom: 5px;">
  1347. <table class="stdbtn" cellspacing="0">
  1348. <tbody>
  1349. <tr></tr>
  1350. </tbody>
  1351. </table>
  1352. </div>
  1353. <div class="clear"></div>
  1354. `;
  1355.  
  1356. return c;
  1357. })();
  1358.  
  1359. const tabPanelContainer = (() => {
  1360. const c = document.createElement("div");
  1361.  
  1362. c.style = "width: 80vw;";
  1363.  
  1364. return c;
  1365. })();
  1366.  
  1367. const content = (() => {
  1368. const c = document.createElement("div");
  1369.  
  1370. c.append(tabContainer);
  1371. c.append(tabPanelContainer);
  1372.  
  1373. return c;
  1374. })();
  1375.  
  1376. const addModule = (() => {
  1377. const tc = tabContainer.getElementsByTagName("tr")[0];
  1378. const cc = tabPanelContainer;
  1379.  
  1380. return (module) => {
  1381. const tabBox = document.createElement("td");
  1382.  
  1383. tabBox.innerHTML = `<a href="javascript:void(0)" class="nobr silver">${module.name}</a>`;
  1384.  
  1385. const tab = tabBox.childNodes[0];
  1386.  
  1387. const toggle = () => {
  1388. Object.values(modules).forEach((item) => {
  1389. if (item.tab === tab) {
  1390. item.tab.className = "nobr";
  1391. item.content.style = "display: block";
  1392. item.refresh();
  1393. } else {
  1394. item.tab.className = "nobr silver";
  1395. item.content.style = "display: none";
  1396. }
  1397. });
  1398. };
  1399.  
  1400. tc.append(tabBox);
  1401. cc.append(module.content);
  1402.  
  1403. tab.onclick = toggle;
  1404.  
  1405. modules[module.name] = {
  1406. ...module,
  1407. tab,
  1408. toggle,
  1409. };
  1410.  
  1411. return modules[module.name];
  1412. };
  1413. })();
  1414.  
  1415. return {
  1416. content,
  1417. modules,
  1418. addModule,
  1419. };
  1420. })();
  1421.  
  1422. // 用户
  1423. const userModule = (() => {
  1424. const content = (() => {
  1425. const c = document.createElement("div");
  1426.  
  1427. c.style = "display: none";
  1428. c.innerHTML = `
  1429. <div class="filter-table-wrapper">
  1430. <table class="filter-table forumbox">
  1431. <thead>
  1432. <tr class="block_txt_c0">
  1433. <th class="c1" width="1">昵称</th>
  1434. <th class="c2">标记</th>
  1435. <th class="c3" width="1">过滤方式</th>
  1436. <th class="c4" width="1">操作</th>
  1437. </tr>
  1438. </thead>
  1439. <tbody></tbody>
  1440. </table>
  1441. </div>
  1442. `;
  1443.  
  1444. return c;
  1445. })();
  1446.  
  1447. const refresh = (() => {
  1448. const container = content.getElementsByTagName("tbody")[0];
  1449.  
  1450. const func = () => {
  1451. container.innerHTML = "";
  1452.  
  1453. Object.values(data.users).forEach((item) => {
  1454. const tc = document.createElement("tr");
  1455.  
  1456. tc.className = `row${
  1457. (container.querySelectorAll("TR").length % 2) + 1
  1458. }`;
  1459.  
  1460. tc.refresh = () => {
  1461. if (data.users[item.id]) {
  1462. tc.innerHTML = `
  1463. <td class="c1">
  1464. <a href="/nuke.php?func=ucp&uid=${
  1465. item.id
  1466. }" class="b nobr">[${
  1467. item.name ? "@" + item.name : "#" + item.id
  1468. }]</a>
  1469. </td>
  1470. <td class="c2">
  1471. ${item.tags
  1472. .map((tag) => {
  1473. if (data.tags[tag]) {
  1474. return `<b class="block_txt nobr" style="background:${data.tags[tag].color}; color:#fff; margin: 0.1em 0.2em;">${data.tags[tag].name}</b>`;
  1475. }
  1476. })
  1477. .join("")}
  1478. </td>
  1479. <td class="c3">
  1480. <div class="filter-table-button-group">
  1481. <button>${item.filterMode || FILTER_MODE[0]}</button>
  1482. </div>
  1483. </td>
  1484. <td class="c4">
  1485. <div class="filter-table-button-group">
  1486. <button>编辑</button>
  1487. <button>删除</button>
  1488. </div>
  1489. </td>
  1490. `;
  1491.  
  1492. const actions = tc.getElementsByTagName("button");
  1493.  
  1494. actions[0].onclick = () => {
  1495. data.users[item.id].filterMode = switchFilterMode(
  1496. data.users[item.id].filterMode || FILTER_MODE[0]
  1497. );
  1498.  
  1499. actions[0].innerHTML = data.users[item.id].filterMode;
  1500.  
  1501. saveData();
  1502. reFilter();
  1503. };
  1504.  
  1505. actions[1].onclick = () => {
  1506. editUser(item.id, item.name, tc.refresh);
  1507. };
  1508.  
  1509. actions[2].onclick = () => {
  1510. if (confirm("是否确认?")) {
  1511. delete data.users[item.id];
  1512. container.removeChild(tc);
  1513.  
  1514. saveData();
  1515. reFilter();
  1516. }
  1517. };
  1518. } else {
  1519. tc.remove();
  1520. }
  1521. };
  1522.  
  1523. tc.refresh();
  1524.  
  1525. container.appendChild(tc);
  1526. });
  1527. };
  1528.  
  1529. return func;
  1530. })();
  1531.  
  1532. return {
  1533. name: "用户",
  1534. content,
  1535. refresh,
  1536. };
  1537. })();
  1538.  
  1539. // 标记
  1540. const tagModule = (() => {
  1541. const content = (() => {
  1542. const c = document.createElement("div");
  1543.  
  1544. c.style = "display: none";
  1545. c.innerHTML = `
  1546. <div class="filter-table-wrapper">
  1547. <table class="filter-table forumbox">
  1548. <thead>
  1549. <tr class="block_txt_c0">
  1550. <th class="c1" width="1">标记</th>
  1551. <th class="c2">列表</th>
  1552. <th class="c3" width="1">过滤方式</th>
  1553. <th class="c4" width="1">操作</th>
  1554. </tr>
  1555. </thead>
  1556. <tbody></tbody>
  1557. </table>
  1558. </div>
  1559. `;
  1560.  
  1561. return c;
  1562. })();
  1563.  
  1564. const refresh = (() => {
  1565. const container = content.getElementsByTagName("tbody")[0];
  1566.  
  1567. const func = () => {
  1568. container.innerHTML = "";
  1569.  
  1570. Object.values(data.tags).forEach((item) => {
  1571. const tc = document.createElement("tr");
  1572.  
  1573. tc.className = `row${
  1574. (container.querySelectorAll("TR").length % 2) + 1
  1575. }`;
  1576.  
  1577. tc.innerHTML = `
  1578. <td class="c1">
  1579. <b class="block_txt nobr" style="background:${
  1580. item.color
  1581. }; color:#fff; margin: 0.1em 0.2em;">${item.name}</b>
  1582. </td>
  1583. <td class="c2">
  1584. <button>${
  1585. Object.values(data.users).filter((user) =>
  1586. user.tags.find((tag) => tag === item.id)
  1587. ).length
  1588. }
  1589. </button>
  1590. <div style="white-space: normal; display: none;">
  1591. ${Object.values(data.users)
  1592. .filter((user) =>
  1593. user.tags.find((tag) => tag === item.id)
  1594. )
  1595. .map(
  1596. (user) =>
  1597. `<a href="/nuke.php?func=ucp&uid=${
  1598. user.id
  1599. }" class="b nobr">[${
  1600. user.name ? "@" + user.name : "#" + user.id
  1601. }]</a>`
  1602. )
  1603. .join("")}
  1604. </div>
  1605. </td>
  1606. <td class="c3">
  1607. <div class="filter-table-button-group">
  1608. <button>${item.filterMode || FILTER_MODE[0]}</button>
  1609. </div>
  1610. </td>
  1611. <td class="c4">
  1612. <div class="filter-table-button-group">
  1613. <button>删除</button>
  1614. </div>
  1615. </td>
  1616. `;
  1617.  
  1618. const actions = tc.getElementsByTagName("button");
  1619.  
  1620. actions[0].onclick = (() => {
  1621. let hide = true;
  1622. return () => {
  1623. hide = !hide;
  1624. actions[0].nextElementSibling.style.display = hide
  1625. ? "none"
  1626. : "block";
  1627. };
  1628. })();
  1629.  
  1630. actions[1].onclick = () => {
  1631. data.tags[item.id].filterMode = switchFilterMode(
  1632. data.tags[item.id].filterMode || FILTER_MODE[0]
  1633. );
  1634.  
  1635. actions[1].innerHTML = data.tags[item.id].filterMode;
  1636.  
  1637. saveData();
  1638. reFilter();
  1639. };
  1640.  
  1641. actions[2].onclick = () => {
  1642. if (confirm("是否确认?")) {
  1643. delete data.tags[item.id];
  1644.  
  1645. Object.values(data.users).forEach((user) => {
  1646. const index = user.tags.findIndex((tag) => tag === item.id);
  1647. if (index >= 0) {
  1648. user.tags.splice(index, 1);
  1649. }
  1650. });
  1651.  
  1652. container.removeChild(tc);
  1653.  
  1654. saveData();
  1655. reFilter();
  1656. }
  1657. };
  1658.  
  1659. container.appendChild(tc);
  1660. });
  1661. };
  1662.  
  1663. return func;
  1664. })();
  1665.  
  1666. return {
  1667. name: "标记",
  1668. content,
  1669. refresh,
  1670. };
  1671. })();
  1672.  
  1673. // 关键字
  1674. const keywordModule = (() => {
  1675. const content = (() => {
  1676. const c = document.createElement("div");
  1677.  
  1678. c.style = "display: none";
  1679. c.innerHTML = `
  1680. <div class="filter-table-wrapper">
  1681. <table class="filter-table forumbox">
  1682. <thead>
  1683. <tr class="block_txt_c0">
  1684. <th class="c1">列表</th>
  1685. <th class="c2" width="1">过滤方式</th>
  1686. <th class="c3" width="1">包括内容</th>
  1687. <th class="c4" width="1">操作</th>
  1688. </tr>
  1689. </thead>
  1690. <tbody></tbody>
  1691. </table>
  1692. </div>
  1693. <div class="silver" style="margin-top: 10px;">支持正则表达式。比如同类型的可以写在一条规则内用&quot;|&quot;隔开,&quot;ABC|DEF&quot;即为屏蔽带有ABC或者DEF的内容。</div>
  1694. `;
  1695.  
  1696. return c;
  1697. })();
  1698.  
  1699. const refresh = (() => {
  1700. const container = content.getElementsByTagName("tbody")[0];
  1701.  
  1702. const func = () => {
  1703. container.innerHTML = "";
  1704.  
  1705. Object.values(data.keywords).forEach((item) => {
  1706. const tc = document.createElement("tr");
  1707.  
  1708. tc.className = `row${
  1709. (container.querySelectorAll("TR").length % 2) + 1
  1710. }`;
  1711.  
  1712. tc.innerHTML = `
  1713. <td class="c1">
  1714. <div class="filter-input-wrapper">
  1715. <input value="${item.keyword || ""}" />
  1716. </div>
  1717. </td>
  1718. <td class="c2">
  1719. <div class="filter-table-button-group">
  1720. <button>${item.filterMode || FILTER_MODE[0]}</button>
  1721. </div>
  1722. </td>
  1723. <td class="c3">
  1724. <div style="text-align: center;">
  1725. <input type="checkbox" ${
  1726. item.filterLevel ? `checked="checked"` : ""
  1727. } />
  1728. </div>
  1729. </td>
  1730. <td class="c4">
  1731. <div class="filter-table-button-group">
  1732. <button>保存</button>
  1733. <button>删除</button>
  1734. </div>
  1735. </td>
  1736. `;
  1737.  
  1738. const inputElement = tc.querySelector("INPUT");
  1739. const levelElement = tc.querySelector(`INPUT[type="checkbox"]`);
  1740. const actions = tc.getElementsByTagName("button");
  1741.  
  1742. actions[0].onclick = () => {
  1743. actions[0].innerHTML = switchFilterMode(actions[0].innerHTML);
  1744. };
  1745.  
  1746. actions[1].onclick = () => {
  1747. if (inputElement.value) {
  1748. data.keywords[item.id] = {
  1749. id: item.id,
  1750. keyword: inputElement.value,
  1751. filterMode: actions[0].innerHTML,
  1752. filterLevel: levelElement.checked ? 1 : 0,
  1753. };
  1754.  
  1755. saveData();
  1756. refresh();
  1757. }
  1758. };
  1759.  
  1760. actions[2].onclick = () => {
  1761. if (confirm("是否确认?")) {
  1762. delete data.keywords[item.id];
  1763.  
  1764. saveData();
  1765. refresh();
  1766. }
  1767. };
  1768.  
  1769. container.appendChild(tc);
  1770. });
  1771.  
  1772. {
  1773. const tc = document.createElement("tr");
  1774.  
  1775. tc.className = `row${
  1776. (container.querySelectorAll("TR").length % 2) + 1
  1777. }`;
  1778.  
  1779. tc.innerHTML = `
  1780. <td class="c1">
  1781. <div class="filter-input-wrapper">
  1782. <input value="" />
  1783. </div>
  1784. </td>
  1785. <td class="c2">
  1786. <div class="filter-table-button-group">
  1787. <button>${FILTER_MODE[0]}</button>
  1788. </div>
  1789. </td>
  1790. <td class="c3">
  1791. <div style="text-align: center;">
  1792. <input type="checkbox" />
  1793. </div>
  1794. </td>
  1795. <td class="c4">
  1796. <div class="filter-table-button-group">
  1797. <button>添加</button>
  1798. </div>
  1799. </td>
  1800. `;
  1801.  
  1802. const inputElement = tc.querySelector("INPUT");
  1803. const levelElement = tc.querySelector(`INPUT[type="checkbox"]`);
  1804. const actions = tc.getElementsByTagName("button");
  1805.  
  1806. actions[0].onclick = () => {
  1807. actions[0].innerHTML = switchFilterMode(actions[0].innerHTML);
  1808. };
  1809.  
  1810. actions[1].onclick = () => {
  1811. if (inputElement.value) {
  1812. addKeyword(
  1813. inputElement.value,
  1814. actions[0].innerHTML,
  1815. levelElement.checked ? 1 : 0
  1816. );
  1817.  
  1818. saveData();
  1819. refresh();
  1820. }
  1821. };
  1822.  
  1823. container.appendChild(tc);
  1824. }
  1825. };
  1826.  
  1827. return func;
  1828. })();
  1829.  
  1830. return {
  1831. name: "关键字",
  1832. content,
  1833. refresh,
  1834. };
  1835. })();
  1836.  
  1837. // 属地
  1838. const locationModule = (() => {
  1839. const content = (() => {
  1840. const c = document.createElement("div");
  1841.  
  1842. c.style = "display: none";
  1843. c.innerHTML = `
  1844. <div class="filter-table-wrapper">
  1845. <table class="filter-table forumbox">
  1846. <thead>
  1847. <tr class="block_txt_c0">
  1848. <th class="c1">列表</th>
  1849. <th class="c2" width="1">过滤方式</th>
  1850. <th class="c3" width="1">操作</th>
  1851. </tr>
  1852. </thead>
  1853. <tbody></tbody>
  1854. </table>
  1855. </div>
  1856. <div class="silver" style="margin-top: 10px;">支持正则表达式。比如同类型的可以写在一条规则内用&quot;|&quot;隔开,&quot;ABC|DEF&quot;即为屏蔽带有ABC或者DEF的内容。<br/>属地过滤功能需要占用额外的资源,请谨慎开启</div>
  1857. `;
  1858.  
  1859. return c;
  1860. })();
  1861.  
  1862. const refresh = (() => {
  1863. const container = content.getElementsByTagName("tbody")[0];
  1864.  
  1865. const func = () => {
  1866. container.innerHTML = "";
  1867.  
  1868. Object.values(data.locations).forEach((item) => {
  1869. const tc = document.createElement("tr");
  1870.  
  1871. tc.className = `row${
  1872. (container.querySelectorAll("TR").length % 2) + 1
  1873. }`;
  1874.  
  1875. tc.innerHTML = `
  1876. <td class="c1">
  1877. <div class="filter-input-wrapper">
  1878. <input value="${item.keyword || ""}" />
  1879. </div>
  1880. </td>
  1881. <td class="c2">
  1882. <div class="filter-table-button-group">
  1883. <button>${item.filterMode || FILTER_MODE[0]}</button>
  1884. </div>
  1885. </td>
  1886. <td class="c3">
  1887. <div class="filter-table-button-group">
  1888. <button>保存</button>
  1889. <button>删除</button>
  1890. </div>
  1891. </td>
  1892. `;
  1893.  
  1894. const inputElement = tc.querySelector("INPUT");
  1895. const actions = tc.getElementsByTagName("button");
  1896.  
  1897. actions[0].onclick = () => {
  1898. actions[0].innerHTML = switchFilterMode(actions[0].innerHTML);
  1899. };
  1900.  
  1901. actions[1].onclick = () => {
  1902. if (inputElement.value) {
  1903. data.locations[item.id] = {
  1904. id: item.id,
  1905. keyword: inputElement.value,
  1906. filterMode: actions[0].innerHTML,
  1907. };
  1908.  
  1909. saveData();
  1910. refresh();
  1911. }
  1912. };
  1913.  
  1914. actions[2].onclick = () => {
  1915. if (confirm("是否确认?")) {
  1916. delete data.locations[item.id];
  1917.  
  1918. saveData();
  1919. refresh();
  1920. }
  1921. };
  1922.  
  1923. container.appendChild(tc);
  1924. });
  1925.  
  1926. {
  1927. const tc = document.createElement("tr");
  1928.  
  1929. tc.className = `row${
  1930. (container.querySelectorAll("TR").length % 2) + 1
  1931. }`;
  1932.  
  1933. tc.innerHTML = `
  1934. <td class="c1">
  1935. <div class="filter-input-wrapper">
  1936. <input value="" />
  1937. </div>
  1938. </td>
  1939. <td class="c2">
  1940. <div class="filter-table-button-group">
  1941. <button>${FILTER_MODE[0]}</button>
  1942. </div>
  1943. </td>
  1944. <td class="c3">
  1945. <div class="filter-table-button-group">
  1946. <button>添加</button>
  1947. </div>
  1948. </td>
  1949. `;
  1950.  
  1951. const inputElement = tc.querySelector("INPUT");
  1952. const actions = tc.getElementsByTagName("button");
  1953.  
  1954. actions[0].onclick = () => {
  1955. actions[0].innerHTML = switchFilterMode(actions[0].innerHTML);
  1956. };
  1957.  
  1958. actions[1].onclick = () => {
  1959. if (inputElement.value) {
  1960. addLocation(inputElement.value, actions[0].innerHTML);
  1961.  
  1962. saveData();
  1963. refresh();
  1964. }
  1965. };
  1966.  
  1967. container.appendChild(tc);
  1968. }
  1969. };
  1970.  
  1971. return func;
  1972. })();
  1973.  
  1974. return {
  1975. name: "属地",
  1976. content,
  1977. refresh,
  1978. };
  1979. })();
  1980.  
  1981. // 猎巫
  1982. const witchHuntModule = (() => {
  1983. const content = (() => {
  1984. const c = document.createElement("div");
  1985.  
  1986. c.style = "display: none";
  1987. c.innerHTML = `
  1988. <div class="filter-table-wrapper">
  1989. <table class="filter-table forumbox">
  1990. <thead>
  1991. <tr class="block_txt_c0">
  1992. <th class="c1">版面</th>
  1993. <th class="c2">标签</th>
  1994. <th class="c3" width="1">操作</th>
  1995. </tr>
  1996. </thead>
  1997. <tbody></tbody>
  1998. </table>
  1999. </div>
  2000. <div class="silver" style="margin-top: 10px;">猎巫模块需要占用额外的资源,请谨慎开启<br/>该功能为实验性功能,仅判断用户是否曾经在某个版面发言<br/>未来可能会加入发言的筛选或是屏蔽功能,也可能移除此功能</div>
  2001. `;
  2002.  
  2003. return c;
  2004. })();
  2005.  
  2006. const refresh = (() => {
  2007. const container = content.getElementsByTagName("tbody")[0];
  2008.  
  2009. const func = () => {
  2010. container.innerHTML = "";
  2011.  
  2012. Object.values(witchHunter.data).forEach((item, index) => {
  2013. const tc = document.createElement("tr");
  2014.  
  2015. tc.className = `row${
  2016. (container.querySelectorAll("TR").length % 2) + 1
  2017. }`;
  2018.  
  2019. tc.innerHTML = `
  2020. <td class="c1">
  2021. <div class="filter-input-wrapper">
  2022. <a href="/thread.php?fid=${item.fid}" class="b nobr">[${item.name}]</a>
  2023. </div>
  2024. </td>
  2025. <td class="c2">
  2026. <b class="block_txt nobr" style="background:${item.color}; color:#fff; margin: 0.1em 0.2em;">${item.label}</b>
  2027. </td>
  2028. <td class="c3">
  2029. <div class="filter-table-button-group">
  2030. <button>删除</button>
  2031. </div>
  2032. </td>
  2033. `;
  2034.  
  2035. const actions = tc.getElementsByTagName("button");
  2036.  
  2037. actions[0].onclick = () => {
  2038. if (confirm("是否确认?")) {
  2039. witchHunter.remove(item.id);
  2040.  
  2041. refresh();
  2042. }
  2043. };
  2044.  
  2045. container.appendChild(tc);
  2046. });
  2047.  
  2048. {
  2049. const tc = document.createElement("tr");
  2050.  
  2051. tc.className = `row${
  2052. (container.querySelectorAll("TR").length % 2) + 1
  2053. }`;
  2054.  
  2055. tc.innerHTML = `
  2056. <td class="c1">
  2057. <div class="filter-input-wrapper">
  2058. <input value="" placeholder="版面ID" />
  2059. </div>
  2060. </td>
  2061. <td class="c2">
  2062. <div class="filter-input-wrapper">
  2063. <input value="" />
  2064. </div>
  2065. </td>
  2066. <td class="c3">
  2067. <div class="filter-table-button-group">
  2068. <button>添加</button>
  2069. </div>
  2070. </td>
  2071. `;
  2072.  
  2073. const inputElement = tc.getElementsByTagName("INPUT");
  2074. const actions = tc.getElementsByTagName("button");
  2075.  
  2076. actions[0].onclick = async () => {
  2077. const fid = parseInt(inputElement[0].value, 10);
  2078. const tag = inputElement[1].value.trim();
  2079.  
  2080. if (isNaN(fid) || tag.length === 0) {
  2081. return;
  2082. }
  2083.  
  2084. await witchHunter.add(fid, tag);
  2085.  
  2086. refresh();
  2087. };
  2088.  
  2089. container.appendChild(tc);
  2090. }
  2091. };
  2092.  
  2093. return func;
  2094. })();
  2095.  
  2096. return {
  2097. name: "猎巫",
  2098. content,
  2099. refresh,
  2100. };
  2101. })();
  2102.  
  2103. // 通用设置
  2104. const commonModule = (() => {
  2105. const content = (() => {
  2106. const c = document.createElement("div");
  2107.  
  2108. c.style = "display: none";
  2109.  
  2110. return c;
  2111. })();
  2112.  
  2113. const refresh = (() => {
  2114. const container = content;
  2115.  
  2116. const func = () => {
  2117. container.innerHTML = "";
  2118.  
  2119. // 默认过滤方式
  2120. {
  2121. const tc = document.createElement("div");
  2122.  
  2123. tc.innerHTML += `
  2124. <div>默认过滤方式</div>
  2125. <div></div>
  2126. <div class="silver" style="margin-top: 10px;">${FILTER_TIPS}</div>
  2127. `;
  2128.  
  2129. ["标记", "遮罩", "隐藏"].forEach((item, index) => {
  2130. const ele = document.createElement("SPAN");
  2131.  
  2132. ele.innerHTML += `
  2133. <input id="s-fm-${index}" type="radio" name="filterType" ${
  2134. data.options.filterMode === item && "checked"
  2135. }>
  2136. <label for="s-fm-${index}" style="cursor: pointer;">${item}</label>
  2137. `;
  2138.  
  2139. const inp = ele.querySelector("input");
  2140.  
  2141. inp.onchange = () => {
  2142. if (inp.checked) {
  2143. data.options.filterMode = item;
  2144. saveData();
  2145. reFilter();
  2146. }
  2147. };
  2148.  
  2149. tc.querySelectorAll("div")[1].append(ele);
  2150. });
  2151.  
  2152. container.appendChild(tc);
  2153. }
  2154.  
  2155. // 小号过滤(时间)
  2156. {
  2157. const tc = document.createElement("div");
  2158.  
  2159. tc.innerHTML += `
  2160. <br/>
  2161. <div>
  2162. 隐藏注册时间小于<input value="${
  2163. (data.options.filterRegdateLimit || 0) / 86400000
  2164. }" maxLength="4" style="width: 48px;" />天的用户
  2165. <button>确认</button>
  2166. </div>
  2167. `;
  2168.  
  2169. const actions = tc.getElementsByTagName("button");
  2170.  
  2171. actions[0].onclick = () => {
  2172. const v = actions[0].previousElementSibling.value;
  2173.  
  2174. const n = Number(v) || 0;
  2175.  
  2176. data.options.filterRegdateLimit = n < 0 ? 0 : n * 86400000;
  2177.  
  2178. saveData();
  2179. reFilter();
  2180. };
  2181.  
  2182. container.appendChild(tc);
  2183. }
  2184.  
  2185. // 小号过滤(发帖数)
  2186. {
  2187. const tc = document.createElement("div");
  2188.  
  2189. tc.innerHTML += `
  2190. <br/>
  2191. <div>
  2192. 隐藏发帖数量小于<input value="${
  2193. data.options.filterPostnumLimit || 0
  2194. }" maxLength="5" style="width: 48px;" />贴的用户
  2195. <button>确认</button>
  2196. </div>
  2197. `;
  2198.  
  2199. const actions = tc.getElementsByTagName("button");
  2200.  
  2201. actions[0].onclick = () => {
  2202. const v = actions[0].previousElementSibling.value;
  2203.  
  2204. const n = Number(v) || 0;
  2205.  
  2206. data.options.filterPostnumLimit = n < 0 ? 0 : n;
  2207.  
  2208. saveData();
  2209. reFilter();
  2210. };
  2211.  
  2212. container.appendChild(tc);
  2213. }
  2214.  
  2215. // 声望过滤
  2216. {
  2217. const tc = document.createElement("div");
  2218.  
  2219. tc.innerHTML += `
  2220. <br/>
  2221. <div>
  2222. 隐藏版面声望低于<input value="${
  2223. data.options.filterReputationLimit || ""
  2224. }" maxLength="5" style="width: 48px;" />点的用户
  2225. <button>确认</button>
  2226. </div>
  2227. `;
  2228.  
  2229. const actions = tc.getElementsByTagName("button");
  2230.  
  2231. actions[0].onclick = () => {
  2232. const v = actions[0].previousElementSibling.value;
  2233.  
  2234. const n = Number(v);
  2235.  
  2236. data.options.filterReputationLimit = n;
  2237.  
  2238. saveData();
  2239. reFilter();
  2240. };
  2241.  
  2242. container.appendChild(tc);
  2243. }
  2244.  
  2245. // 删除没有标记的用户
  2246. {
  2247. const tc = document.createElement("div");
  2248.  
  2249. tc.innerHTML += `
  2250. <br/>
  2251. <div>
  2252. <button>删除没有标记的用户</button>
  2253. </div>
  2254. `;
  2255.  
  2256. const actions = tc.getElementsByTagName("button");
  2257.  
  2258. actions[0].onclick = () => {
  2259. if (confirm("是否确认?")) {
  2260. Object.values(data.users).forEach((item) => {
  2261. if (item.tags.length === 0) {
  2262. delete data.users[item.id];
  2263. }
  2264. });
  2265.  
  2266. saveData();
  2267. reFilter();
  2268. }
  2269. };
  2270.  
  2271. container.appendChild(tc);
  2272. }
  2273.  
  2274. // 删除没有用户的标记
  2275. {
  2276. const tc = document.createElement("div");
  2277.  
  2278. tc.innerHTML += `
  2279. <br/>
  2280. <div>
  2281. <button>删除没有用户的标记</button>
  2282. </div>
  2283. `;
  2284.  
  2285. const actions = tc.getElementsByTagName("button");
  2286.  
  2287. actions[0].onclick = () => {
  2288. if (confirm("是否确认?")) {
  2289. Object.values(data.tags).forEach((item) => {
  2290. if (
  2291. Object.values(data.users).filter((user) =>
  2292. user.tags.find((tag) => tag === item.id)
  2293. ).length === 0
  2294. ) {
  2295. delete data.tags[item.id];
  2296. }
  2297. });
  2298.  
  2299. saveData();
  2300. reFilter();
  2301. }
  2302. };
  2303.  
  2304. container.appendChild(tc);
  2305. }
  2306. };
  2307.  
  2308. return func;
  2309. })();
  2310.  
  2311. return {
  2312. name: "通用设置",
  2313. content,
  2314. refresh,
  2315. };
  2316. })();
  2317.  
  2318. u.addModule(userModule).toggle();
  2319. u.addModule(tagModule);
  2320. u.addModule(keywordModule);
  2321. u.addModule(locationModule);
  2322. u.addModule(witchHuntModule);
  2323. u.addModule(commonModule);
  2324.  
  2325. // 增加菜单项
  2326. (() => {
  2327. const title = "过滤设置";
  2328.  
  2329. let window;
  2330.  
  2331. const container = document.createElement("DIV");
  2332.  
  2333. container.className = `td`;
  2334. container.innerHTML = `<a class="mmdefault" href="javascript: void(0);" style="white-space: nowrap;">屏蔽</a>`;
  2335.  
  2336. const content = container.querySelector("A");
  2337.  
  2338. const anchor = document.querySelector("#mainmenu .td:last-child");
  2339.  
  2340. anchor.before(container);
  2341.  
  2342. content.onclick = () => {
  2343. if (window === undefined) {
  2344. window = n.createCommmonWindow();
  2345. }
  2346.  
  2347. window._.addContent(null);
  2348. window._.addTitle(title);
  2349. window._.addContent(u.content);
  2350. window._.show();
  2351. };
  2352. })();
  2353.  
  2354. // 执行过滤
  2355. (() => {
  2356. const hookFunction = (object, functionName, callback) => {
  2357. ((originalFunction) => {
  2358. object[functionName] = function () {
  2359. const returnValue = originalFunction.apply(this, arguments);
  2360.  
  2361. callback.apply(this, [returnValue, originalFunction, arguments]);
  2362.  
  2363. return returnValue;
  2364. };
  2365. })(object[functionName]);
  2366. };
  2367.  
  2368. const initialized = {
  2369. topicArg: false,
  2370. postArg: false,
  2371. };
  2372.  
  2373. hookFunction(n, "eval", () => {
  2374. if (Object.values(initialized).findIndex((item) => item === false) < 0) {
  2375. return;
  2376. }
  2377.  
  2378. if (n.topicArg && initialized.topicArg === false) {
  2379. hookFunction(n.topicArg, "add", reFilter);
  2380.  
  2381. initialized.topicArg = true;
  2382. }
  2383.  
  2384. if (n.postArg && initialized.postArg === false) {
  2385. hookFunction(n.postArg, "proc", reFilter);
  2386.  
  2387. initialized.postArg = true;
  2388. }
  2389. });
  2390.  
  2391. reFilter();
  2392. })();
  2393. })(commonui, __CURRENT_UID);