豆瓣小组屏蔽用户及屏蔽标题关键词

提供豆瓣小组屏蔽用户及屏蔽标题关键词的功能

As of 2022-03-07. See the latest version.

// ==UserScript==
// @name         豆瓣小组屏蔽用户及屏蔽标题关键词
// @namespace    http://tampermonkey.net/
// @version      1.0.4
// @license      MIT
// @description  提供豆瓣小组屏蔽用户及屏蔽标题关键词的功能
// @author       https://greasyforks.org/users/574395-frammolz-amanda
// @require		 https://cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.js
// @match        https://www.douban.com/group/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function() {
	var Html = `
		<div id="top-nav-blk" class="douban-blk">
			<div class="douban-blk-out"></div>
			<div class="popup">
				<div id="app">
					<img class="img" src="https://s1.ax1x.com/2022/03/08/b6j7pF.png" height="60" width="60" />
					<p class="blockTitle">屏蔽名单:</p>
					<div id="blk"></div>
					<div>
						<br /><input type="text" placeholder="输入主页地址或屏蔽词" id="blockItem" />
						<button id="addBlockItem" class="addBlockItem">add</button>
						<p align="center">示例:https://www.douban.com/people/xxxxxxx/<br />(链接后面不要加后缀)or抽奖</p>
					</div>
				</div>
				<button id="Done" class="addBlockItem" >完成</button><br /><br />
			</div>
		</div>
	`;
	var style = `
		<style>
			.img{
				position:absolute;
				top:0px;
				right:0px;
			}
			.blk{
				float: left;
				margin: auto auto auto 30px;
			}
			.del{
				float: right;
				cursor: pointer;
				margin-right: 30px;
				padding: 0px 12px;
			}
			.del:hover {
				color: #fff;
			}
			.addBlockItem{
				cursor: pointer;
				padding: 0px 8px;
			}
			.addBlockItem:hover {
				color: #fff;
			}
			.douban-blk {
				width: 100vw;
				height: 100vh;
				position: absolute;
				top: 0;
				left: 0;
				display:none;
			}
			.douban-blk-out {
				position: absolute;
				background: rgba(0,0,0,.6);
				width: 100%;
				height: 100%;
				z-index: 99;
			}
			.popup {
				height: auto;
				width: 400px;
				text-align: center;
				margin: auto;
				position:absolute;
				right:0px;
				top: 28px;
				background: #fff;
				padding: auto;
				overflow: auto;
				z-index: 100;
			}
		</style>
	`;

	$(document.body).append(Html);
	$(document.body).append(style);

	const utils = {
		bindedEles: [],
		bindClick: function(selector, callback) {
			this.bindedEles.push(selector);
			$(selector).click(callback);
		}
	}

	const insertPos = $('#db-global-nav .top-nav-doubanapp');
	if (insertPos && insertPos[0]) {
		$(insertPos[0]).after('<div id="blk-config" class="top-nav-info"><span class="addBlockItem">黑名单设置</span></div>');
	}
	const $contain = $('#top-nav-blk');
	const $body = $(document.body);
	utils.bindClick('#blk-config', e => {
		$contain.show();
		$body.css('overflow', 'hidden');
	});
	utils.bindClick('#Done', e => {
		$contain.hide();
		$body.css('overflow', 'initial');
	});
	utils.bindClick('.douban-blk-out', e => {
		$contain.hide();
		$body.css('overflow', 'initial');
	});

	var blk=JSON.parse(localStorage.getItem("blk"));

	var list=[];

	goto();

	function goto(){

		list=[];

		blk.forEach(function(item,index){

			var listItem='<br /><div class="blockItem"><p class="blk">item</p><button data-index="{index}" class="del">删除</button></div><br />'.replace(/item/g,item)

			listItem=listItem.replace(/{index}/g,index)

			list.push(listItem)

			$("#blk").html(list.join(""));

			$(".del").on("click",function(){

				var index=$(this).attr("data-index");

				$(this).closest("div").remove();

				blk=JSON.parse(localStorage.getItem("blk"));

				blk.splice(index,1)

				localStorage.setItem("blk", JSON.stringify(blk));

				goto();

			})
		})
	}
	$("#addBlockItem").on("click",function(){

		var blockItem=$("#blockItem").val();

		if(!blockItem){

			alert("不能提交空白内容")

			return;
		}

		blk=JSON.parse(localStorage.getItem("blk"));

		var listItem='<br /><div class="blockItem"><p class="blk">item</p><button data-index="{index}" class="del">删除</button></div><br />'.replace(/item/g,blockItem);

		if($.isEmptyObject(blk)){

			blk.push(blockItem)

			localStorage.setItem("blk", JSON.stringify([blockItem]));

      		listItem=listItem.replace(/{index}/,"0")

		}

		else{

			blk.push(blockItem)

			localStorage.setItem("blk", JSON.stringify(blk));

     		listItem=listItem.replace(/{index}/,blk.length-1)
         	 
		}

		$("#blockItem").val("");

		goto();

	})

	var windowUrl = window.location.href;
	var topicre = /https:\/\/www.douban.com\/group\/topic\/*/;
	var groupre = /https:\/\/www.douban.com\/group\/*/;
	if( windowUrl.match(groupre)){
		if( windowUrl.match(topicre)){
			blk=JSON.parse(localStorage.getItem("blk"));
			$("a").each(function(index,item){
    			var href=$(item).attr("href");
				var title=$(item).attr("title");
				blk.forEach(function(blockItem){
					var re = new RegExp(".*"+blockItem+".*");
					var fix = new RegExp("真的要删除"+".*"+blockItem+".*"+"的发言");
					var result1=re.exec(href);
					var result2=re.exec(title);
					var result3=fix.exec(title);
					if(result1||result2&&!result3){
						$(item).closest("li").hide();
						$(item).closest(".comment-item").hide();
					}
				})
			})
		}
		else{
			blk=JSON.parse(localStorage.getItem("blk"));
			$("a").each(function(index,item){
				var href=$(item).attr("href");
				var title=$(item).attr("title");
				blk.forEach(function(blockItem){
					var re = new RegExp(".*"+blockItem+".*");
					var result1=re.exec(href);
					var result2=re.exec(title);
					if(result1||result2){
						$(item).closest("tr").hide();
					}
				})
			})
		}
	}
})();
长期地址
遇到问题?请前往 GitHub 提 Issues。