Tieba Common

Common JS for Baidu scripts by Gerald

目前为 2014-07-13 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/144/9622/Tieba%20Common.js

  1. // ==UserScript==
  2. // @name Tieba Common
  3. // @namespace http://gera2ld.blog.163.com/
  4. // @author Gerald <gera2ld@163.com>
  5. // @description Common JS for Baidu scripts by Gerald
  6. // ==/UserScript==
  7.  
  8. var $=unsafeWindow.$,PageData=unsafeWindow.PageData,utils=null;
  9. (function(){
  10. function getObj(key,def){
  11. var v=(ff||window)[key];
  12. if(v==null&&def!=null) setObj(key,v=def);
  13. return v;
  14. }
  15. function setObj(key,val){(ff||window)[key]=val;}
  16. function notice(title,msg){
  17. var n=getObj('msg',{});
  18. if(!n[title]) {
  19. n[title]=1;
  20. var d=document.createElement('div');
  21. d.setAttribute('style','position:fixed;z-index:999999;background:white;border:1px solid;border-radius:3px;padding:10px;top:50px;left:50px;');
  22. d.innerHTML='<a href=# style="float:right">关闭</a><h3>'+title+'</h3>'+msg;
  23. document.body.appendChild(d);
  24. d.firstChild.onclick=function(e){
  25. e.preventDefault();d.parentNode.removeChild(d);
  26. };
  27. return d;
  28. }
  29. }
  30. var ff=null,key='__ge_firefox', // For Greasemonkey or Scriptish
  31. firefox=/Firefox\//.test(navigator.userAgent);
  32. //if(firefox) {
  33. ff=unsafeWindow[key];
  34. if(!ff) ff=unsafeWindow[key]={};
  35. //}
  36. utils=getObj('utils');
  37. if(!utils)
  38. notice('未检测到依赖脚本!','请确认已安装并启用:<br><a target=_blank href=https://greasyfork.org/scripts/118>Tieba Utilities</a><br><p align=right>——寂寞的原子</p>');
  39. if(firefox) this.injectScript=function(s) {
  40. var c=document.createElement('script');
  41. c.innerHTML=s;c.async=true;
  42. document.body.appendChild(c);
  43. document.body.removeChild(c);
  44. }
  45. })();