remove the posts which make you sick

移除讨厌鬼的帖子

当前为 2015-08-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name remove the posts which make you sick
  3. // @author burningall
  4. // @description 移除讨厌鬼的帖子
  5. // @version 2015.8.10
  6. // @include *tieba.baidu.com/p/*
  7. // @include *tieba.baidu.com/*
  8. // @include *tieba.baidu.com/f?*
  9. // @grant GM_addStyle
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @grant GM_listValues
  13. // @grant GM_deleteValue
  14. // @run-at document-start
  15. // @compatible chrome 推荐
  16. // @compatible firefox 性能稍微不足
  17. // @license The MIT License (MIT); http://opensource.org/licenses/MIT
  18. // @supportURL http://www.burningall.com
  19. // @contributionURL troy450409405@gmail.com|alipay.com
  20. // @namespace https://greasyfork.org/zh-CN/users/3400-axetroy
  21. // ==/UserScript==
  22. //
  23. (function(window,document){
  24. //==============默认配置==============
  25. var defaultdConfig = {
  26. 'blockWay': '遮罩屏蔽', //遮罩屏蔽或删除节点
  27. 'color': '#ffffff', //遮罩颜色
  28. 'opacity': '0.8', //遮罩透明度
  29. 'blurpx': '3', //高斯模糊大小
  30. };
  31. //==============TQuery=================
  32. function $(tArg){
  33. return new TQuery(tArg);
  34. }
  35. function TQuery(tArg){
  36. this.arg = tArg;//保存传进来的参数
  37. this.elements = [];//用来保存选择的元素
  38. this.doc = document;
  39. switch( typeof tArg ){
  40. case "undefined" :
  41. return this;
  42. case "function" :
  43. addEvent(window,'load',tArg);
  44. break;
  45. case "string" :
  46. var aElems = this.doc.querySelectorAll(tArg);
  47. for(var i=0;i<aElems.length;i++){
  48. this.elements.push(aElems[i]);
  49. }
  50. break;
  51. case "object" : //对象
  52. this.elements.push(tArg);
  53. break;
  54. }
  55. this.length = this.elements.length;
  56. }
  57. TQuery.prototype.find = function(str){
  58. var childElements = [];//存放临时数据
  59. for(var i=0;i<this.length;i++){
  60. var aElems = this.elements[i].querySelectorAll(str);
  61. var length = aElems.length;
  62. var j =0;
  63. while(j<length){
  64. childElements.push( aElems[j] );
  65. j++;
  66. }
  67. }
  68. this.elements = childElements;
  69. this.length = childElements.length;//返回新的长度
  70. return this;
  71. };
  72. TQuery.prototype.click = function(fn){
  73. var length = this.elements.length;
  74. for(var i=0;i<length;i++){
  75. addEvent(this.elements[i],'click',fn);
  76. }
  77. return this;//返回对象,进行链式操作
  78. };
  79. TQuery.prototype.bind = function(type,fn){
  80. if(arguments.length==1){//如果只传一个json参数e
  81. for(var k=0;k<this.length;k++){
  82. for(var attr in type){
  83. addEvent(this.elements[k],attr,type[attr]);
  84. }
  85. }
  86. }else{//如果传两个参数,则统一执行一个e
  87. var events = type.split(' ');
  88. var eventsLength = events.length;
  89. for(var i=0;i<this.length;i++){
  90. var j=0;
  91. while(j<eventsLength){
  92. addEvent(this.elements[i],events[j],fn);
  93. j++;
  94. }
  95. }
  96. }
  97. return this;//返回对象,进行链式操作
  98. };
  99. TQuery.prototype.on = function(type,fn){
  100. if(arguments.length==1){//如果只传一个json参数
  101. for(var k=0;k<this.length;k++){
  102. for(var attr in type){
  103. this.elements[k][ 'on'+attr ] = type[attr];
  104. }
  105. }
  106. }else{//如果传两个参数e,fn
  107. var events = type.split(' ');//获取每个事件
  108. var eventsLength = events.length;
  109. for(var i=0;i<this.length;i++){
  110. var j =0;
  111. while(j<eventsLength){
  112. this.elements[i][ 'on'+events[j] ] = fn;
  113. j++;
  114. }
  115. }
  116. }
  117. return this;//返回对象,进行链式操作
  118. };
  119. TQuery.prototype.toggle = function(){
  120. var _arguments = arguments;
  121. var length = _arguments.length;
  122. var count = 0;
  123. for(var i=0;i<this.length;i++){
  124. var _this = this.elements[i];
  125. this.on('click',function(){
  126. _arguments[count++%length].call(_this);//执行 ,解决this错误的问题
  127. });
  128. }
  129. return this;//返回对象,进行链式操作
  130. };
  131. TQuery.prototype.css = function(attr,value){
  132. var type = /^(width|left|top|bottom|right|line-height|font-size)+/ig;
  133. var type2 = /^(height|margin|padding)+/ig;
  134. var type3 = /\d+(px)/ig;
  135. var type4 = /\:/ig;
  136. if(arguments.length==2){//设置单个样式
  137. if( type.test(attr) && value.indexOf('%')<0 ){
  138. value = parseFloat(value).toFixed(2) + 'px';
  139. }
  140. for(var m=0;m<this.length;m++){
  141. this.elements[m].style[attr] = value;
  142. }
  143. }else{//一个参数
  144. if(typeof attr=="string"){//获取样式
  145. if( type4.test(attr) ){//如果一长串字符串设置,background:#303030;font-size:20px;
  146. for(var x=0;x<this.length;x++){
  147. this.elements[x].style.cssText = attr;
  148. }
  149. }else{
  150. return this.elements[0].currentStyle ? this.elements[0].currentStyle[attr] : getComputedStyle(this.elements[0])[attr];
  151. }
  152. }else if( typeof(attr) == "object" && Object.prototype.toString.call(attr).toLowerCase() == "[object object]" && !attr.length ){//json
  153. //json设置样式
  154. var css = "";
  155. for(var i =0;i<this.length;i++){
  156. //纯CSS写法
  157. for(var k in attr){
  158. //k == 属性名字,width,height,opacity等
  159. //attr[k] == 属性值,300px,#303030等
  160. if((type.test(k) || type2.test(k)) && attr[k].indexOf('%')<0 ){//如果是带像素的属性,并且没有%符号
  161. attr[k] = parseFloat( attr[k] ).toFixed(2) + 'px';
  162. }
  163. css += k+":"+attr[k]+";";
  164. }
  165. this.elements[i].style.cssText = css;
  166. }
  167. }
  168. }
  169. return this;//返回对象,进行链式操作
  170. };
  171. TQuery.prototype.style = function(attr){
  172. //IE下,如果宽高设置为百分比,则返回也是百分比。
  173. return this.elements[0].currentStyle ? this.elements[0].currentStyle[attr] : getComputedStyle(this.elements[0])[attr];
  174. };
  175. TQuery.prototype.size = function(attr){
  176. return this.doc.documentElement[attr] ? this.doc.documentElement[attr] : this.doc.body[attr];
  177. };
  178. TQuery.prototype.animate = function(json,configjson){
  179. //如果两个参数.animate('width','300');
  180. for(var i=0;i<this.length;i++){
  181. var _this = this.elements[i];
  182. clearInterval(_this.animate);
  183. _this.animate = setInterval(function() {
  184. //注意,此处this指的是window(匿名函数)
  185. var bStop = true;//判断运动是否停止
  186. for(var attr in json){//attr代表属性,'width','height'.而json[attr]代表数值
  187. // 1. 取得当前的值(可以是width,height,opacity等的值)
  188. var objAttr = 0 ;
  189. if(attr == 'opacity'){//获取当前数值
  190. objAttr = Math.round(parseFloat( $(_this).style(attr) ) * 100);
  191. }else{
  192. objAttr = parseInt( $(_this).style(attr) );
  193. }
  194. // 2.计算运动速度
  195. var jsonattr = parseFloat( json[attr] );
  196. var speedConfig = (configjson && typeof ( configjson.speed ) != 'undefined') ? configjson.speed : 10;
  197. var iSpeed = (jsonattr - objAttr) / speedConfig; //(目标数值-当前数值)/10
  198. iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed); //如果速度>0,则速度向上取整,如果小于0,则保留小数
  199. // 3. 检测所有运动是否到达目标
  200. //objAttr,当前点,json[attr]为目标点
  201. if ( (iSpeed>0 && objAttr <= jsonattr) || (iSpeed<0 && objAttr >= jsonattr) ) {//如果有其中一项没有达到目标
  202. bStop = false;
  203. }
  204. if (attr == "opacity") {
  205. _this.style.filter = 'alpha(opacity:' + (objAttr + iSpeed) + ')';
  206. _this.style.opacity = (objAttr + iSpeed) / 100;
  207. } else {
  208. _this.style[attr] = objAttr + iSpeed + 'px'; //赋值开始运动
  209. }
  210. if( configjson && typeof configjson.load !='undefined' ){
  211. configjson.load.call(_this);
  212. }
  213. if (bStop) { // 表示所有运动都到达目标值
  214. clearInterval(_this.animate);
  215. if( configjson && typeof configjson.end != 'undefined' ){
  216. configjson.end.call(_this);
  217. }
  218. }
  219. }//for
  220. },30);
  221. }//for
  222. return this;//返回对象,进行链式操作
  223. };
  224. TQuery.prototype.attr = function(attr,value){
  225. //attr不能是数字
  226. if(arguments.length==2){//2个参数,设置属性
  227. for(var k=0;k<this.length;k++){
  228. if(this.elements[k][attr]){
  229. this.elements[k][attr] = value;
  230. }else{
  231. this.elements[k].setAttribute(attr,value);
  232. }
  233. }
  234. }else if(arguments.length==1){//1个参数
  235. if( typeof(attr) == "object" && Object.prototype.toString.call(attr).toLowerCase() == "[object object]" && !attr.length ){//如果是json,则分别设置属性
  236. for(var i=0;i<this.length;i++){
  237. for(var j in attr){
  238. if( this.elements[i][j] ){//如果属性是可以直接读取
  239. this.elements[i][j] = attr[j];
  240. }else{//如果是自定义属性
  241. this.elements[i].setAttribute(j,attr[j]);
  242. }
  243. }
  244. }
  245. }else{//读取属性
  246. return this.elements[0][attr] || this.elements[0].getAttribute(attr);
  247. }
  248. }
  249. return this;//返回对象,进行链式操作
  250. };
  251. TQuery.prototype.value = function(setting){
  252. if(setting){//设置
  253. for(var i=0;i<this.length;i++){
  254. this.elements[i].value = setting;
  255. }
  256. return this;
  257. }
  258. //读取
  259. return this.elements[0].value;
  260. };
  261. TQuery.prototype.html = function(setting){
  262. if(setting){//设置
  263. for(var i=0;i<this.length;i++){
  264. this.elements[i].innerHTML = setting;
  265. }
  266. return this;
  267. }
  268. return this.elements[0].innerHTML;
  269. };
  270. TQuery.prototype.text = function(setting){
  271. if(setting){//设置
  272. for(var i=0;i<this.length;i++){
  273. this.elements[i].innerText = this.elements[i].textContent = setting;
  274. }
  275. return this;
  276. }
  277. //读取
  278. return this.elements[0].innerText || this.elements[0].textContent;
  279. };
  280. TQuery.prototype.remove = function(){
  281. for(var i=0;i<this.length;i++){
  282. this.elements[i].remove();
  283. }
  284. return this;//返回对象,进行链式操作
  285. };
  286. TQuery.prototype.get = function(n){
  287. n = n || 0;
  288. if(n=='all' && this.length>1){//如果没有参数,并且多个,则返回数组
  289. return this.elements;
  290. }
  291. return this.elements[n];
  292. };
  293. TQuery.prototype.extend = function(name,fn){
  294. TQuery.prototype[name] = fn;
  295. return this;//返回对象,进行链式操作
  296. };
  297. TQuery.prototype.constructor = TQuery;
  298.  
  299.  
  300. //==============公共函数=================
  301. function addEvent(obj, type, fn){
  302. return obj.addEventListener ?
  303. obj.addEventListener(type, function(e){
  304. var ev = window.event ? window.event : (e ? e : null);
  305. ev.target = ev.target || ev.srcElement;
  306. if( fn.call(obj,ev)===false ){//回掉函数为false,则阻止默认时间
  307. e.cancelBubble = true;//阻止冒泡
  308. e.preventDefault();//chrome,firefox下阻止默认事件
  309. }
  310. }, false)
  311. :
  312. obj.attachEvent('on' + type, function(e){
  313. //fn.call(obj,e);//解决IE8下,this是window的问题
  314. var ev = window.event ? window.event : (e ? e : null);
  315. ev.target = ev.target || ev.srcElement;
  316. if(fn.call(obj,ev)===false ){
  317. e.cancelBubble = true;//阻止冒泡
  318. return false;//阻止默认事件,针对IE8
  319. }
  320. });
  321. }
  322.  
  323. function hasClass(obj, cName) {
  324. // ( \\s|^ ) 判断前面是否有空格 (\\s | $ )判断后面是否有空格 两个感叹号为转换为布尔值 以方便做判断
  325. return !!obj.className.match(new RegExp("(\\s|^)" + cName + "(\\s|$)"));
  326. }
  327.  
  328. //==============主要函数=================
  329. function position(){
  330. var url = location.href,
  331. postIn = /.*tieba.baidu.com\/p\/.*/ig,
  332. postList = /.*tieba.baidu.com\/(f\?.*|[^p])/ig;
  333. if (postIn.test(url)) { //如果是帖子内
  334. return "post";//1
  335. } else if (postList.test(url)) { //如果在帖子列表
  336. return "list";//0
  337. }
  338. }
  339.  
  340. function barName() {
  341. var $name = $(".card_title_fname").text(),
  342. newText = $name.replace(/\s*/ig,'');
  343. return newText;
  344. }
  345.  
  346. function blockMod() {
  347. if (GM_getValue('setting-blockWay', defaultdConfig.blockWay) == '遮罩屏蔽') {
  348. return "wrap"; //遮罩模式,1
  349. } else {
  350. return "remove"; //删除节点,2
  351. }
  352. }
  353.  
  354. function createList() {
  355. $('#showList').html(" "); //先清空,后生成
  356. var li = '',
  357. json = null,
  358. length = GM_listValues().length,
  359. key,
  360. value;
  361. for (var i = 0; i < length; i++) {
  362. key = GM_listValues()[i];
  363. value = GM_getValue(GM_listValues()[i], '');
  364. if (value.length < 10 || value === true || value === false) continue;
  365. json = JSON.parse(value);
  366. li +='<tr data-value=' + value + '>'+
  367. '<td style="min-width:100px">' + json.name + '</td>'+
  368. '<td style="min-width:100px">' + json.id + '</td>'+
  369. '<td style="min-width:75px">' + json.bar + '</td>'+
  370. '<td style="min-width:75px">' + json.reson + '</td>'+
  371. '<td style="min-width:50px"><input type="button" class="deletThis" value="删除"/></td>'+
  372. '</tr>';
  373. } //for
  374. $('#showList').html(li);
  375. }
  376.  
  377. function searchInList() {
  378. var str = '',
  379. userInfo = "",
  380. userInfoStr = "",
  381. list = document.querySelectorAll('#showList tr'),
  382. listLength = list.length,
  383. inputValue = $('#sear').value(),
  384. $list = $("#showList");
  385. createList();
  386. $("#showList").html(" ");
  387. for (var i = 0; i < listLength; i++) {
  388. userInfo = JSON.parse($(list[i]).attr('data-value'));
  389. if (userInfo.name.indexOf(inputValue) >= 0 || userInfo.id.indexOf(inputValue) >= 0 || userInfo.bar.indexOf(inputValue) >= 0 || userInfo.reson.indexOf(inputValue) >= 0) { //匹配name,id,bar,reson
  390. userInfoStr = JSON.stringify(userInfo);
  391. str += '<tr data-value=' + userInfoStr + '>'+
  392. '<td style="width:100px">' + userInfo.name + '</td>'+
  393. '<td style="width:100px">' + userInfo.id + '</td>'+
  394. '<td style="width:75px">' + userInfo.bar + '</td>'+
  395. '<td style="width:75px">' + userInfo.reson + '</td>'+
  396. '<td style="width:50px"><input type="button" class="deletThis" value="删除"/></td>'+
  397. '</tr>';
  398. }
  399. } //for
  400. $("#showList").html(str);
  401. }
  402. //将脚本还原到最初状态
  403. function clearall(){
  404. var length = GM_listValues().length;
  405. for(var i=0;i<length;i++){
  406. console.log(GM_deleteValue(GM_listValues()[i]) + ":" + GM_getValue(GM_listValues()[i], ''));
  407. }
  408. GM_setValue('setting-blockWay', defaultdConfig.blockWay); //屏蔽方式
  409. GM_setValue('setting-col', defaultdConfig.color); //默认遮罩的颜色
  410. GM_setValue('setting-opa', defaultdConfig.opacity); //默认遮罩透明度
  411. GM_setValue('setting-gus', defaultdConfig.blurpx); //默认遮罩下的高斯模糊半径
  412. }
  413. //==============主要对象=================
  414. function init(){
  415. return new Init();
  416. }
  417. function Init(){
  418. var user,userName,userId,pos,temp,lzl;
  419. this.user = [];//用于储存所有用户信息,包括name,id
  420. // this.userLzl = [];//用于储存所有用户信息,包括name,id
  421. this.list = position()=="post" ? document.querySelectorAll('#j_p_postlist>div[data-field]') : document.querySelectorAll('#thread_list>li[data-field]');//所有用户所占的DIV,LI
  422. // this.listLzl = document.querySelectorAll('.j_lzl_m_w>li[data-field]:not(.lzl_li_pager)');
  423. // pos = position()=="post" ? document.querySelectorAll('.l_post .d_name') : document.querySelectorAll('#thread_list>li[data-field] .threadlist_lz>.threadlist_author');//点击屏蔽,屏蔽按钮需要插入的位置
  424. var listLength = this.list.length;
  425. for(var i=0;i<listLength;i++){
  426. userName = position()=="post" ? JSON.parse(this.list[i].getAttribute('data-field')).author.user_name : JSON.parse(this.list[i].getAttribute('data-field')).author_name;
  427. userId = position()=="post" ? JSON.parse(this.list[i].getAttribute('data-field')).author.user_id : JSON.parse(this.list[i].getAttribute('data-field')).id;
  428. temp = {};
  429. temp.name = userName;
  430. temp.id = userId;
  431. this.user.push(temp);
  432. }
  433. //楼中楼
  434. // var listLzlLength = this.listLzl.length;
  435. // console.log( listLzlLength );
  436. // for(var j=0;j<listLzlLength;j++){
  437. // var lzlName = JSON.parse( this.listLzl[j].getAttribute("data-field").replace(/\'/ig,'\"') ).user_name;
  438. // var lzlId = "";
  439. // temp = {};
  440. // temp.name = lzlName;
  441. // temp.id = lzlId;
  442. // // console.log( lzlName );
  443. // // console.log( j );
  444. // this.userLzl.push(temp);
  445. // }
  446. return this;
  447. }
  448.  
  449. //页面加载开始屏蔽
  450. Init.prototype.block = function(){
  451. this.oMar = document.createElement("div");//创建遮罩层
  452. var obj,objLzl,data,oMarClone,
  453. listLength = GM_listValues().length,
  454. userLength = this.user.length,
  455. // userLzlLength = this.userLzl.length,
  456. config = {
  457. "blockWay": GM_getValue('setting-blockWay', defaultdConfig.blockWay),//屏蔽方式
  458. "color": GM_getValue('setting-col', defaultdConfig.color),//遮罩颜色
  459. "opacity": GM_getValue('setting-opa', defaultdConfig.opacity),//遮罩透明度
  460. "blur": GM_getValue('setting-gus', defaultdConfig.blurpx)//高斯模糊
  461. };
  462. $(this.oMar).attr("class","mar").css({
  463. "background":config.color,
  464. "opacity":config.opacity
  465. });
  466. for (var i = 0; i < listLength; i++) {//GM_listValues().length
  467. for(var j=0;j<userLength;j++){
  468. obj = this.list[j];//要屏蔽的模块
  469. if( GM_listValues()[i]==this.user[j].name ){
  470. if(blockMod()=="remove"){
  471. $(obj).css("display","none");
  472. }else if(blockMod()=="wrap"){
  473. if( $(obj).find(".mar").length >= 1 ){
  474. continue;
  475. }
  476. oMarClone = this.oMar.cloneNode(true);//克隆遮罩层
  477. //要屏蔽的模块
  478. $(obj).css({
  479. "position":"relative",
  480. "filter":"blur(" + config.blur +"px)",
  481. "-webkit-filter":"blur(" + config.blur +"px)",
  482. "-moz-filter":"blur(" + config.blur +"px)",
  483. "-o-filter":"blur(" + config.blur +"px)",
  484. "-ms-filter":"blur(" + config.blur +"px)",
  485. "backface-visibility":"hidden",
  486. "-webkit-backface-visibility":"hidden",
  487. "-moz-backface-visibility":"hidden",
  488. "-o-backface-visibility":"hidden",
  489. "-ms-backface-visibility":"hidden",
  490. });
  491. if (GM_listValues()[i] == this.user[j].name) {
  492. data = GM_getValue(GM_listValues()[i], '');
  493. }
  494. $(oMarClone).attr("data",data);
  495. obj.appendChild(oMarClone);
  496. }
  497. }
  498. }
  499. //屏蔽楼中楼
  500. // for(var k=0;k<userLzlLength;k++){
  501. // objLzl = this.listLzl[k];//要屏蔽的模块
  502. // if( GM_listValues()[i]==this.userLzl[k].name ){//如果匹配到
  503. // if(blockMod()=="remove"){
  504. // objLzl.style.display = "none";
  505. // }else if(blockMod()=="wrap"){
  506. // if( objLzl.querySelectorAll('.mar').length >= 1 ){
  507. // continue;
  508. // }
  509. // oMarClone = oMar.cloneNode(true);//克隆遮罩层
  510. // //要屏蔽的模块
  511. // objLzl.style.cssText = "position:relative;filter:blur(" + config.blur +"px);-webkit-filter:blur(" + config.blur + "px);-moz-filter:blur(" + config.blur + "px);-o-filter:blur(" + config.blur + "px);backface-visibility:hidden;-webkit-backface-visibility:hidden;-moz-backface-visibility:hidden;-ms-backface-visibility:hidden;";
  512. // if (GM_listValues()[i] == this.userLzl[k].name) {
  513. // data = GM_getValue(GM_listValues()[i], '');
  514. // }
  515. // oMarClone.setAttribute('data', data);
  516. // objLzl.appendChild(oMarClone);
  517. // }
  518. // }
  519. // }
  520. } //for,遍历屏蔽
  521. };
  522. //智能提示
  523. Init.prototype.autoTips = function(){
  524. var list = [],//储存所有用户名
  525. temp = {},
  526. str = "";
  527. for(var i=0;i<this.user.length;i++){
  528. if(typeof temp[this.user[i].name]=="undefined"){
  529. temp[this.user[i].name] = 1;
  530. list.push(this.user[i].name);
  531. }
  532. }
  533. for(var j=0;j<list.length;j++){
  534. str += '<option value="' + list[j] + '" />';
  535. }
  536. $("#lst").html(str);
  537. };
  538. //监听
  539. $().extend("ob",function(){
  540. var target = this.elements[0];
  541. return new Ob(target);
  542. });
  543. function Ob(target){
  544. this.MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  545. this.target = target;
  546. return this;
  547. }
  548. Ob.prototype.observer = function(config,fn){
  549. var MutationObserver = this.MutationObserver,
  550. observer = new MutationObserver(function(mutations){
  551. mutations.forEach(function(mutation) {
  552. fn.call(this.target);
  553. });
  554. });
  555. observer.observe(this.target, config);
  556. };
  557.  
  558. //拖拽
  559. $().extend("drag",function(pressTarget,MoveTarget,json){
  560. return new Drag(pressTarget,MoveTarget,json);
  561. });
  562. function Drag(pressTarget,MoveTarget,json){
  563. var _this = this;
  564. this.disX = 0;
  565. this.disY = 0;
  566. if(json){
  567. this.json = json;
  568. }
  569. this.MoveTarget = MoveTarget;
  570. pressTarget.onmousedown = function(e){
  571. _this.fnDown(e);
  572. return false;//chrome,firefox去除文字选中
  573. };
  574. }
  575. Drag.prototype.fnDown = function(e){//鼠标按下(未松开)
  576. var ev = e || window.event;
  577. var _this = this;
  578. this.disX = e.clientX - this.MoveTarget.offsetLeft;
  579. this.disY = e.clientY - this.MoveTarget.offsetTop;
  580. if(this.MoveTarget.setCaptrue){//IE,解决文字选中
  581. this.MoveTarget.onmousemove = function(ev){
  582. _this.fnMove(ev);
  583. };
  584. this.MoveTarget.onmouseup = function(){
  585. var this_ = this;
  586. _this.fnUp(this_);
  587. };
  588. this.MoveTarget.setCaptrue();//添加事件捕获
  589. }else{
  590. document.onmousemove = function(e){
  591. _this.fnMove(e);
  592. };
  593. document.onmouseup = function(){
  594. var this_ = this;
  595. _this.fnUp(this_);
  596. };
  597. }
  598. };
  599. Drag.prototype.fnMove = function(e){//鼠标移动,则div移动
  600. var ev = e || window.event;
  601. var L = this.json ? this.range(e.clientX - this.disX,this.json.L[0],this.json.L[1]) : (e.clientX - this.disX);
  602. var T = this.json ? this.range(e.clientY - this.disY,this.json.T[0],this.json.T[1]) : (e.clientY - this.disY);
  603. this.MoveTarget.style.left = L + 'px';
  604. this.MoveTarget.style.top = T + 'px';
  605. };
  606. Drag.prototype.fnUp = function(this_){//鼠标松开,则停止
  607. this_.onmousemove = null;
  608. this_.onmouseup = null;
  609. if( this_.setCaptrue ){
  610. this_.releaseCapture();//释放捕获
  611. }
  612. };
  613. Drag.prototype.range = function(iNow,iMin,iMax){
  614. if(iNow>iMax){
  615. return iMax;
  616. }else if(iNow<iMin){
  617. return iMin;
  618. }else{
  619. return iNow;
  620. }
  621. };
  622. //==============主要事件=================
  623. $(window).bind({
  624. "DOMContentLoaded":function(){
  625. //脚本初始化
  626. init().block();
  627. },
  628. "load":function(){
  629. init().block();
  630. //监听翻页
  631. if(position()=="post" ){
  632. $("#j_p_postlist").ob().observer({"childList":true},function(){
  633. init().block();
  634. });
  635. }else{
  636. $('thread_list').ob().observer({"childList":true},function(){//帖子列表
  637. init().block();
  638. });
  639. }
  640. }
  641. });
  642. $(document).bind('click',function(e){
  643. var target = e.target || e.srcElement,
  644. id=target.id || null;
  645. //如果点击到ID
  646. if ($(target).attr('data-field') && hasClass(target.parentNode, 'd_name') || $(target).attr('data-field') && hasClass(target.parentNode, 'tb_icon_author')) { //如果点到了名字上面
  647. (function(target){
  648. var data3,name,id,parent;
  649. if( $("#confirmBox") ){
  650. $("#confirmBox").remove();
  651. }
  652. if(hasClass(target.parentNode,"d_name")){
  653. parent = target.parentNode.parentNode.parentNode.parentNode;
  654. data3 = JSON.parse($(parent).attr("data-field")).author;
  655. name = data3.user_name;
  656. id = data3.user_id;
  657. }else{
  658. parent = target.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  659. data3 = JSON.parse($(parent).attr("data-field"));
  660. name = data3.author_name;
  661. id = data3.id;
  662. }
  663. var confirmBox = document.createElement("div");
  664. $(confirmBox).attr("id","confirmBox").html("<p>是否屏蔽</p><p>" + name + "</p><input type='button' value='确认' id='confirm-yes' /><input type='button' value='取消' id='confirm-no' />");
  665. document.documentElement.appendChild(confirmBox);
  666. $(confirmBox).animate({"top":"100","opacity":"100"},{"end":function(){
  667. clearTimeout(confirmBox.fadeOut);
  668. this.fadeOut=setTimeout(function(){
  669. $(confirmBox).animate({"top":"60","opacity":"0"},{"end":function(){
  670. $(this).remove();
  671. }});
  672. },3000);
  673. }});
  674. $('#confirm-yes').on('click',function(){
  675. GM_setValue(name,'{"name":"' + name + '","id":"' + id + '","bar":"' + barName() + '","reson":"不顺眼"}');
  676. init().block();
  677. confirmBox.remove(this);
  678. });
  679. $("#confirm-no").on('click',function(){
  680. confirmBox.remove(this);
  681. });
  682. })(target);
  683. //阻止默认事件和冒泡
  684. return false;
  685. }
  686. //屏蔽列表删除键
  687. else if( hasClass(target,"deletThis") ){
  688. var ele = $(target.parentNode.parentNode);
  689. var thisKey = JSON.parse(ele.attr('data-value')).name; //获取当前结点的key
  690. GM_deleteValue(thisKey); //删除变量
  691. ele.remove(); //删除节点
  692. }
  693. //如果点击到遮罩层
  694. else if (hasClass(target, 'mar')){
  695. $(".mar").html(" ");
  696. //获取data数据
  697. var data = JSON.parse($(target).attr('data'));
  698. //第一次点击
  699. if (!target.ready) {
  700. $(target).css({
  701. "border-left":"5px solid rgb(174, 103, 34)"
  702. });
  703. target.ready = true;
  704. // target.style.borderLeft = '5px solid rgb(174, 103, 34)';
  705. }
  706. //再次点击
  707. else if(target.ready === true){
  708. $(target.parentNode).css({
  709. "position":"relative",
  710. "-webkit-filter":"none",
  711. "-moz-filter":"none",
  712. "o-filter":"none",
  713. "ms-filter":"none",
  714. "filter":"none"
  715. });
  716. $(target).css({
  717. "background":"none",
  718. "opacity":"1",
  719. "filter":"alpha(opacity=100)"
  720. }).html('<input type="button" id="keeplock" value="继续屏蔽" /><input type="button" id="unlockNow" value="暂时解除 "/><input type="button" id="unlock" value="永久解除" />' + '<p>' + data.name + '(' + data.id + '),其在' + data.bar + '因[' + data.reson + ']被屏蔽' + '</p>');
  721. target.ready = null;
  722. }
  723. }
  724. else{
  725. switch(id){
  726. //解除屏蔽
  727. case "unlock" :
  728. var $ele1 = $(target.parentNode);
  729. var data2 = JSON.parse( $ele1.attr("data") );
  730. GM_deleteValue(data2.name); //删除键名
  731. $ele1.remove();
  732. break;
  733. //暂时解除
  734. case "unlockNow" :
  735. target.parentNode.remove(this);
  736. break;
  737. //继续屏蔽
  738. case "keeplock" :
  739. var targetParent = target.parentNode;
  740. var config = {
  741. "blockWay": GM_getValue('setting-blockWay', defaultdConfig.blockWay),//屏蔽方式
  742. "color": GM_getValue('setting-col', defaultdConfig.color),//遮罩颜色
  743. "opacity": GM_getValue('setting-opa', defaultdConfig.opacity),//遮罩透明度
  744. "blur": GM_getValue('setting-gus', defaultdConfig.blurpx)//高斯模糊
  745. };
  746. $(targetParent.parentNode).css({
  747. "position":"relative",
  748. "filter":"blur(" + config.blur +"px)",
  749. "-webkit-filter":"blur(" + config.blur + "px)",
  750. "-moz-filter":"blur(" + config.blur + "px)",
  751. "-o-filter":"blur(" + config.blur + "px)",
  752. "-ms-filter":"blur(" + config.blur + "px)",
  753. "backface-visibility":"hidden",
  754. "-webkit-backface-visibility":"hidden",
  755. "-moz-backface-visibility":"hidden",
  756. "-o-backface-visibility":"hidden",
  757. "-ms-backface-visibility":"hidden"
  758. });
  759. $(targetParent).css({
  760. "opacity":config.opacity,
  761. "background":config.color,
  762. "border":"none"
  763. }).html(" ");
  764. break;
  765. //退出
  766. case "queit" :
  767. $('#pannal,#wrap').remove();
  768. document.body.className = '';
  769. break;
  770. case "wrap" :
  771. $('#pannal,#wrap').remove();
  772. document.body.className = '';
  773. break;
  774. //保存
  775. case "save" :
  776. //判断屏蔽方式
  777. GM_setValue('setting-blockWay', $("#blockWay").value() );
  778. //遮罩颜色
  779. GM_setValue('setting-col', $("#col").value() );
  780. //遮罩透明度1
  781. GM_setValue('setting-opa', $('#opa').value() );
  782. //高斯模糊半径
  783. GM_setValue('setting-gus', $('#gus').value());
  784. //添加黑名单
  785. var name = $('#userName').value();
  786. if(name === "" || name === null){
  787. return;
  788. }
  789. GM_setValue($('#userName').value(), '{"name":"' + $('#userName').value() + '","id":"' + $("#userId").value() + '","bar":"' + $("#curBar").value() + '","reson":"' + $("#reson").value() + '"}');
  790. init().block();
  791. createList();//重新生成列表
  792. break;
  793. //初始化
  794. case "clear" :
  795. clearall();
  796. createList();
  797. break;
  798. default:
  799. return;
  800. }
  801. }
  802. });
  803.  
  804. $(document).bind('input',function(e){
  805. var target = e.target || e.srcElement,
  806. id = target.id;
  807. switch(id){
  808. case "sear" :
  809. searchInList();
  810. break;
  811. case "opa" :
  812. $('#opa-text').html( $('#opa').value() );
  813. break;
  814. case "gus" :
  815. $('#gus-text').html( $('#gus').value() );
  816. break;
  817. case "userName" :
  818. if( $("#lst").html() === "" || $("#lst").html() === null ){
  819. init().autoTips();
  820. }
  821. break;
  822. default :
  823. return;
  824. }
  825. });
  826.  
  827. $(window).bind('keyup',function(e){
  828. var target = e.target || e.srcElement;
  829. if(e.keyCode==8){//backspace
  830. if ( target.id=="sear" && target.value === '') {
  831. createList();
  832. return;
  833. }
  834. }else if(e.ctrlKey && e.keyCode == 114){//快捷键ctrl+F3
  835. if( $("#pannal").length>=1 ){
  836. return;
  837. }
  838. var oFragment = document.createDocumentFragment(),//创建文档碎片
  839. pannal = document.createElement('div'),//控制面板
  840. pannal_wrap = pannal.cloneNode(false),//遮罩层
  841. config = {
  842. "blockWay": GM_getValue('setting-blockWay', defaultdConfig.blockWay),//屏蔽方式
  843. "color": GM_getValue('setting-col', defaultdConfig.color),//遮罩颜色
  844. "opacity": GM_getValue('setting-opa', defaultdConfig.opacity),//遮罩透明度
  845. "blur": GM_getValue('setting-gus', defaultdConfig.blurpx)//高斯模糊
  846. };
  847. $(pannal_wrap).attr("id","wrap");
  848. $(pannal).attr("id","pannal");
  849. pannal.innerHTML = '\
  850. <h3 id="pannal-tittle" style="cursor:move;font-size:20px;line-height:20px;color:#fff;background:#165557;">配置参数</h3>\
  851. <div id="pannal-setting">\
  852. 屏蔽方式:<select id="blockWay">\
  853. <option>遮罩屏蔽</option>\
  854. <option>删除节点</option>\
  855. </select><br/>\
  856. 遮罩层颜色:<input id="col" type="color" value="'+config.color+'" /><br/>\
  857. 遮罩透明度(0~1):<span id="opa-text">'+config.opacity+'</span><input id="opa" type="range" value="'+config.opacity+'" min="0" max="1" step="0.1" /><br/>\
  858. 高斯模糊像素(0~10):<span id="gus-text">'+config.blur+'</span><input id="gus" type="range" value="'+config.blur+'" min="0" max="10" step="1" /><br/>\
  859. </div>\
  860. <hr/>\
  861. <h3>添加讨厌鬼</h3>\
  862. <div id="addBlackList">\
  863. 数字ID(选填):<input id="userId" type="text" placeholder="user_id"/><br/>\
  864. 贴吧ID(必填):<input id="userName" type="text" placeholder="user_name" list="lst" autocomplete="off"/><br/>\
  865. <datalist id="lst" autocomplete="on"></datalist>\
  866. 所在贴吧:<input id="curBar" type="text" value="'+barName()+'" /><br/>\
  867. 屏蔽原因:<input id="reson" type="text" list="lstr" value="" />\
  868. </div>\
  869. <hr/>\
  870. <h3>功能</h3>\
  871. <div id="fn">\
  872. <input id="save" type="button" value="保存" />\
  873. <input id="clear" type="button" value="初始化" />\
  874. <input id="view" type="button" value="列表" />\
  875. </div>\
  876. <div id="list" style="margin:0;">\
  877. <input id="sear" type="text" list="BlackList" placeholder="搜索" autocomplete="off" />\
  878. <table id="showList"></table>\
  879. </div>\
  880. <span id="queit">X</span>\
  881. ';
  882. oFragment.appendChild(pannal);
  883. oFragment.appendChild(pannal_wrap);
  884. document.body.className = 'blur';
  885. document.documentElement.appendChild(oFragment);
  886. //居中
  887. $(pannal).css({
  888. "top": ($().size('clientHeight') - pannal.offsetHeight) / 2 + "px",
  889. "left":($().size('clientWidth') - pannal.offsetWidth) / 2 + "px"
  890. });
  891. //初始化数据
  892. $('#blockWay').attr('value',GM_getValue('setting-blockWay', defaultdConfig.blockWay) );//屏蔽方式
  893. //生成屏蔽名单列表
  894. createList();
  895. //可拖拽
  896. $().drag( $('#pannal-tittle').get(0),pannal );
  897. //展开收起
  898. $('#view').toggle(function(){
  899. $('#list').animate({
  900. // "height":parseInt( $('#pannal').style("height") )
  901. "height":parseInt( pannal.offsetHeight )
  902. });
  903. },function(){
  904. $('#list').animate({"height":"0"});
  905. });
  906. }
  907. });
  908.  
  909.  
  910.  
  911. //==============样式=================
  912. var style = '\
  913. body{\
  914. -webkit-backface-visibility: hidden;\
  915. }\
  916. /*给body添加滤镜*/\
  917. .blur{\
  918. -webkit-filter: blur(5px) grayscale();\
  919. -moz-filter: blur(5px) grayscale();\
  920. -o-filter: blur(5px) grayscale();\
  921. -ms-filter: blur(5px) grayscale();\
  922. filter: blur(5px) grayscale();\
  923. }\
  924. #pannal{\
  925. width:200px;\
  926. height:auto;\
  927. background:rgba(38, 50, 56, 1);\
  928. color:#fff;\
  929. position:fixed;\
  930. z-index:1000000000;\
  931. text-align:center;\
  932. box-shadow:0 0 20px 5px #000000;\
  933. }\
  934. #pannal>div{\
  935. margin:10px 0;\
  936. }\
  937. #pannal input{\
  938. color:#3e3e3e;\
  939. border:1px solid transparent;\
  940. height:20px;\
  941. line-height:20px;\
  942. }\
  943. #pannal input:focus{\
  944. background-color:rgba(38, 50, 56, 1);\
  945. color:#fff;\
  946. border:1px solid;\
  947. transition:all 0.2s ease-in-out;\
  948. }\
  949. #pannal h3{\
  950. color:rgb(0, 255, 226);\
  951. }\
  952. #pannal-setting input[type=range]{\
  953. width:80%;\
  954. }\
  955. #fn input{\
  956. padding:10px;\
  957. margin:0 5px;\
  958. cursor:pointer;\
  959. }\
  960. #fn input:hover{\
  961. background:#004d40;\
  962. color:#fff;\
  963. }\
  964. #pannal>span{\
  965. position:absolute;\
  966. width:21px;\
  967. height:21px;\
  968. line-height:21px;\
  969. font-size:21px;\
  970. top:0;\
  971. right:0;\
  972. cursor:pointer;\
  973. opacity:0.8;\
  974. background:#fff;\
  975. color:#303030;\
  976. }\
  977. #blockWay{\
  978. color:#3e3e3e;\
  979. border:none;\
  980. }\
  981. #wrap{\
  982. position:fixed;\
  983. width:100%;\
  984. height:100%;\
  985. background:rgba(155, 155, 155,0.5);\
  986. top:0;\
  987. left:0;\
  988. z-index:999999999;\
  989. }\
  990. .mar{\
  991. width:100%;\
  992. height:100%;\
  993. position:absolute;\
  994. top:0;\
  995. left:0;\
  996. z-index:999999998;\
  997. -webkit-backface-visibilityhidden;\
  998. text-align:center;\
  999. font-size:16px;\
  1000. }\
  1001. .mar input{\
  1002. background:#303030;\
  1003. color:#fff;\
  1004. padding:5px 10px;\
  1005. margin:5px 10px;\
  1006. font-family:"宋体";\
  1007. font-size:14px;\
  1008. border:none;\
  1009. }\
  1010. .mar input:hover{\
  1011. background:#004d40;\
  1012. transition:all 0.2s ease-in-out;\
  1013. }\
  1014. .mar p{\
  1015. color:##2B2929;\
  1016. font-weight:bold;\
  1017. background-color:rgba(72, 70, 70, 0.35);\
  1018. line-height:30px;\
  1019. width:60%;\
  1020. margin:0 auto;\
  1021. }\
  1022. .mar p:hover{\
  1023. color:#fff;\
  1024. background-color:#004d40;\
  1025. transition:all 0.2s ease-in-out;\
  1026. }\
  1027. #list{\
  1028. position:absolute;\
  1029. top:0;\
  1030. left:200px;\
  1031. width:400px;\
  1032. height:0;\
  1033. overflow-x:hidden;\
  1034. overflow-y:auto;\
  1035. background:inherit;\
  1036. margin:0;\
  1037. }\
  1038. #list tr:hover{\
  1039. background:#004d40;\
  1040. transition:all 0.2s ease-in-out;\
  1041. }\
  1042. .key{\
  1043. float:left;\
  1044. clear:both;\
  1045. margin-left:10px;\
  1046. width:120px;\
  1047. text-align:left;\
  1048. overflow:hidden;\
  1049. text-overflow:ellipsis;\
  1050. white-space:nowrap;\
  1051. }\
  1052. .col{\
  1053. border:none;\
  1054. }\
  1055. .deletThis{\
  1056. float:right;\
  1057. cursor:pointer;\
  1058. margin-right:10px;\
  1059. padding:0 5px;\
  1060. border:0;\
  1061. height:18px;\
  1062. }\
  1063. .disable-btn{\
  1064. background:#6B6B6B;\
  1065. cursor:not-allowed;\
  1066. }\
  1067. #addBlackList input{\
  1068. width:80%;\
  1069. }\
  1070. /*userName列表*/\
  1071. #thread_list>li[data-field] .threadlist_lz>.threadlist_author:hover,.l_post .d_name:hover{\
  1072. background:#004d40;\
  1073. transition:all 0.2s ease-in-out;\
  1074. }\
  1075. #sear{\
  1076. position:relative;\
  1077. margin:0 auto;\
  1078. text-align:center;\
  1079. height:21px;\
  1080. width:100%;\
  1081. border:none;\
  1082. }\
  1083. #confirmBox{\
  1084. width:300px;\
  1085. background:rgba(5, 49, 43, 0.8);\
  1086. position:fixed;\
  1087. left:50%;\
  1088. top:60px;\
  1089. margin-left:-150px;\
  1090. text-align:center;\
  1091. z-index:999999;\
  1092. opacity:0;\
  1093. box-shadow:1px 1px 10px 2px #000000;\
  1094. }\
  1095. #confirmBox input{\
  1096. border:none;\
  1097. padding:10px 30px;\
  1098. margin:10px;\
  1099. cursor:pointer;\
  1100. }\
  1101. #confirmBox input:hover{\
  1102. background:#004d40;\
  1103. transition:all 0.2s ease-in-out;\
  1104. }\
  1105. #confirmBox p{\
  1106. font-size:18px;\
  1107. color:#fff;\
  1108. margin-top:20px;\
  1109. }\
  1110. ';
  1111. GM_addStyle(style);
  1112. })(window,document);