// ==UserScript== // @name NGA 帖子过滤器 // @namespace https://greasyfork.org/zh-CN/scripts/28659-nga-%E5%B8%96%E5%AD%90%E8%BF%87%E6%BB%A4%E5%99%A8 // @version 0.0.1.1 // @description 超简易NGA论坛帖子过滤器 // @author F1re // @include /^https?://(bbs\.ngacn\.cc|nga\.178\.com|bbs\.nga\.cn)/.+/ // @grant none // @require http://cdn.bootcss.com/jquery/3.2.1/jquery.min.js // @downloadURL none // ==/UserScript== var $Q = jQuery.noConflict(); (function() { // textbox for regular expression var regex_textbox=document.createElement('input'); regex_textbox.type='textarea'; regex_textbox.rows='2'; regex_textbox.cols='50'; regex_textbox.value='.+萌新|监狱塔.+'; // filter button var filter_btn=document.createElement('input'); filter_btn.type='button'; filter_btn.value='过滤'; filter_btn.onclick = filter_handler; var box = $Q('table#topicrows.forumbox')[0]; box.parentNode.insertBefore(regex_textbox,box); box.parentNode.insertBefore(filter_btn,box); function filter_handler(){ if(this.value=="还原"){ this.value="过滤"; showall(); } else { this.value="还原"; filter(); } } function showall(){ var rows = $Q('.topicrow*'); for(i = 0; i < rows.length; i++) { rows[i].style.display = ''; } } function filter(){ var regex = new RegExp(regex_textbox.value); var rows = $Q('.topicrow*'); for(i = 0; i < rows.length; i++) { var row = rows[i]; // filter posts matched by regex, excluding elevated posts if(row.children[1].children[1].className=='topic' && regex.test(row.childNodes[3].innerText)) { row.style.display = 'none'; } else { row.style.display = ''; } } } })();