Flashback hide

Hide specific users on Flashback

目前為 2021-05-12 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Flashback hide
// @namespace    http://tampermonkey.net/
// @version      1.1
// @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;
var i;
// Check if on main page
if (p.length>0)
{
    // 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.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);
            }
        }
    }

    // Check quotes
    p = document.getElementsByClassName('glyphicon-arrow-left');
    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.parentNode.parentNode.childNodes[3].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)
            {
                // Add line break
                Create_Element("BR",n.parentNode.parentNode.parentNode.parentNode);
                // Create show button
                mybutton=Create_Button("[Show " + name_ + "]",null,n.parentNode.parentNode.parentNode.parentNode);
                // Add name in button
                mybutton.setAttribute("poster_name", name_);
                // Remove name from array if clicked
                mybutton.onclick=function(){RemoveFromHideArray(this.getAttribute("poster_name"))};
                n.parentNode.parentNode.parentNode.parentNode.removeChild(n.parentNode.parentNode.parentNode);
            }
            else
            {
                // Add line break
                Create_Element("BR",n.parentNode.parentNode.parentNode.parentNode);
                // Create hide button
                mybutton=Create_Button("[Hide " + name_ + "]",null,n.parentNode.parentNode.parentNode.parentNode);
                // Add name in button
                mybutton.setAttribute("poster_name", name_);
                // Add name to array if clicked
                mybutton.onclick=function(){AddToHideArray(this.getAttribute("poster_name"))};
            }
        }
    }
}
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);
}