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

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

目前為 2022-03-09 提交的版本,檢視 最新版本

// ==UserScript==
// @name         豆瓣小组屏蔽用户及屏蔽标题关键词
// @namespace    http://tampermonkey.net/
// @version      1.0.7
// @license      MIT
// @description  提供豆瓣小组屏蔽用户及屏蔽标题关键词的功能,no sight,no mind
// @author       https://gf.qytechs.cn/users/574395-frammolz-amanda
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// @match        https://www.douban.com/group/*
// @grant        unsafeWindow
// ==/UserScript==
 
(function() {
	window.onload = function(){
		var Html = `
			<div id="top-nav-blk" class="douban-blk">
				<div class="douban-blk-out"></div>
				<div class="popup">
					<div>
						<img class="img" src="https://s1.ax1x.com/2022/03/08/b6j7pF.png" height="80" width="80" />
						<h1><br /></h1>
						<h1>屏蔽名单</h1>
						<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,0);
					width: 100%;
					height: 100%;
					z-index: 99;
				}
				.popup {
					width: 400px;
					text-align: center;
					margin: auto;
					position:absolute;
					right:0px;
					top: 28px;
					background: #fff;
					padding: auto;
					overflow: auto;
					z-index: 100;
					border-style: groove
				}
			</style>
		`;
		var style1 = `
			<style>
				.popup {
					height: auto;
				}
			</style>
		`;

		var style2 = `
			<style>
				.popup {
					height: 800px;
				}
			</style>
		`;
	 
		var blk=JSON.parse(localStorage.getItem("blk"));
	 
		if(!blk){
			blk=[];
			localStorage.setItem("blk", JSON.stringify(blk));
		}

		$(document.body).append(Html);
		$(document.body).append(style);
	 
		if(blk.length>13){
			$(document.body).append(style2);
		}
		else{
			$(document.body).append(style1);
		}

		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 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();
						}
					})
				})
			}
		}
	}
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址