fokse's d2jsp post blocker

Hides posts from a defined list of users [Update 03/03/2024]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @license MIT
// @name          fokse's d2jsp post blocker
// @author        Fokse
// @description   Hides posts from a defined list of users [Update 03/03/2024]
// @namespace	  jsppostblocker
// @include       https://forums.d2jsp.org/topic.php?t=*&f=*
// @include	  https://forums.d2jsp.org/topic.php?t=*
// @include	  https://forums.d2jsp.org/post.php
// @require http://code.jquery.com/jquery-latest.js
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @version 1.15
// ==/UserScript==

if (!Array.isArray(GM_getValue("fokse_post_blocker_userlist"))) {
    GM_setValue("fokse_post_blocker_userlist", []);
}

function parsePage(){
    console.log('sup');
	var blockedUser = GM_getValue('fokse_post_blocker_userlist')

    $('body > form > dl').each(function() {
        if (typeof $('.pU > div > a', this).attr('href') !== 'undefined' && ~$('.pU > div > a', this).attr('href').indexOf('user.php?i=')) {
			var userId = $('.pU > div > a', this).attr('href').split("=")[1];
			if (~blockedUser.indexOf(userId)){
				$('dd > div > div.bc1.upc > div.desc.cl.rc > div.fR.links', this).prepend(`<b><a href="#" class="blockPost" action="unblock" userId="${userId}">Unblock Posts</a></b>`);
				$('dd > div > div.bc1.upc > .sig', this).hide();
                $('.pU', this).children().eq(1).hide()
				$('div.bts', this).html('<center><b><span style="color:#d65a5a;">Post from that user are hidden</style></b></center>');
			} else{
				$('dd > div > div.bc1.upc > div.desc.cl.rc > div.fR.links', this).prepend(`<b><a href="#" class="blockPost" action="block" userId="${userId}">Block Posts</a></b>`);
			}
        }
    });

    $('.blockPost').click(function(){
    	var 		blockedUser = GM_getValue('fokse_post_blocker_userlist'),
    				userId		= $(this).attr('userId');

    	if ($(this).attr('action') == "block" && !~blockedUser.indexOf(userId)){
    			blockedUser.push(userId);
    	}
    	else if ($(this).attr('action') == "unblock" && ~blockedUser.indexOf(userId)){
    			blockedUser.splice(blockedUser.indexOf(userId),1);
    	}


    	GM_setValue("fokse_post_blocker_userlist", blockedUser);
        location.reload();
    })

}

parsePage();