Baidu Zhidao Thread Notification

在贴吧对来自百度知道的贴子进行提醒和删除。

  1. // ==UserScript==
  2. // @name Baidu Zhidao Thread Notification
  3. // @version 1.1
  4. // @description 在贴吧对来自百度知道的贴子进行提醒和删除。
  5. // @match http://tieba.baidu.com/p/*
  6. // @match http://tieba.baidu.com/f?*z=*
  7. // @include http://tieba.baidu.com/p/*
  8. // @include http://tieba.baidu.com/f?*z=*
  9. // @author 864907600cc
  10. // @grant none
  11. // @run-at document-end
  12. // @icon http://1.gravatar.com/avatar/147834caf9ccb0a66b2505c753747867
  13. // @namespace https://greasyfork.org/users/141
  14. // ==/UserScript==
  15.  
  16. // 贴子判断方式由 8qwe24657913 提供
  17. // 本脚本基于 GPLv3 协议开源 http://www.gnu.org/licenses/gpl.html‎
  18. // (c) 86497600cc. Some Rights Reserved.
  19.  
  20.  
  21. var context='警告:该贴子来自百度知道!'; // 此处定义提醒文字
  22. var class_name='zhidao_thread_notification'; // 此处定义框架的 class
  23. var stylesheet='.zhidao_thread_notification{-webkit-animation:"kill_17" 1s ease-in;animation:"kill_17" 1s ease-in;width:100%;height:75px;line-height:75px;position:fixed;z-index:99999;bottom:0px;left:0px;pointer-events:none;background:rgba(255,0,0,0.5);font-size:32px;color:#FFF;text-shadow:0 0 5px #F00;text-align:center}@-webkit-keyframes kill_17{from{opacity:0;bottom:-50px}to{opacity:1;bottom:0px}}@keyframes kill_17{from{opacity:0;bottom:-50px}to{opacity:1;bottom:0px}}'; // 此处定义样式表(请使用完整样式表,而不是仅提供属性)
  24. var kill=0; // 此处定义是否自动删除来自知道的贴子,0 为不删除,1 为删除,需要吧务权限,默认不开启
  25. var kill_timeout=3000; // 此处定义执行删除操作的等待时间,单位为毫秒,需开启自动删除
  26. var close_tiemout=3000; // 此处定义执行删除操作成功后关闭页面的等待时间,单位为毫秒,需开启自动删除
  27.  
  28. // 下面的内容除非特殊需要请不要修改
  29. // GM_addStyle(stylesheet) // 为什么加上这货在 Firefox 上就显示不了,即便设定了 @grant _(:з」∠)_
  30. var ss=document.createElement('style');
  31. ss.textContent=stylesheet;
  32. document.head.appendChild(ss);
  33.  
  34. if(PageData.thread.thread_type=='17'){
  35. var node=document.createElement('div');
  36. node.textContent=context;
  37. node.className=class_name;
  38. document.body.appendChild(node);
  39. if(kill==1&&(PageData.user.bawu==1||PageData.user.bawu==2)){
  40. var xhr=new XMLHttpRequest(),
  41. form=new FormData();
  42. setTimeout(function(){
  43. node.textContent='正在删除贴子……';
  44. form.append('commit_fr','pb');
  45. form.append('ie','utf-8');
  46. form.append('kw',PageData.forum_name);
  47. form.append('fid',PageData.forum_id);
  48. form.append('tid',PageData.thread.id);
  49. form.append('tbs',PageData.tbs); // 居然不需要额外获取 tbs……
  50. xhr.onreadystatechange=function(){
  51. if(xhr.readyState==4&&xhr.status==200){
  52. var callback=JSON.parse(xhr.responseText);
  53. if(callback.err_code==0){
  54. node.textContent='该贴子已删除,稍后关闭该页面……';
  55. setTimeout(function(){
  56. window.open('','_self','');
  57. window.close();
  58. },close_tiemout)
  59. }
  60. else{
  61. node.textContent='贴子删除失败,错误码:'+callback.err_code;
  62. console.error('贴子删除失败,错误码:'+callback.err_code+',错误信息:'+callback.error);
  63. }
  64. }
  65. }
  66. xhr.open('POST','http://tieba.baidu.com/f/commit/thread/delete');
  67. xhr.send(form);
  68. },kill_timeout)
  69. }
  70. }