Tieba Advanced

贴吧增强 - Gerald倾情打造

目前为 2014-05-17 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Tieba Advanced
  3. // @namespace http://gera2ld.blog.163.com/
  4. // @author Gerald <gera2ld@163.com>
  5. // @icon http://s.gravatar.com/avatar/a0ad718d86d21262ccd6ff271ece08a3?s=80
  6. // @version 2.7.5.1
  7. // @description 贴吧增强 - Gerald倾情打造
  8. // @homepage http://geraldl.ml/UserJS/TiebaAdvanced
  9. // @include http://tieba.baidu.com/*
  10. // @exclude http://tieba.baidu.com/tb/*
  11. // @require https://greasyfork.org/scripts/144/code.user.js
  12. // ==/UserScript==
  13.  
  14. var mask=$('<div class=ge_mask style="padding:100px 100px 20px;">').appendTo('body'); // Mask layer
  15. // Arrays for Lzl initiation
  16. var lzl_init=[],lzl_buttons=[],lzl_styles=[],lzl_efilters=[];
  17. addPButton=function(o,c,m,a) { // 新增楼中楼按钮
  18. lzl_styles=lzl_styles.concat(c);o.addClass(c[0]);
  19. if(!a) a={};if(!a.after) a.after='.lzl_panel_submit';
  20. lzl_buttons.push([o,m,a]);
  21. return o;
  22. };
  23. DELAY=2000;
  24.  
  25. // 初始化贴子管理面板
  26. function initPostManager() {
  27. if(utils.postManager) return;
  28. utils.addStyle('\
  29. #ge_tm{display:none;border-collapse:separate;width:100%;height:100%;background:white;color:#333;padding:20px;border-radius:20px;shadow:0 1px 5px #333;border-spacing:5px;table-layout:fixed;}\
  30. #ge_tm tr{height:1px;}\
  31. #ge_tm tr.ge_td{height:auto;}\
  32. .ge_td>td{width:50%;height:100%;vertical-align:top;position:relative;}\
  33. .ge_td>td>*{width:100%;height:100%;border:1px solid;overflow:auto;background:transparent;'+(window.opera?'position:absolute;':'')+'}\
  34. ');
  35. var tm=$('<table id=ge_tm>').appendTo(mask);
  36. tm.listItems=function(t,e,x,s){
  37. var d=[];
  38. if(x) d.push('<option>'+x+'</option>');
  39. t.list.forEach(function(i){d.push('<option>'+i.name+'</option>');});
  40. e.html(d.join(''));
  41. if(s) {x=x?1:0;t.load(s-x);e.prop('selectedIndex',t.last+x);}
  42. };
  43. tm.newItem=function(e,d) {
  44. tm.list.load(tm.list.length-1);
  45. if(!tm.list.cur||tm.list.cur.data) {
  46. tm.list.load(tm.list.push(d));
  47. $('<option>').appendTo(ti).text(tm.list.cur.name);
  48. } else {
  49. tm.list.cur.type=d.type;
  50. tm.list.cur.data=d.data;
  51. }
  52. $(ti).prop('selectedIndex',tm.list.last);
  53. editItem();
  54. };
  55. var th=document.createElement('p'),tk='innerText' in th?'innerText':'textContent';
  56. function h2t(h){ // html to text
  57. th.innerHTML=h.replace(/<br>/g,'\n');
  58. return th[tk];
  59. }
  60. function t2h(t){ // text to html
  61. th[tk]=t;
  62. return th.innerHTML.replace(/ /g,'&nbsp; ').replace(/(^| ) /g,'&nbsp;$1').replace(/\r?\n/g,'<br>');
  63. }
  64. function editItem(e) {
  65. if(e) tm.list.load(ti.prop('selectedIndex'),1);
  66. var t=tm.list.cur;
  67. tc.prop('disabled',!t);
  68. if(!t) t={type:'s',data:''};
  69. tt.val(t.type);
  70. if(['j','h','H'].indexOf(t.type)>=0) tc.val(t.data);
  71. else tc.val(h2t(t.data));
  72. liveShow();
  73. }
  74. function saveItem(e) {
  75. var t=tm.list.cur;if(!t) return;
  76. switch(t.type=tt.val()) {
  77. case 'j':try{eval(t.data=tc.val());}catch(e){}break;
  78. case 's':t.data=t2h(tc.val());break;
  79. case 'H':t.data=tc.val();break;
  80. default:tv.find('img').each(function(i,e){
  81. e.setAttribute('pic_type',1);
  82. unsafeWindow.EditorUI.resizeImage(e,560);
  83. });
  84. tc.val(t.data=tv.html());
  85. }
  86. }
  87. function liveShow(e) {
  88. function show() {
  89. if(--count) return;
  90. var t=tt.val(),s;
  91. if(t=='j') try{s=eval(tc.val());}catch(e){s='<font color=red>JS代码有误!</font>';}
  92. else s=tc.val();
  93. if(t=='s') s=t2h(s);
  94. else if(t=='H') s=s.split('\n').shift();
  95. tv.html(s);
  96. }
  97. count++;
  98. setTimeout(show,500);
  99. }
  100. var count=0;
  101. tm.loadPanel=function(t,n,c) {
  102. tm.list=t;tn.text(n);tm.callback=c;
  103. tm.listItems(t,ti);editItem(1);
  104. mask.fadeIn('fast',function() {
  105. tm.css({display:'table'}).animate({top:'0px',left:'0px'},300);
  106. });
  107. };
  108. var c=$('<td colspan=2>').appendTo($('<tr>').appendTo(tm)),
  109. tn=$('<strong class=ge_rsep>').appendTo(c),
  110. ti=$('<select>').appendTo(c).change(editItem);
  111. $('<span class="ge_sbtn ge_rsep">改名</span>').appendTo(c).click(function(e) {
  112. if(!tm.list.cur) return;
  113. var t=prompt('修改名称:',tm.list.cur.name);
  114. if(t) {tm.list.cur.name=t;ti.children('option:eq('+tm.list.last+')').text(t);}
  115. });
  116. var tt=$('<select>').appendTo($('<label class=ge_rsep>类型:'+utils.getLink('advanced',{title:'帮助',html:'(?)'})+'</label>').appendTo(c)).html('<option value="s" checked>普通字串</option><option value="h">HTML代码</option><option value="H">HTML随机</option><option value="j">JS代码</option>').change(liveShow).blur(saveItem);
  117. $('<span class=ge_sbtn>添加</span>').appendTo(c).click(tm.newItem);
  118. $('<span class=ge_sbtn>删除</span>').appendTo(c).click(function() {
  119. var l=tm.list.last;tm.list.pop(l);ti.children().eq(l).remove();editItem(1);
  120. });
  121. c=$('<div style="float:right;"></div>').appendTo(c);
  122. $('<span class=ge_sbtn>关闭</span>').appendTo(c).click(function() {
  123. tm.list.save();if(tm.callback) tm.callback();
  124. tm.animate({top:innerHeight+'px'},300,function() {$(this).hide();mask.fadeOut('fast');});
  125. });
  126. $('<tr><td>编辑框</td><td align=right>预览框</td></tr>').appendTo(tm);
  127. c=$('<tr class=ge_td>').appendTo(tm);
  128. var tc=$('<textarea>').appendTo($('<td>').appendTo(c)).blur(saveItem).keyup(liveShow).mouseup(liveShow);
  129. var tv=$('<div>').appendTo($('<td>').appendTo(c));
  130. utils.postManager=tm;
  131. }
  132. // 灌水
  133. function initAddWater(editor) {
  134. initPostManager();
  135. var tails=utils.list('tails',null,function(){return {type:'s',data:'',name:'新尾巴'};},[
  136. {type:'j',name:'UA',data:'"——我喂自己袋盐<br>&gt;&gt;"+navigator.userAgent'},
  137. {type:'h',name:'求妹纸',data:'<img pic_type="1" class="BDE_Image" src="http://imgsrc.baidu.com/forum/w%3D580/sign=6ca77dcee5dde711e7d243fe97edcef4/b03533fa828ba61e111605e44134970a314e5905.jpg" width="560" height="11"><br><img pic_type="1" src="http://static.tieba.baidu.com/tb/editor/images/tsj/t_0010.gif" class="BDE_Smiley" height="40" width="40">求妹纸~'},
  138. ]).load(),water=utils.list('water',null,function(){return {type:'s',data:'',name:'新水贴'};},[
  139. {type:'s',name:'打酱油',data:'我是打酱油的~'},
  140. ]).load();
  141. function initTails(){utils.postManager.listItems(tails,ti,'随机',utils.getObj('tailindex',1));}
  142. function initWater(){utils.postManager.listItems(water,wi,'随机',utils.getObj('waterindex',0));}
  143. function getItem(t,s){
  144. var l=s.prop('selectedIndex'),L=t.length;if(!L) return;
  145. if(!l) l=Math.floor(Math.random()*L); else l--;
  146. t=t.list[l];var d=t.data;
  147. if(t.type=='j') d=eval(d);
  148. else if(t.type=='H') {d=d.split('\n');d=d[Math.floor(Math.random()*d.length)];}
  149. return d;
  150. }
  151. var op=utils.addPopup($('#tb_rich_poster'),utils.addSButton('灌 水')).panel;
  152. $('<div class=ge_sbtn style="cursor:default">智能灌水</div>').appendTo(op);
  153. var ti=$('<select class=ge_rsep>').appendTo($('<label>尾巴:</label>').appendTo(op)).change(function(e){utils.setObj('tailindex',this.selectedIndex);});
  154. $('<br>').appendTo(op);
  155. var tail=utils.bindProp($('<input type=checkbox>').prependTo($('<label class=ge_rsep>自动附加尾巴</label>').appendTo(op)),'checked','usetail',true);
  156. $('<br>').appendTo(op);
  157. $('<span class=ge_sbtn>存为新尾巴</span>').appendTo(op).click(function(e){
  158. utils.postManager.loadPanel(tails,'尾巴管理',initTails);
  159. utils.postManager.newItem(e,{type:'h',name:'新尾巴',data:editor.$body.html()});
  160. });
  161. $('<span class=ge_sbtn>管理</span>').appendTo(op).click(function(e){utils.postManager.loadPanel(tails,'尾巴管理',initTails);});
  162. $('<hr>').appendTo(op);
  163. var wi=$('<select class=ge_rsep>').appendTo($('<label>水贴:</label>').appendTo(op)).change(function(e){utils.setObj('waterindex',this.selectedIndex);});
  164. $('<br>').appendTo(op);
  165. $('<span class=ge_sbtn>存为新水贴</span>').appendTo(op).click(function(e){
  166. utils.postManager.loadPanel(water,'水贴管理',initWater);
  167. utils.postManager.newItem(e,{type:'h',name:'新水贴',data:editor.$body.html()});
  168. });
  169. $('<span class=ge_sbtn>管理</span>').appendTo(op).click(function(e){utils.postManager.loadPanel(water,'水贴管理',initWater);});
  170. $('<br>').appendTo(op);
  171. $('<span class=ge_sbtn>载入</span>').appendTo(op).click(function(e){
  172. editor.execCommand('inserthtml',getItem(water,wi));
  173. });
  174. $('<span class=ge_sbtn>发表</span>').appendTo(op).click(function(e){
  175. editor.$body.html(getItem(water,wi));
  176. unsafeWindow.test_poster.post();
  177. });
  178. /*$('<span class=ge_sbtn>人工置顶</span>').appendTo(op).click(function(e){
  179. function post(){PostHandler.post(rich_postor._option.url,b,delay,function(){});}
  180. function delay(m){
  181. if(m) {
  182. if(m.no) d+=1000; else {d=DELAY;e.text('停止('+(++c)+')');}
  183. }
  184. if(!m||!m.no) b.content=getItem(water,wi);
  185. setTimeout(post,d);
  186. }
  187. (e=$(this)).unbind('click').text('停止').click(function(){location.reload();});
  188. var c=0,d=0;b=rich_postor._getData();delay();
  189. });*/
  190. var tailed=false;
  191. utils.hook(unsafeWindow.test_poster,'post',{before:function(){
  192. var t=getItem(tails,ti);
  193. if(!tail.prop('checked')||!t||tailed) return;
  194. editor.$body.append('&nbsp;<br><br>'+t);tailed=true; // 加个空格以免破坏@
  195. }});
  196. initTails();initWater();
  197. }
  198.  
  199. // 尾页直达功能
  200. function initLastPage() {
  201. utils.addStyle('.threadlist_rep_num{cursor:pointer;}');
  202. $('.threadlist_rep_num').prop('title','直达尾页').click(function(e){
  203. e=$(e.target);e.unbind('click');
  204. var s='',d=JSON.parse(e.parents('.j_thread_list').attr('data-field'));
  205. setInterval(function(){
  206. if(s.length>2) s=''; else s+='.';
  207. e.html(s);
  208. },300);
  209. d='/p/'+d.id;
  210. $.get(d,function(data){
  211. var m=data.match(/共<span class="red">(\d+)/)[1];
  212. if(m=='1') m=''; else m='?pn='+m;
  213. location.href=d+m;
  214. });
  215. });
  216. }
  217.  
  218. // 召唤术增强
  219. var calllist=utils.list('calllist','calllast',function(){return {name:'新列表',data:[]};},true).load(),
  220. purl='http://imgsrc.baidu.com/forum/pic/item/fcb4c3fdfc039245664e092a8594a4c27c1e2592.jpg';
  221. function initCard() {
  222. function fix(){
  223. var t=this._j_card,c=calllist.cur.data;
  224. setTimeout(function(){
  225. function updateCSS(e) {e.css('background-position',j<0?'0 0':'-62px 0');}
  226. var u=t.getData().un,j=c.indexOf(u),w=t.find('.interaction_wrap'),a;
  227. if(w.length) updateCSS(a=$('<a href=# style="background:url('+purl+') no-repeat scroll 0 0">').appendTo(w).click(function(e){
  228. e.preventDefault();
  229. if(j<0) {j=c.length;c.push(u);}
  230. else {for(;j<c.length-1;j++) c[j]=c[j+1];c.pop();j=-1;}
  231. calllist.save();
  232. updateCSS(a);
  233. }));
  234. },0);
  235. }
  236. unsafeWindow._.Module.use("ihome/widget/UserVisitCard",{},function(b){
  237. utils.hook(b.__proto__,'buildVisitCard',{before:function(){
  238. utils.hook(this._visit_card,'setContent',{after:fix});
  239. }});
  240. });
  241. }
  242. function initCall(editor) {
  243. var pl,sl,be,bs,c=calllist;
  244. utils.addStyle('\
  245. #callList{border:1px solid;height:125px;overflow:auto;background:white;width:380px;margin:0 auto;}\
  246. #callList a{padding:2px;border-radius:2px;margin:2px;display:inline-block;}\
  247. #callList a.selected{background:limegreen;color:white}\
  248. .edui-btn-toolbar .edui-btn .call_list,.lzl_panel_call{background:url("'+purl+'") no-repeat scroll transparent -124px 0;width:21px;}\
  249. .lzl_panel_call{height:20px;width:22px;float:right;}\
  250. ');
  251. function newList(e) {
  252. c.load(c.push());$('<option>').appendTo(sl).text(c.cur.name);
  253. sl.prop('selectedIndex',c.last);
  254. editList(e);
  255. }
  256. function editList(e) {
  257. if(e) c.load(sl.prop('selectedIndex')); else sl.prop('selectedIndex',c.last);
  258. pl.empty();
  259. c.cur.data.forEach(function(i){$('<a href=#>').html(i).appendTo(pl);});
  260. pl.prop('contenteditable',false);
  261. }
  262. function loadLists(p) {
  263. var op=p.panel;
  264. c.load();op.empty();
  265. $('<div class=ge_sbtn style="cursor:default">超级召唤</div>').appendTo(op);
  266. sl=$('<select>').appendTo($('<label>选择名单:</label>').appendTo(op)).change(editList);
  267. $('<span class="ge_sbtn ge_rsep">改名</span>').appendTo(op).click(function(e) {
  268. e.preventDefault();
  269. var t=prompt('列表名称:',c.cur.name);
  270. if(t) {sl.children(':eq('+c.last+')').text(t);c.cur.name=t;c.save();}
  271. });
  272. $('<span class=ge_sbtn>新建列表</span>').appendTo(op).click(newList);
  273. $('<span class="ge_sbtn ge_rsep">删除列表</span>').appendTo(op).click(function(e){
  274. e.preventDefault();
  275. var l=c.last;c.pop(l);editList();sl.children().eq(l).remove();
  276. });
  277. pl=$('<div id=callList>').appendTo(op).click(function(e){
  278. e.preventDefault();
  279. e=e.target;if(e.tagName=='A') $(e).toggleClass('selected');
  280. }).dblclick(function(e){
  281. e.stopPropagation();
  282. var s=window.getSelection();
  283. if(!s.rangeCount) return;
  284. var r=s.getRangeAt(0),c=r.startContainer,k=r.startOffset;
  285. var i=c.data.substr(0,k).search(/\s\S*$/),j=c.data.substr(k).search(/\s/);
  286. r.setStart(c,i+1);r.setEnd(c,j<0?c.data.length:k+j);
  287. s.removeAllRanges();s.addRange(r); // Compatible with Chrome
  288. });
  289. $('<label>名单管理:</label>').appendTo(op);
  290. be=$('<span>').appendTo(op);
  291. $('<span class=ge_sbtn>编辑</span>').appendTo(be).click(function(e){
  292. bs.show();be.hide();
  293. pl.prop('contenteditable',true);
  294. pl.text(c.cur.data.join(' '));
  295. });
  296. $('<span class=ge_sbtn>全选/不选</span>').appendTo(be).click(function(e){
  297. e.preventDefault();
  298. var a=pl.children('a:not(.selected)');
  299. if(a.length) a.addClass('selected'); else pl.children('a').removeClass('selected');
  300. });
  301. bs=$('<span>').appendTo(op).hide();
  302. $('<span class=ge_sbtn>去重</span>').appendTo(bs).click(function(e){
  303. var d=pl.text().replace(/^\s+|\s+$/,'').split(/\s+/),h={};
  304. d.forEach(function(i){h[i]=0;});
  305. pl.text(Object.getOwnPropertyNames(h).join(' '));
  306. });
  307. $('<span class="ge_sbtn ge_rsep">完成</span>').appendTo(bs).click(function(e){
  308. c.cur.data=pl.text().replace(/^\s+|\s+$/,'').split(/\s+/);
  309. c.save();editList(e);be.show();bs.hide();
  310. });
  311. $('<span>空格隔开,双击选中一个名字</span>').appendTo(bs);
  312. var b=$('<div style="float:right">').appendTo(op);be=be.add(b);
  313. $('<span class=ge_sbtn title="普通召唤,超过十个ID将会失败">召唤</span>').appendTo(b).click(function(e){
  314. var se=p.holder==E?editor:unsafeWindow.LzlEditor._s_p._se;
  315. pl.children('a.selected').each(function(i,e){se.execCommand('inserthtml','@'+e.innerHTML+'&nbsp;');});
  316. p.onclose();
  317. });
  318. /*$('<span class=ge_sbtn title="插入一个占位符,将自动替换成召唤名单">自动召唤</span>').appendTo(b).click(function(e){
  319. e=[];pl.children('a.selected').each(function(){e.push(this.innerHTML);});
  320. p.onclose();
  321. if(e.length) {
  322. p.holder.names=e;
  323. e=p.holder==E?editor:unsafeWindow.LzlEditor._s_p._se;
  324. e.execCommand('inserthtml','<img class=BDE_Smiley title="将在此自动插入召唤名单" alt="召唤列表" height=18>');
  325. }
  326. });*/
  327. c.list.forEach(function(i){$('<option>').text(i.name).appendTo(sl);});
  328. editList();
  329. }
  330. var l=/<img [^>]*?alt="召唤列表"[^>]*>/;
  331. function addNames(e,n){
  332. if(n.splice) n='@'+n.splice(0,10).join(' @')+' ';
  333. return e.replace(l,n);
  334. }
  335. // 主编辑框
  336. var o=utils.addTButton($('<div unselectable="on" class="edui-icon call_list" title="召唤">'));
  337. var E=o.parents('.edui-toolbar');
  338. utils.addPopup(E,o,loadLists);
  339. /*utils.hook(unsafeWindow.PostHandler,'post',{before:function(f,a){
  340. function post(){f.hook_func(a[0],a[1],E.names?delay:a[2],a[3]);}
  341. function delay(m){
  342. if(m){if(m.no) d+=1000; else d=DELAY;}
  343. if((!m||!m.no)&&E.names) {
  344. a[1].content=addNames(e,E.names);
  345. if(!E.names.length) delete E.names;
  346. }
  347. setTimeout(post,d);
  348. }
  349. var e=a[1].content,d=0;f.hookStop();
  350. if(E.names&&e.search(l)<0) delete E.names;
  351. delay();
  352. }});*/
  353. // 楼中楼
  354. /*lzl_init.push(function(){
  355. utils.hook(unsafeWindow.SimplePostor.prototype,'_submitData',{before:function(f){
  356. function post(){
  357. $.tb.post(FORUM_POST_URL.postAdd,b,delay);
  358. }
  359. function delay(m){
  360. if(o.names) {
  361. if(m){if(m.no) d+=1000; else d=DELAY;}
  362. if(!m||!m.no) {
  363. b.content=addNames(a,o.names);
  364. if(!o.names.length) delete o.names;
  365. }
  366. setTimeout(post,d);
  367. } else location.reload();
  368. }
  369. if(o.names&&this._se.editArea.innerHTML.search(l)>=0) {
  370. f.hookStop();var d=0,b=this._getData(),a=b.content;delay();
  371. }
  372. }});
  373. });*/
  374. o=$('<span title="召唤">');
  375. addPButton(o,['lzl_panel_call'],utils.addPopup(o,null,loadLists).ontoggle,{keys:['click']});
  376. }
  377.  
  378. // 自动获取礼包
  379. // 来源:http://userscripts.org/scripts/show/268885
  380. // 感谢 Star Brilliant <m13253@hotmail.com>
  381. function initFetchGift() {
  382. setInterval(function(){
  383. $('.rand_gift').click();
  384. $('.time_gift.unopen_gift').click();
  385. },10000);
  386. }
  387.  
  388. // 字体颜色初始化
  389. function initFont() {
  390. utils.colors={red:'#e10602'};
  391. utils.switchColor=function(cr,cs) {
  392. document.execCommand('forecolor',false,document.queryCommandValue('forecolor').replace(/\s/g,'')==cr?'#333333':cs);
  393. }
  394. function fix() {
  395. $(this.editArea).find('font[color]').each(function(i,e){
  396. e=$(e);i=e.html();
  397. switch(e.prop('color')){
  398. case utils.colors.red:
  399. e.replaceWith('<span class="edit_font_color">'+i+'</span>');
  400. break;
  401. }
  402. }).end().find('b').each(function(i,e){
  403. e=$(e);i=e.html();e.replaceWith('<strong>'+i+'</strong>');
  404. }).end().find('span.at').each(function(i,e){ // allow at
  405. e.outerHTML=e.innerHTML;
  406. });
  407. }
  408. var p=unsafeWindow.TED.EditorCore.prototype;
  409. p.submitValidHTML=p.submitValidHTML.concat(['span','strong']); // allow font in Lzl
  410. utils.hook(unsafeWindow.rich_postor._editor,'filteSubmitHTML',{before:fix});
  411. lzl_efilters.push(fix);
  412. }
  413.  
  414. // 修复楼中楼定位翻页
  415. function initLzlFix() {
  416. $('li.lzl_li_pager').each(function(i,e){
  417. if((e=$(e)).children('.lzl_more:hidden').length) e.children('.j_pager:hidden').show();
  418. });
  419. }
  420. // 楼中楼初始化
  421. function initLzL() {
  422. // 倒序添加按钮
  423. var t=$('#edit_parent .tb-editor-toolbar');
  424. if(t.children('.font_color').length)
  425. addPButton($('<span title="红字" unselectable="on"></span>'),['font_color'],
  426. function(e){utils.switchColor('rgb(225,6,2)',utils.colors.red);},{before:'.lzl_panel_smile'});
  427. if(t.children('.font_strong').length)
  428. addPButton($('<span title="加粗" unselectable="on"></span>'),['font_strong'],
  429. function(e){document.execCommand('bold',false,'');},{before:'.lzl_panel_smile'});
  430. // 楼中楼初始化
  431. function fixLzl() {
  432. var p=$('div.lzl_panel_btn');p.parent().css('width','50%').prev().css('width','50%');
  433. lzl_buttons.forEach(function(i){utils.addButton(p,i[0],i[1],i[2]);});
  434. }
  435. t='.font_strong,.font_color{background:url("http://tb2.bdstatic.com/tb/editor/v2/font_style.png") no-repeat transparent;height:20px;width:22px;}.font_color{background-position:0 -20px;}';
  436. if(lzl_styles.length) t+='.'+lzl_styles.join(',.')+'{margin:2px 1px;float:right;}';
  437. utils.addStyle(t);
  438. if(unsafeWindow.LzlEditor._s_p) fixLzl();
  439. lzl_init.forEach(function(i){i();});
  440. utils.hook(unsafeWindow.SimplePostor.prototype,'_buildNormalEditor',{after:fixLzl});
  441. utils.hook(unsafeWindow.TED.SimpleEditor.prototype,'filteSubmitHTML',{before:lzl_efilters});
  442. utils.hook(unsafeWindow.SimplePostor.prototype,'_getHtml',{before:function(f){
  443. f.hookStop();return this._se.getHtml();
  444. }});
  445. }
  446. function fixer(func,args){
  447. try{func.apply(this,args);}catch(e){
  448. var f=$('<div>').appendTo('body').css({width:'120px',position:'fixed',left:0,top:0,display:'none','text-align':'center','z-index':999});
  449. $('<div>出错了!如需反馈请复制以上信息</div>').appendTo(f).css('color','white').add(
  450. $('<a href=http://userscripts.org/scripts/discuss/152918>点此反馈</a>').appendTo(f).css('color','yellow')
  451. ).css({background:'purple',margin:'1px',padding:'10px','border-radius':'5px',display:'block'});
  452. var m=location.href+'\n'+e.name+': '+e.message+'\n'+(e.stacktrace||e.stack);
  453. if(window.console) console.log(m);
  454. f.prepend($('<textarea style="height:200px;">').val(m.slice(0,1024)).mouseover(function(e){this.select();})).show();
  455. }
  456. }
  457.  
  458. function initEditor(editor){
  459. // 此模块仅在有输入框且允许发言时加载
  460. fixer(function(){
  461. initAddWater(editor); // 灌水+尾巴
  462. initCall(editor); // 召唤增强,召唤列表
  463. //initFont(editor); //初始化:高级字体
  464. });
  465. }
  466.  
  467. // 以下为模块调用,可将不需要的模块注释,不要改变顺序
  468. if($&&PageData&&PageData.user) { // 出错反馈按钮
  469. initCard(); // 用户卡片上添加召唤按钮
  470. // 以下模块无需登录
  471. if(PageData.thread) { // 以下模块仅在帖子浏览页面加载
  472. //initLzlFix(); // 修复楼中楼定位翻页
  473. } else {
  474. initLastPage(); // 尾页直达功能
  475. }
  476. //以下模块仅在登录时加载
  477. if(PageData.user.is_login) {
  478. if(unsafeWindow.PosterContext&&unsafeWindow.PosterContext.isPostAllowed()) utils.wait(unsafeWindow,'test_editor',initEditor);
  479. initFetchGift();
  480. if(unsafeWindow.LzlEditor&&unsafeWindow.SimplePostor) initLzL(); //初始化楼中楼:支持已加载的功能
  481. }
  482. }