隱藏巴哈姆特原鐵絕看板內鬼資訊

以眼不見為淨的方式隱藏巴哈姆特《原神》、《崩壞:星穹鐵道》和《絕區零》看板內的內鬼相關文章

Установить этот скрипт?
Рекомендуемый автором скрипт

Вам также может понравится 巴哈黑名單、關鍵詞、字數過少隱藏顯示.

Установить этот скрипт
  1. // ==UserScript==
  2. // @name 隱藏巴哈姆特原鐵絕看板內鬼資訊
  3. // @namespace http://wysalan.com/
  4. // @version 0.9.50
  5. // @description 以眼不見為淨的方式隱藏巴哈姆特《原神》、《崩壞:星穹鐵道》和《絕區零》看板內的內鬼相關文章
  6. // @author Wysalan
  7. // @match https://forum.gamer.com.tw/B.php?bsn=36730*
  8. // @match https://forum.gamer.com.tw/B.php?bsn=72822*
  9. // @match https://forum.gamer.com.tw/B.php?bsn=74860*
  10. // @match https://forum.gamer.com.tw/C.php?bsn=36730
  11. // @match https://forum.gamer.com.tw/C.php?bsn=72822*
  12. // @match https://forum.gamer.com.tw/C.php?bsn=74860*
  13. // @match https://forum.gamer.com.tw/B.php?page=*
  14. // @match https://forum.gamer.com.tw/C.php?page=*
  15. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  16. // @grant GM_setValue
  17. // @grant GM_getValue
  18. // @grant GM_registerMenuCommand
  19. // @run-at document-body
  20. // @license MIT
  21. // ==/UserScript==
  22.  
  23. (function() {
  24. "use strict";
  25. var status = false;
  26. let url = document.URL;
  27.  
  28. // --------強制模式-----------
  29. let forceMode = GM_getValue("forceMode", false);
  30.  
  31. console.log("GM_getValue: " + GM_getValue("forceMode"));
  32.  
  33. // ------內鬼分類編號---------
  34. // 編號說明:從零開始,由上至下、從左到右
  35. let subForumIndex_Genshin = 1;
  36. let subForumIndex_StarRail = 12;
  37. let subForumIndex_ZZZ = 1;
  38.  
  39. let forumID_Genshin = "36730";
  40. let forumID_StarRail = "72822";
  41. let forumID_ZZZ = "74860";
  42.  
  43. waitForElementObserved('BH-menuE', createIndicator);
  44. waitForElementObserved('b-list', removePost);
  45. hidePostContent();
  46.  
  47. // 等待 elementClassName 元素出現後立刻執行 functionName 函數
  48. function waitForElementObserved(elementClassName, functionName)
  49. {
  50. let callback = function(mutationsList) {
  51. if (document.getElementsByClassName(elementClassName).length > 0) {
  52. functionName();
  53. this.disconnect();
  54. }
  55. };
  56. let observer = new MutationObserver(callback);
  57. let targetNode = document.documentElement;
  58. let config = { attributes: true, childList: true, subtree: true };
  59. observer.observe(targetNode, config);
  60. }
  61.  
  62. // 建立指示器
  63. function createIndicator()
  64. {
  65. // Get Bahamut menu bar
  66. const menuBar = document.querySelector('.BH-menuE');
  67.  
  68. // Create indicator element
  69. const indicator = document.createElement('li');
  70. const indicatorContent = document.createElement('a');
  71. indicatorContent.className = "indicator";
  72. indicatorContent.style.fontWeight = "bold";
  73.  
  74. // Create advance setting element
  75. const advanceSetting = document.createElement('li');
  76. const advanceSettingContent = document.createElement('a');
  77. advanceSettingContent.className = "advanceSetting";
  78. advanceSettingContent.style.fontWeight = "bold";
  79.  
  80. if(status)
  81. {
  82. indicatorContent.innerHTML = "防內鬼已啟用";
  83. indicatorContent.onclick = () => hidePostSwitchToggle();
  84. advanceSettingContent.innerHTML = "進階設定";
  85. advanceSettingContent.onclick = () => advanceSettingUI();
  86. } else {
  87. indicatorContent.innerHTML = "防內鬼已啟用(範圍外)";
  88. advanceSettingContent.innerHTML = "進階設定";
  89. advanceSettingContent.onclick = () => advanceSettingUI();
  90. }
  91.  
  92. if(GM_getValue("forceMode"))
  93. {
  94. hideCategoryTab();
  95. advanceSettingContent.innerHTML = ".";
  96. advanceSetting.appendChild(advanceSettingContent);
  97. menuBar.appendChild(advanceSetting);
  98. }
  99. else
  100. {
  101. indicator.appendChild(indicatorContent);
  102. advanceSetting.appendChild(advanceSettingContent);
  103. menuBar.appendChild(indicator);
  104. menuBar.appendChild(advanceSetting);
  105. }
  106. }
  107.  
  108. // 隱藏指示器
  109. function hidePostSwitchToggle()
  110. {
  111. const postListArea = document.querySelector('.b-list');
  112. const indicator = document.querySelector('.indicator');
  113. if(status)
  114. {
  115. postListArea.style.display = postListArea.style.display === "none" ? "block" : "none";
  116. indicator.innerHTML = indicator.innerHTML === "防內鬼已啟用" ? "防內鬼暫時停用" : "防內鬼已啟用";
  117. }
  118. }
  119.  
  120. // 移除文章列表內所有文章
  121. function removePost()
  122. {
  123. if(urlChecker("PostList", url))
  124. {
  125. const postListArea = document.querySelector('.b-list');
  126. postListArea.style.display = "none";
  127. status = true;
  128. }
  129. }
  130.  
  131. // 隱藏文章內容
  132. function hidePostContent()
  133. {
  134. if (urlChecker("PostContent", url))
  135. {
  136. status = true;
  137. warnWindowGenerate();
  138. }
  139. }
  140.  
  141. // 隱藏子板入口
  142. function hideCategoryTab()
  143. {
  144. // test();
  145. if(locationChecker("StarRail", url))
  146. {
  147. let tab = document.querySelectorAll('.b-tags__item')[subForumIndex_StarRail].remove();
  148. }
  149. else if(locationChecker("Genshin", url))
  150. {
  151. let tab = document.querySelectorAll('.b-tags__item')[subForumIndex_Genshin].remove();
  152. }
  153. else if(locationChecker("ZZZ", url))
  154. {
  155. let tab = document.querySelectorAll('.b-tags__item')[subForumIndex_ZZZ].remove();
  156. }
  157. }
  158.  
  159. // 網址檢查(偵測是否位於文章列表或文章內)
  160. function urlChecker(checkType, url)
  161. {
  162. const inGenshinForum = url.includes("&subbsn=10");
  163. const inStarRailForum = url.includes("&subbsn=8");
  164. const inZZZForum = url.includes("&subbsn=3");
  165. const inPLFirstPage = url.includes("B.php?bsn=");
  166. const inPLAnotherPages = url.includes("B.php?page=");
  167. const inPostPage = url.includes("C");
  168.  
  169. if(checkType == "PostList")
  170. {
  171. return (inPLFirstPage || inPLAnotherPages) && (inGenshinForum || inStarRailForum || inZZZForum);
  172.  
  173. }
  174. else if(checkType == "PostContent")
  175. {
  176. return inPostPage && (inGenshinForum || inStarRailForum || inZZZForum);
  177. }
  178. }
  179.  
  180. // 網址檢查(偵測是否位於原神或崩鐵看板)
  181. function locationChecker(GameName, url)
  182. {
  183. const inGenshinForum = url.includes(forumID_Genshin);
  184. const inStarRailForum = url.includes(forumID_StarRail);
  185. const inZZZForum = url.includes(forumID_ZZZ);
  186.  
  187. if(GameName == "Genshin")
  188. {
  189. return inGenshinForum;
  190. }
  191. else if(GameName == "StarRail")
  192. {
  193. return inStarRailForum;
  194. }
  195. else if(GameName == "ZZZ")
  196. {
  197. return inZZZForum;
  198. }
  199. }
  200.  
  201. // 建立警告頁面
  202. function warnWindowGenerate()
  203. {
  204. // 警告:底部背景
  205. const div = document.createElement('div');
  206. div.className = "leakContentAlert";
  207. div.style.position = "fixed";
  208. div.style.top = 0;
  209. div.style.right = 0;
  210. div.style.width = "100%";
  211. div.style.height = "100%";
  212. div.style.zIndex = 9999;
  213. div.style.backgroundColor = "#ffffff";
  214. document.body.appendChild(div);
  215.  
  216. // 警告:內容區域
  217. const contentDiv = document.createElement('div');
  218. contentDiv.style.position = "absolute";
  219. contentDiv.style.top = "50%";
  220. contentDiv.style.left = "50%";
  221. contentDiv.style.transform = "translate(-50%, -50%)";
  222. contentDiv.style.fontSize = "24px";
  223. div.appendChild(contentDiv);
  224.  
  225. // 警告:文字區域
  226. const contentText = document.createElement("p");
  227. contentText.style.lineHeight = "1.5";
  228. if(forceMode)
  229. {
  230. contentText.innerHTML = "此文章含有<b>內鬼</b>資訊<br>選擇「返回上一頁」離開或自行關閉此分頁。";
  231. } else {
  232. contentText.innerHTML = "你即將要瀏覽<b>內鬼</b>分類裡的文章<br>如要繼續請選擇「仍要閱讀」<br>否則選擇「返回上一頁」離開或自行關閉此分頁。";
  233. }
  234.  
  235. const returnButton = document.createElement("button");
  236. const allowButton = document.createElement("button");
  237.  
  238. // Style for returnButton
  239. returnButton.style.width = "100px";
  240. returnButton.style.height = "40px";
  241. returnButton.style.margin = "10px";
  242. returnButton.style.backgroundColor = "#04AA6D";
  243. returnButton.textContent = "返回上一頁";
  244.  
  245. // Evnet for returnButton
  246. returnButton.addEventListener("click", function() {
  247. window.history.back();
  248. });
  249.  
  250. // Style for allowButton
  251. allowButton.style.width = "100px";
  252. allowButton.style.height = "40px";
  253. allowButton.style.margin = "10px";
  254. allowButton.style.backgroundColor = "#ff8787";
  255. allowButton.textContent = "仍要閱讀";
  256.  
  257. // Evnet for allowButton
  258. allowButton.addEventListener("click", function() {
  259. let warnWindow = document.querySelector('.leakContentAlert');
  260. if(warnWindow)
  261. {
  262. if(window.confirm("確定要瀏覽嗎?這次允許之後還會出現提示。"))
  263. {
  264. warnWindow.style.display = "none";
  265. }
  266. }
  267. });
  268.  
  269. // 附加在 contentDiv 底下
  270. contentDiv.appendChild(contentText);
  271. contentDiv.appendChild(returnButton);
  272.  
  273. // 警告:按鈕
  274. if(!forceMode)
  275. {
  276. contentDiv.appendChild(allowButton);
  277. }
  278.  
  279. status = true;
  280. }
  281.  
  282. // 建立進階設定介面
  283. function advanceSettingUI()
  284. {
  285. // 進階設定:背景
  286. const div = document.createElement('div');
  287. div.id = "advanceSettingUI";
  288. div.style.position = "fixed";
  289. div.style.top = "5%";
  290. div.style.right = "5%";
  291. div.style.width = "20%";
  292. div.style.height = "20%";
  293. div.style.zIndex = "9999";
  294. div.style.backgroundColor = "gray";
  295. div.style.border = "3px solid black";
  296. div.style.borderRadius = "10px";
  297. document.body.appendChild(div);
  298.  
  299. // 進階設定:內容區域
  300. const contentDiv = document.createElement('div');
  301. contentDiv.style.position = "absolute";
  302. contentDiv.style.top = "10%";
  303. contentDiv.style.left = "10%";
  304. contentDiv.style.transform = "translate(-10%, -10%)";
  305. contentDiv.style.fontSize = "24px";
  306. div.appendChild(contentDiv);
  307.  
  308. // 進階設定:文字區域
  309. const contentText = document.createElement("p");
  310. contentText.style.lineHeight = "1.5";
  311. if(forceMode)
  312. {
  313. contentText.innerHTML = "「強制模式」開關";
  314. } else {
  315. contentText.innerHTML = "「強制模式」開關";
  316. }
  317.  
  318. // 進階設定:Checkbox
  319. const forceModeCheckbox = document.createElement("input");
  320. forceModeCheckbox.id = "forceModeStatus";
  321. forceModeCheckbox.type = "checkbox";
  322. // forceModeCheckbox.checked = true;
  323. forceModeCheckbox.checked = GM_getValue("forceMode");
  324.  
  325. // Style for saveButton
  326. const saveButton = document.createElement("button");
  327. saveButton.style.width = "50px";
  328. saveButton.style.height = "30px";
  329. saveButton.style.margin = "10px";
  330. saveButton.style.backgroundColor = "#04AA6D";
  331. saveButton.textContent = "儲存";
  332.  
  333. // Style for cancelButton
  334. const cancelButton = document.createElement("button");
  335. cancelButton.style.width = "50px";
  336. cancelButton.style.height = "30px";
  337. cancelButton.style.margin = "10px";
  338. cancelButton.style.backgroundColor = "#ff8787";
  339. cancelButton.textContent = "取消";
  340.  
  341. saveButton.addEventListener("click", () => advanceSettingSaveFunction(document.getElementById("forceModeStatus").checked));
  342. cancelButton.addEventListener("click", () => removeElement("advanceSettingUI"));
  343.  
  344. contentDiv.appendChild(contentText);
  345. contentDiv.appendChild(forceModeCheckbox);
  346. contentDiv.appendChild(saveButton);
  347. contentDiv.appendChild(cancelButton);
  348. }
  349.  
  350. function advanceSettingSaveFunction(status)
  351. {
  352. GM_setValue("forceMode", status);
  353. removeElement("advanceSettingUI");
  354. window.location.reload();
  355. }
  356.  
  357. function removeElement(elementID)
  358. {
  359. let element = document.getElementById(elementID);
  360. if(element)
  361. {
  362. let parentElement = element.parentNode;
  363. parentElement.removeChild(element);
  364. }
  365. }
  366. })();