Flashback hide

Hide specific users on Flashback

Version vom 12.05.2021. Aktuellste Version

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Flashback hide
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Hide specific users on Flashback
// @author       Andreas Mustola
// @match        https://www.flashback.org/*
// @icon         https://www.google.com/s2/favicons?domain=flashback.org
// @grant        none
// ==/UserScript==

// Permanent hide
// Ex: ["name1","name2","name3"];
var permanent_hide_array=[];

// Dynamic hide array, from hide clicks
var hide_array;
// Check if got saved cookie
var json_str = readCookie('hide_array');
if (json_str!=null)
{
    // parse json
    hide_array=JSON.parse(json_str);
}
else
{
    // No cookie, use permanent array
    hide_array=permanent_hide_array;
}

// Check for usernames
var p = document.getElementsByClassName('post-user-username');
var n;
var found_in_array=false;
var name_="";
var mybutton;
var ii;
// Check if on main page
if (p.length>0)
{
    // On subject page
    for (var i=p.length; --i>=0;)
    {
        n = p[i];
        found_in_array=false;
        name_="";
        //while(n.className.split(" ").indexOf(hide)==-1) {
        //    n = n.parentNode;
        //}
        if (n)
        {
            // Get name
            name_=n.innerHTML.trim();
            for(ii=0;ii < hide_array.length;ii++)
            {
                //if (n.innerHTML.indexOf(hide_array[ii])>-1)
                if (name_==hide_array[ii])
                {
                    found_in_array=true;
                    break;
                }
            }
            if (found_in_array==true)
            {
                // Create show button
                mybutton=Create_Button("[Show " + name_ + "]",null,n.parentNode.parentNode.parentNode.parentNode.parentNode.previousElementSibling);
                // Add name in button
                mybutton.setAttribute("poster_name", name_);
                // Remove name from array if clicked
                mybutton.onclick=function(){RemoveFromHideArray(this.getAttribute("poster_name"))};
                // Add line break
                Create_Element("BR",n.parentNode.parentNode.parentNode.parentNode.parentNode.previousElementSibling);
                //n.parentNode.removeChild(n.nextElementSibling);
                n.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.removeChild(n.parentNode.parentNode.parentNode.parentNode.parentNode);
            }
            else
            {
                // Create hide button
                mybutton=Create_Button("[Hide " + name_ + "]",null,n.parentNode.parentNode.parentNode.parentNode.parentNode.previousElementSibling);
                // Add name in button
                mybutton.setAttribute("poster_name", name_);
                // Add name to array if clicked
                mybutton.onclick=function(){AddToHideArray(this.getAttribute("poster_name"))};
                // Add line break
                Create_Element("BR",n.parentNode.parentNode.parentNode.parentNode.parentNode.previousElementSibling);
            }
        }
    }
}
else
{
    // On main page
    p = document.getElementsByClassName('thread-poster');
    // On subject page
    for (i=p.length; --i>=0;)
    {
        n = p[i];
        found_in_array=false;
        name_="";
        //while(n.className.split(" ").indexOf(hide)==-1) {
        //    n = n.parentNode;
        //}
        if (n)
        {
            // Get name
            name_=n.childNodes[1].innerHTML.trim();
            for(ii=0;ii < hide_array.length;ii++)
            {
                //if (n.innerHTML.indexOf(hide_array[ii])>-1)
                if (name_==hide_array[ii])
                {
                    found_in_array=true;
                    break;
                }
            }
            if (found_in_array==true)
            {
                // Create show button
                mybutton=Create_Button("[Show " + name_ + "]",null,n.parentNode.previousElementSibling.parentNode);
                // Add name in button
                mybutton.setAttribute("poster_name", name_);
                // Remove name from array if clicked
                mybutton.onclick=function(){RemoveFromHideArray(this.getAttribute("poster_name"))};
                var post_data_array=n.parentNode.previousElementSibling.parentNode.childNodes;
                var number_to_remove=post_data_array.length-1;
                console.log(post_data_array);
                for(ii=0;ii < number_to_remove;ii++)
                {
                    post_data_array[0].parentNode.removeChild(post_data_array[0]);
                }
            }
            else
            {
                // Create hide button
                mybutton=Create_Button("[Hide " + name_ + "]",null,n.parentNode.previousElementSibling.parentNode);
                // Add name in button
                mybutton.setAttribute("poster_name", name_);
                // Add name to array if clicked
                mybutton.onclick=function(){AddToHideArray(this.getAttribute("poster_name"))};
            }
        }
    }
}
function AddToHideArray(value_)
{
    // Add to array
    hide_array.push(value_)
    // Save to cookie
    var new_array_str=JSON.stringify(hide_array);
    createCookie("hide_array",new_array_str,999);
    // Reload page
    location.reload();
}

function RemoveFromHideArray(value_)
{
    for( var i = 0; i < hide_array.length; i++)
    {

        if ( hide_array[i] === value_)
        {
            hide_array.splice(i, 1);
            i--;
        }
    }
    // Save to cookie
    var new_array_str=JSON.stringify(hide_array);
    createCookie("hide_array",new_array_str,999);
    // Reload page
    location.reload();
}

function Create_Element(ElementType,addInNode)
{
    var input=document.createElement(ElementType);
    if (addInNode!=null)
    {
        addInNode.appendChild(input);
    }
    else
    {
        document.body.appendChild(input);
    }
}

function Create_Button(buttonText,cookieName,addInNode)
{
    // Get cookie info
    if (cookieName!=null)
    {
        var showThis=readCookie(cookieName);
        if (showThis==null)
        {
            showThis="True";
        }
    }
    else
    {
        showThis="True";
    }

    var input=document.createElement("input");
    input.type="button";
    input.value=buttonText;
    //input.onclick = Toggle_Nedl;
    if (showThis=="True")
    {
        input.setAttribute("style", "float:left;font-weight: bold;");
    }
    else
    {
        input.setAttribute("style", "float:left;color: #888888");
    }
    if (addInNode!=null)
    {

        addInNode.appendChild(input);
    }
    else
    {
        document.body.appendChild(input);
    }
    return input;
}

function createCookie(name,value,days) {
	var expires;
    if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}