Ahab / Fourm user remove (with added whole fac post removal)

// ==UserScript==
// @name            Fourm user remove (with added whole fac post removal)
// @description     Hide posts/threads from selected users/factions
// @include         *torn.com/forums.php*
// @license         MIT
// @author          Ahab [1735214]
// @version         1.1
// @license         MIT
// @updateURL       https://openuserjs.org/meta/Ahab/Fourm_user_remove_(with_added_whole_fac_post_removal).meta.js
// @grant           GM.xmlHttpRequest
// ==/UserScript==

var d = new Date();
var apiKey = "";
var blockedFaction = [];
var blockedUser = [];

function check(blockedFaction, apiKey, d){
    if(blockedFaction.length > 0 && localStorage.factionmembers === undefined){
        apicall(apiKey, blockedFaction, d);
    }else if(blockedFaction.length > 0 && Object.keys(JSON.parse(localStorage.factionmembers)) !== String(d.getDate())){
        apicall(apiKey, blockedFaction, d);
    }
}

function apicall(key, Faction, d){
    for (var i = 0; i < Faction.length; i++){
        GM.xmlHttpRequest({
            method: "GET",
            url: "https://api.torn.com/faction/"+Faction[i]+"?selections=basic&key="+key,
            onload: function(response) {
                var parseResponse = JSON.parse(response.responseText);
                var day = String(d.getDate());
                var save = {};
                save[day] = Object.keys(parseResponse['members']);
                localStorage.factionmembers = JSON.stringify(save);
            }
        });
}}

function test(blockedUser, apiKey, blockedFaction, d){
    if (window.location.pathname === "/forums.php") {
        if(blockedFaction.length === 0){
            localStorage.removeItem("factionmembers");
        }else{
            check(blockedFaction,apiKey,d);
        };
        var fromStorage = JSON.parse(localStorage.factionmembers);
        var members = fromStorage[String(d.getDate())];
        for(var g = 0; g < members.length; g++){
            blockedUser.push(parseInt(members[g]));
        }
        var observerTarget = document.querySelector("#sidebarroot");
        var observerConfig = { attributes: true, childList: true, characterData: true, subtree: true };
        var observer = new MutationObserver(function(mutations) {
            if ($('li[class^=last-post]').length > 0 || $('li[class^=last-poster]').length > 0 || $('div[class^=poster-wrap]').length > 0) {
                for (var i = 0; i < blockedUser.length; i++){
                    //$("div[class^='forums-thread-wrap'] a[href$='profiles.php?XID="+ blocked[i] +"']").parent().parent().parent().remove(); // Safer post removal
                    $("div[class^='forums-thread-wrap'] a[href$='profiles.php?XID="+ blockedUser[i] +"']").closest('li').remove(); // Nuke posts
                    $("li[class^='starter'] a[href$='profiles.php?XID="+ blockedUser[i] +"']").parent().parent().parent().parent().remove(); // Threads
                    $("li[class^='last-post'] a[href$='profiles.php?XID="+ blockedUser[i] +"']").children().remove(); // Last post
                    $("div[class^='forums-thread-wrap'] a[href$='factions.php?step=profile&ID="+ blockedUser[i] +"']").parent().parent().parent().parent().remove();
                }
            }
        });
        observer.observe(observerTarget, observerConfig);
    }
}

test(blockedUser, apiKey, blockedFaction, d);