Greasy Fork镜像 支持简体中文。

NGA艾泽拉斯国家地理 - 主题过滤器

根据关键字过滤NGA论坛主题

  1. // ==UserScript==
  2. // @name NGA艾泽拉斯国家地理 - 主题过滤器
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description 根据关键字过滤NGA论坛主题
  6. // @author 艾德帕拉丁/斩梦人天天
  7. // @match *://bbs.nga.cn/*
  8. // @match *://nga.178.com/*
  9. // @match *://ngabbs.com/*
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=nga.cn
  11. // @require https://openuserjs.org/src/libs/sizzle/GM_config.js
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // @grant GM.getValue
  15. // @grant GM.setValue
  16. // @license MIT
  17. // ==/UserScript==
  18.  
  19. (function() {
  20. 'use strict';
  21. let defaultKeywords = '';
  22. let keywords = '';
  23. let gmc = new GM_config({
  24. 'id': 'MyConfig',
  25. 'title': '艾泽拉斯国家地理 - 主题过滤器 - 设置',
  26. 'fields': {
  27. 'keywords': {
  28. 'label': '过滤关键字',
  29. 'type': 'text',
  30. 'default': defaultKeywords
  31. }
  32. },
  33. 'css': '#MyConfig_wrapper {text-align:center;} #MyConfig_field_keywords{width:30em} #MyConfig_buttons_holder{text-align:center}',
  34. 'events':{
  35. 'init': function () {
  36. keywords = this.get('keywords');
  37. handleFiltration();
  38. setupSettingButton();
  39. },
  40. 'save': function () {
  41. keywords = this.get('keywords');
  42. handleFiltration();
  43. location.reload();
  44. }
  45. }
  46. });
  47. let arrayKeywords = null;
  48. let topicTable = null;
  49. let topicLists = null;
  50. let settingButtonContainer = null;
  51. let settingButtonTemplate = null;
  52. let settingButton = null;
  53. let intervalTimer = null;
  54.  
  55. function resetup(){
  56. arrayKeywords = convertKeywordsToRegex(keywords);
  57. topicTable = document.querySelector('#topicrows');
  58. if (topicTable) {
  59. topicLists = Array.from(topicTable.tBodies);
  60. }
  61. settingButtonContainer = document.querySelector('#m_pbtntop .right_ table tr');
  62. if (settingButtonContainer){
  63. settingButtonTemplate = settingButtonContainer.querySelector('td')
  64. }
  65. }
  66. function isMatched(topicName){
  67. let ret = false
  68. arrayKeywords.forEach(function(reg, index, arr){
  69. if (topicName.match(reg)) {
  70. console.log('matched!', topicName)
  71. ret = true
  72. }
  73. });
  74. return ret
  75. }
  76. function convertKeywordsToRegex(){
  77. keywords = keywords.replaceAll(' ','');
  78. let ret = null;
  79. if (keywords) {
  80. ret = [];
  81. let list = keywords.replaceAll(',',',').split(',');
  82. list.forEach(function(item, index, arr){
  83. let reg = new RegExp(item, 'g');
  84. ret.push(reg)
  85. })
  86. }
  87. return ret;
  88. }
  89. function setupSettingButton(){
  90. if (settingButtonTemplate && topicLists) {
  91. settingButton = settingButtonTemplate.cloneNode();
  92. settingButton.innerHTML = settingButtonTemplate.innerHTML;
  93.  
  94. let link = settingButton.querySelector('a');
  95. let linkText = link.querySelector('span');
  96. link.setAttribute('href', 'javascript:void 0');
  97. link.onclick = function(){gmc.open()};
  98. if (linkText) {
  99. linkText.innerText = '过滤设置';
  100. settingButtonContainer.insertBefore(settingButton, settingButtonTemplate);
  101. }else{
  102. settingButton = null;
  103. }
  104. }
  105. }
  106. function handleFiltration(){
  107. resetup()
  108. arrayKeywords = convertKeywordsToRegex(keywords);
  109. if (arrayKeywords && topicTable && topicLists && settingButtonTemplate) {
  110. topicLists.forEach(function(tbody, index, arr){
  111. let topicName = tbody.querySelector('.c2 a.topic').innerText;
  112. if (isMatched(topicName)){
  113. topicTable.removeChild(tbody)
  114. }
  115. });
  116. topicLists = Array.from(topicTable.tBodies);
  117. let rowOneMark = true;
  118. topicLists.forEach(function(tbody, index, arr){
  119. let tr = tbody.querySelector('tr')
  120. tr.classList.remove('row1');
  121. tr.classList.remove('row2');
  122. if (rowOneMark) {
  123. tr.classList.add('row1');
  124. }else{
  125. tr.classList.add('row2');
  126. }
  127. rowOneMark = !rowOneMark;
  128. });
  129. }
  130. }
  131. function checkPageFresh(){
  132. if (settingButton != document.querySelector('#m_pbtntop .right_ table tr td')){
  133. handleFiltration();
  134. setupSettingButton();
  135. }
  136. }
  137. clearInterval(intervalTimer)
  138. intervalTimer = setInterval(function(){
  139. checkPageFresh()
  140. }, 50)
  141.  
  142. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址