fokse's d2jsp post blocker

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

当前为 2024-03-04 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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();