reabble 过滤文章

过滤文章

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         reabble 过滤文章
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  过滤文章
// @author       yb
// @match        https://reabble.com/app*
// @icon         https://www.google.com/s2/favicons?domain=reabble.com
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    function main(){
        for (let i of document.querySelectorAll('article')){
            i.style.display= /^.+赞同了回答: .+$/.test(i.textContent)?'none':''
        }

        let btn=document.createElement('button');
        (function bthHidden(){
            btn.id="hiddenBtn"
            btn.data=true
            btn.value="隐藏"
            let btnDiv= document.querySelector('#app-root > div > div:nth-child(2) > nav > div')
            btnDiv.append(btn)
            btn.onclick=()=>{
                btn.data=!btn.data
                for (let child of articleList.children){
                    change(child,btn.data)
                }
            }

        })()

        function change(element,bool){
            let v=bool?'none':''
            element.style.display= /^.+赞同了回答: .+$/.test(element.lastChild.textContent)?v:''
            //console.log(element.lastChild.textContent, /^.+赞同了回答: .+$/.test(element.lastChild.textContent))
        }
        let articleList=document.querySelector('#app-root > div > div:nth-child(2) > div:nth-child(2) div div');
        let mutationObserver = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                if (mutation.addedNodes.length>0){
                    change(mutation.addedNodes[0],btn.data)
                }
            });
        });
        mutationObserver.observe(articleList, {
            childList: true,
            subtree: false,
        });
    }

    setTimeout(main, 6000 )

})();