您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
移除讨厌鬼的帖子
当前为
- // ==UserScript==
- // @name remove the posts which make you sick
- // @author burningall
- // @description 移除讨厌鬼的帖子
- // @version 2015.7.4.2.0
- // @include *tieba.baidu.com/p/*
- // @include *tieba.baidu.com/*
- // @include *tieba.baidu.com/f?*
- // @grant GM_addStyle
- // @grant GM_getValue
- // @grant GM_setValue
- // @grant GM_listValues
- // @grant GM_deleteValue
- // @supportURL http://www.burningall.com
- // @contributionURL troy450409405@gmail.com|alipay.com
- // @namespace https://greasyfork.org/zh-CN/users/3400-axetroy
- // ==/UserScript==
- //============快捷键==========
- //【Ctrl】+【F3】-----调出控制面板
- //============样式区==========
- var style='\
- body{\
- -webkit-backface-visibility: hidden;\
- }\
- .blur{\
- -webkit-filter: blur(10px);\
- -moz-filter: blur(10px);\
- -o-filter: blur(10px);\
- -ms-filter: blur(10px);\
- filter: blur(10px);\
- }\
- #pannal-troy{\
- width:200px;\
- height:auto;\
- background:#303030;\
- color:#fff;\
- position:fixed;\
- z-index:1000000000;\
- text-align:center;\
- }\
- #pannal-troy>div{\
- margin:10px 0;\
- }\
- #pannal-troy input{\
- color:#3e3e3e;\
- }\
- #pannal-troy h3{\
- color:rgb(0, 255, 226);\
- }\
- #pannal-setting input[type=range]{\
- width:80%;\
- }\
- #fn input{\
- padding:5px;\
- margin:0 5px;\
- border:none;\
- cursor:pointer;\
- }\
- #fn input:hover{\
- background:#2A959D;\
- color:#fff;\
- }\
- #pannal-troy>span{\
- position:absolute;\
- padding:0 10px;\
- top:0;\
- right:0;\
- cursor:pointer;\
- opacity:0.8;\
- background:#fff;\
- color:#303030;\
- }\
- #blockWay{\
- color:#3e3e3e;\
- border:none;\
- }\
- #mars{\
- position:fixed;\
- width:100%;\
- height:100%;\
- background:rgba(155, 155, 155,0.5);\
- top:0;\
- left:0;\
- z-index:999999999;\
- }\
- #showList{\
- position:relative;\
- overflow-y:auto;\
- width:100%;\
- max-height:115px;\
- }\
- #showList>li{\
- width:100%;\
- height:18px;\
- clear:both;\
- }\
- .key{\
- float:left;\
- clear:both;\
- }\
- .deletThis{\
- float:right;\
- cursor:pointer;\
- }\
- .disable-btn{\
- background:#6B6B6B;\
- cursor:not-allowed;\
- }\
- #addBlackList input{\
- width:80%;\
- }\
- ';
- GM_addStyle(style);
- //============公共函数区==========
- function addEvent(obj, event, fn) {
- return obj.addEventListener ? obj.addEventListener(event, fn, false) : obj.attachEventListener('on' + event, fn);
- };
- function getStyle(obj, attr) {
- return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj)[attr];
- };
- function $(id) {
- return document.getElementById(id)
- };
- function getSize(attr){
- return document.documentElement[attr] ? document.documentElement[attr] : document.body[attr]
- }
- function uniqueArray(data){
- data = data || [];
- var a = {};
- for (var i=0; i<data.length; i++) {
- var v = data[i];
- if (typeof(a[v]) == 'undefined'){
- a[v] = 1;
- }
- };
- data.length=0;
- for (var i in a){
- data[data.length] = i;
- }
- return data;
- }
- //============主要代码区==========
- function juggUrl(){
- var url=location.href;
- var postIn=/.*tieba.baidu.com\/p\/.*/ig;
- var postList=/.*tieba.baidu.com\/(f\?.*|[^p])/ig;
- if( postIn.test(url) ){//如果是帖子内
- return 1;
- }else if( postList.test(url) ){//如果在帖子列表
- return 2;
- }
- }
- function createList(){
- $('showList').innerHTML='';
- var li='';
- for(var i=0;i<GM_listValues().length;i++){
- //控制台输出 键名:键值
- var key = GM_listValues()[i];
- var value = GM_getValue( GM_listValues()[i],'');
- if( (typeof value =='number' && value>1000) || value==''){
- console.log( GM_listValues()[i] + ":" + GM_getValue(GM_listValues()[i],'') );
- li += '<li class="show_list" data="'+ key +'">'+'<span class="key">'+key+'</span>'+'<input class="deletThis" type="button" value="删除"/>'+'</li>';
- }//if
- }//for
- $('showList').innerHTML=li;
- var aDeleBtn=document.querySelectorAll('.deletThis');
- for(var i=0;i<aDeleBtn.length;i++){
- aDeleBtn[i].onclick=function(){
- var thisKey = this.parentNode.getAttribute('data');//获取当前结点的key
- GM_deleteValue( thisKey );//删除变量
- this.parentNode.remove( this.parentNode );//删除节点
- }//clickb
- }//for
- };
- function marks(obj){
- if(obj.querySelectorAll('mar').length>=1){
- return;
- }
- var oMar = document.createElement('div');
- oMar.className = 'mar';
- oMar.innerHTML = '屏蔽';
- obj.style.position = 'relative';
- obj.style.webkitFilter = 'blur('+ GM_getValue('setting-gus','3') +'px)';//chrome
- obj.style.filter = 'blur('+ GM_getValue('setting-gus','3') +'px)';//firefox
- obj.style.oFilter = 'blur('+ GM_getValue('setting-gus','3') +'px)';//opera
- obj.style.msFilter = 'blur('+ GM_getValue('setting-gus','3') +'px)';//IE
- obj.style.webkitBackfaceVisibility = 'hidden';
- obj.appendChild( oMar );
- oMar.style.width = parseInt( getStyle(obj,'width') ) + 'px';
- oMar.style.height = parseInt( getStyle(obj,'height') ) + 'px';
- oMar.style.background = GM_getValue('setting-col','#fff');
- oMar.style.position = 'absolute';
- oMar.style.top = '0';
- oMar.style.left = '0';
- oMar.style.zIndex = '999999998';
- oMar.style.opacity = GM_getValue('setting-opa','0.8');
- oMar.style.filter = 'alpha(opacity=' + GM_getValue('setting-opa','0.8')*100 +')';
- };
- function blockMod(){
- if( GM_getValue('setting-blockWay','遮罩屏蔽')=='遮罩屏蔽' ){
- return 1;//遮罩模式
- }else{
- return 2;//删除节点
- }
- }
- function btclick(This,list,n){
- var _thisTop,_thisUserId,_thisUserName,nowUserId,nowUserName;
- if(n=='postList'){
- _thisTop = This.parentNode.parentNode.parentNode.parentNode;
- _thisUserId = JSON.parse(_thisTop.getAttribute('data-field')).id;//当前id
- _thisUserName = JSON.parse(_thisTop.getAttribute('data-field')).author_name;//当前userName
- }else if(n=='post'){
- _thisTop = This.parentNode.parentNode.parentNode;
- _thisUserId = JSON.parse(_thisTop.getAttribute('data-field')).author.user_id;//当前id
- _thisUserName = JSON.parse(_thisTop.getAttribute('data-field')).author.user_name;//当前userName
- }
- if ( confirm('是否屏蔽') == true) { //如果按下确认
- GM_setValue( _thisUserName,_thisUserId );
- for (var j = 0; j < list.length; j++) {//循环匹配是否符合
- var userInfo = JSON.parse(list[j].getAttribute('data-field'))
- if(n=='postList'){
- nowUserId = userInfo.id;
- nowUserName = userInfo.author_name;
- }else if(n=='post'){
- nowUserId = userInfo.author.user_id;
- nowUserName = userInfo.author.user_name;
- }
- if (nowUserId == _thisUserId || nowUserName==_thisUserName) {//匹配成功
- if( blockMod()==1 ){//遮罩模式
- marks(list[j]);
- }else{//删除节点模式
- list[j].style.display = 'none';
- }
- }//匹配是否符
- } //for
- }//if如果按下确认
- }
- function block(name,id,list,I){
- for(var j=0;j<GM_listValues().length;j++){
- if( GM_listValues()[j] == name || GM_getValue(GM_listValues()[j],'') == id ){//如果匹配到
- if( blockMod()==1 ){//遮罩模式
- marks(list[I]);
- }else{//删除节点模式
- list[I].style.display = 'none';
- }
- }//匹配是否符合
- }//for,遍历屏蔽
- }
- function init() {//初始化程序
- //先清空
- var aBlockBtn = document.querySelectorAll('.shutup-post,.shutup-list,.mar')
- for(var i=0;i<aBlockBtn.length;i++){
- aBlockBtn[i].remove(this);
- }
- //=======帖子内==========
- if( juggUrl()==1 ){
- var aUsers = document.querySelectorAll('#j_p_postlist>div[data-field]');//获取列表
- var aName = document.querySelectorAll('.l_post .d_name');//屏蔽按钮将要插入的位置
- for (var i = 0; i < aUsers.length; i++) {
- //获取id和name
- var userName = JSON.parse(aUsers[i].getAttribute('data-field')).author.user_name;//第i个userName
- var userId = JSON.parse(aUsers[i].getAttribute('data-field')).author.user_id;//第i个userId
- //添加样式
- aName[i].style.background = '#303030';
- //添加点击事件
- aName[i].onclick=function(){
- var this_=this;
- btclick(this_,aUsers,'post');
- }
- //页面加载开始屏蔽
- block(userName,userId,aUsers,i);
- } //for,遍历所有节点
- //=======帖子列表==========
- }else if( juggUrl()==2 ){
- var aUsers=document.querySelectorAll('#thread_list>li[data-field]');//获取列表
- var aName = document.querySelectorAll('#thread_list>li[data-field] .threadlist_lz>.threadlist_author');//屏蔽按钮将要插入的位置
- for(var i=0;i<aUsers.length;i++){
- //获取id和name
- var userName = JSON.parse(aUsers[i].getAttribute('data-field')).author_name;//第i个userName
- var userId = JSON.parse(aUsers[i].getAttribute('data-field')).id;//第i个userId
- //添加样式
- aName[i].style.background = '#303030';
- //添加点击事件
- aName[i].onclick=function(){
- var this_=this;
- btclick(this_,aUsers,'postList');
- }
- //页面加载开始屏蔽
- block(userName,userId,aUsers,i)
- }//for,遍历所有节点
- }//在帖子列表
- }//初始化
- function autoTips(){
- var aUsers,userName,userId;
- if( juggUrl()==1 ){//帖子内
- var aTipsArr = new Array();
- var newString = '';
- aUsers = document.querySelectorAll('#j_p_postlist>div[data-field]');//获取列表
- for(var i=0;i<aUsers.length;i++){
- userName = JSON.parse(aUsers[i].getAttribute('data-field')).author.user_name;//第i个userName
- userId = JSON.parse(aUsers[i].getAttribute('data-field')).author.user_id;//第i个userId
- aTipsArr.push( userName );
- }
- uniqueArray( aTipsArr );
- for(var i=0;i<aTipsArr.length;i++){
- newString += '<option value="' + aTipsArr[i] + '" />';
- }
- lst.innerHTML = newString;
- }else{//帖子列表
- var aTipsArr = new Array();
- var newString = '';
- aUsers=document.querySelectorAll('#thread_list>li[data-field]');//获取列表
- for(var i=0;i<aUsers.length;i++){
- userName = JSON.parse(aUsers[i].getAttribute('data-field')).author_name;//第i个userName
- userId = JSON.parse(aUsers[i].getAttribute('data-field')).id;//第i个userId
- aTipsArr.push( userName );
- }
- uniqueArray( aTipsArr );
- for(var i=0;i<aTipsArr.length;i++){
- newString += '<option value="' + aTipsArr[i] + '" />';
- }
- lst.innerHTML = newString;
- }//if....else
- }
- //============执行区==========
- addEvent(window,'load',function(){
- init();
- })
- //跟随翻页加载
- var aUsers,aShut;
- addEvent(window,'scroll',function(){
- if( getSize('scrollTop') == 0){
- if( juggUrl()==1 ){//帖子内
- aUsers = document.querySelectorAll('#j_p_postlist>div[data-field]');
- aShut = document.querySelectorAll('.shutup-post');
- }else if(juggUrl()==2){//帖子列表
- aUsers=document.querySelectorAll('#thread_list>li[data-field]');
- aShut = document.querySelectorAll('.shutup-list');
- }
- if(aShut.length <= aUsers.length){//如果不存在屏蔽按钮
- init();
- }
- }//如果滚动到顶部
- })
- //============控制面板以及相关==========
- addEvent(window,'resize',function(){
- if( $('pannal-troy') ){
- $('pannal-troy').style.top = ( getSize('clientHeight') - $('pannal-troy').offsetHeight )/2 + 'px';
- $('pannal-troy').style.left = ( getSize('clientWidth') - $('pannal-troy').offsetWidth )/2 + 'px';
- }
- })
- addEvent(window,'keyup',function(e){
- var e = e || window.event;
- if( e.ctrlKey && e.keyCode==114 ){//快捷键ctrl+F3
- if( $('pannal-troy') ) return;
- var pannal = document.createElement('div');
- var pannal_mars = document.createElement('div');
- pannal_mars.id = 'mars';
- pannal_mars.className = "blur";
- pannal.id = 'pannal-troy';
- pannal.innerHTML='\
- <h3>配置参数</h3>\
- <div id="pannal-setting">\
- 屏蔽方式:<select id="blockWay">\
- <option>遮罩屏蔽</option>\
- <option>删除节点</option>\
- </select><br/>\
- 遮罩层颜色:<input id="col" type="color" /><br/>\
- 遮罩透明度(0~1):<input id="opa" type="range" min="0" max="1" step="0.1" /><br/>\
- 高斯模糊像素(0~10):<input id="gus" type="range" min="0" max="10" step="1" /><br/>\
- </div>\
- <hr/>\
- <h3>添加讨厌鬼</h3>\
- <div id="addBlackList">\
- 数字ID(选填):<input id="userId" type="text" placeholder="user_id"/><br/>\
- 贴吧ID(必填):<input id="userName" type="text" placeholder="user_name" list="lst" autocomplete="off"/>\
- <datalist id="lst" autocomplete="on"></datalist>\
- </div>\
- <hr/>\
- <h3>功能</h3>\
- <div id="fn">\
- <input id="save" type="button" value="保存" />\
- <input id="clear" type="button" value="清空" />\
- <input id="view" type="button" value="查看" />\
- </div>\
- <hr/>\
- <h3>屏蔽列表</h3>\
- <div>\
- <ul id="showList"></ul>\
- </div>\
- <span id="queit">X</span>\
- '
- document.body.appendChild( pannal );
- document.body.appendChild( pannal_mars );
- pannal.style.top = ( getSize('clientHeight') - pannal.offsetHeight )/2 + 'px';
- pannal.style.left = ( getSize('clientWidth') - pannal.offsetWidth )/2 + 'px';
- //初始化
- //智能提示userName和userId
- addEvent($('userName'),'input',function(){
- autoTips();
- })
- $('blockWay').value = GM_getValue('setting-blockWay','遮罩屏蔽' );//屏蔽方式
- $('col').value = GM_getValue('setting-col','#fff'); //默认遮罩的颜色
- $('opa').value = GM_getValue('setting-opa','0.8'); //默认遮罩透明度
- $('gus').value = GM_getValue('setting-gus','3'); //默认遮罩下的高斯模糊半径
- createList(); //加载黑名单列表
- //删除节点模式则禁用选项
- addEvent($('blockWay'),'input',function(){
- var aInput=[$('col'),$('opa'),$('gus')]
- if( $('blockWay').value == '删除节点' ){//删除节点模式
- for(var i=0;i<aInput.length;i++){
- aInput[i].readOnly = 'true';
- aInput[i].className = 'disable-btn';
- }
- }else{//遮罩屏蔽模式模式
- for(var i=0;i<aInput.length;i++){
- aInput[i].readOnly = 'false';
- aInput[i].className = '';
- }
- }
- })
- //====保存按钮====
- addEvent($('save'),'click',function(){
- //判断屏蔽方式
- if($('blockWay').value=='遮罩屏蔽'){
- GM_setValue('setting-blockWay','遮罩屏蔽');
- }else if($('blockWay').value=='删除节点'){
- GM_setValue('setting-blockWay','删除节点');
- }
- //遮罩颜色
- GM_setValue('setting-col',$('col').value);
- //遮罩透明度
- if( $('opa').value!='' && $('opa').value>0 && $('opa').value<1 ){//透明度有添加,并且0~1
- GM_setValue('setting-opa',$('opa').value);
- }
- //高斯模糊半径
- if( $('gus').value!='' && $('gus').value>0){
- GM_setValue('setting-gus',$('gus').value);
- }
- //匹配ID是否正确
- var reg=/^[0-9]{9}$/ig;
- if( $('userName').value!='' && (reg.test($('userId').value)==true || $('userId').value=='') ){
- //保存形式:user_name:user_id
- GM_setValue( $('userName').value,$('userId').value );
- alert('保存成功' + "\n用户名:" + $('userName').value + "\nID:" + GM_getValue($('userName').value,'') + '\n屏蔽方式:'+ GM_getValue('setting-blockWay','遮罩屏蔽' )+'\n遮罩颜色:' + GM_getValue('setting-col','#fff') + '\n遮罩透明度:'+ GM_getValue('setting-opa','0.8') +'\n高斯模糊:'+GM_getValue('setting-gus','3') );
- }else if( $('userName').value=='' && $('userId').value==''){
- alert('保存成功\n屏蔽方式:'+ GM_getValue('setting-blockWay','遮罩屏蔽' )+'\n遮罩颜色:' + GM_getValue('setting-col','#fff') + '\n遮罩透明度:'+ GM_getValue('setting-opa','0.8') +'\n高斯模糊:'+GM_getValue('setting-gus','3') )
- }else{
- alert('输入不正确:\n数字ID:选填(如果填了必须是9位数字)\n贴吧ID:必填')
- }
- createList();//重新生成列表
- })
- //====清空按钮====
- addEvent($('clear'),'click',function(){
- for(var i=0;i<GM_listValues().length;i++){
- //清空所有变量
- //GM_deleteValue( GM_listValues()[i] ) + ":" + GM_getValue( GM_listValues()[i],'' )
- var value = GM_getValue( GM_listValues()[i],'');
- if( (typeof value=='number' && value>1000) || value==''){
- GM_deleteValue( GM_listValues()[i] );//删除键名
- }
- }//for
- createList();//重新生成列表
- })
- //====清空按钮====
- addEvent($('view'),'click',function(){
- createList();//生成列表
- })
- //===关闭按钮====
- addEvent($('queit'),'click',function(){
- $('pannal-troy').remove(this);
- $('mars').remove(this);
- })
- addEvent($('mars'),'click',function(){
- $('pannal-troy').remove(this);
- $('mars').remove(this);
- })
- }//if
- })//addEvent