ninalanyon / Similar Worlds: remove vaccine

// ==UserScript==
// @name        Similar Worlds: remove vaccine
// @namespace   ninalanyon@hotmail.com
// @description Remove posts that mention vaccine and related words
// @include     https://similarworlds.com/
// @include     https://similarworlds.com/posts
// @include     https://similarworlds.com/posts-circle
// @include     https://similarworlds.com/posts-groups
// @include     https://similarworlds.com/top
// @updateURL   https://openuserjs.org/meta/ninalanyon/Similar_Worlds_remove_vaccine.meta.js
// @downloadURL https://openuserjs.org/install/ninalanyon/Similar_Worlds_remove_vaccine.user.js
// @version     0.2
// @grant       none
// @license MIT
// @copyright 2021, ninalanyon (https://openuserjs.org/users/ninalanyon)
// ==/UserScript==

/*

Adapted from PalinHider by pyro (http://www.metafilter.com/user/84673)

Removes links and articles from the main page that match a certain regex.

Feel free to adapt it how you like.

*/

var matcher = new RegExp("vaccine|vaccination|antivax|vaxxer", "i")


function hideLinks() {
    "use strict";
    var links = document.getElementsByTagName("a"),
        keyVar,
        thisLink,
        linkText,
        linkHref;
   
    try {
        for (keyVar in links) {
            thisLink = links[keyVar];
            if (thisLink) {
                linkText = thisLink.innerHTML;
                linkHref = thisLink.href;
                if (linkText &&
                    ((linkHref.search(matcher) !== -1) ||
                     (linkText.search(matcher) !== -1))) {
                    //alert('match href ' + linkHref + ' it ' + linkText);
                    thisLink.parentNode.style.display = "none";
                    thisLink.parentNode.visibility = "hidden";
                }
            }
        }
    } catch (ex) {
        alert('caught ' + ex.toString());
    }
}


function hideHeadings() {
    "use strict";
    var elements = document.getElementsByTagName("h2"),
        element,
        text,
        i;
    try {
        for (i = 0; i< elements.length; i++) {
             element = elements[i];
             if (element) {
                 //alert('e ' + element.toString());
                 text = element.textContent;
                 //alert('t ' + text);
                 if (typeof text !== 'undefined') {
                     //alert('t ' + text + ' m: ' + text.search(matcher));
                     if (text.search(matcher) !== -1) {
                         //alert('match ' + text);
                         element.parentNode.style.display = "none";
                         element.parentNode.visibility = "hidden";
                     }
                 }
             }
         }        
    } catch (ex) {
        alert('b ex: ' + ex.toString());
    }
}
function hideArticles(c) {
    "use strict";
    var elements = document.getElementsByClassName(c),
        element,
        text,
        i;
    try {
        for (i = 0; i< elements.length; i++) {
             element = elements[i];
             if (element) {
                 text = element.textContent;
                 if (typeof text !== 'undefined') {
                     if (text.search(matcher) !== -1) {
                         element.style.display = "none";
                         element.visibility = "hidden";
                     }
                 }
             }
         }        
    } catch (ex) {
        alert('b ex: ' + ex.toString());
    }
}

function hideClass(c) {

    var elements = document.getElementsByClassName(c),
        element,
        i;

    for (i = 0; i< elements.length; i++) {
        element = elements[i];
        element.remove();
    }
}

function hide() {
    hideArticles("pstbx-main");
    hideArticles("rctrpl-element");
    //hideLinks();
    //hideHeadings();
    //hideClass("fff-hottest-list");
}

try {
    hide();
    window.setInterval(hide, 10000);
} catch (ex) {
    alert('a ex: ' + ex.toString());
}