tb_borer

tba_style

  1. // ==UserScript==
  2. // @name tb_borer
  3. // @namespace iaceob_tborer
  4. // @description tba_style
  5. // @include http://tieba.baidu.com/*
  6. // @version 2.2.2 alpha
  7. // @grant none
  8. // @author 生物烯丙菊
  9. // ==/UserScript==
  10.  
  11. String.prototype.format = function () {
  12. var txt = this.toString();
  13. for (var i = 0; i < arguments.length; i++) {
  14. var exp = getStringFormatPlaceHolderRegEx(i);
  15. txt = txt.replace(exp, (arguments[i] == null ? "" : arguments[i]));
  16. }
  17. return cleanStringFormatResult(txt);
  18. };
  19. function getStringFormatPlaceHolderRegEx(placeHolderIndex) {
  20. return new RegExp('({)?\\{' + placeHolderIndex + '\\}(?!})', 'gm');
  21. };
  22. function cleanStringFormatResult(txt) {
  23. if (txt == null) return '';
  24. return txt.replace(getStringFormatPlaceHolderRegEx("\\d+"), "");
  25. };
  26.  
  27. String.prototype.filterHtmlTag = function(){
  28. var str = this.toString();
  29. str = str.replace(/</g, '&lt;');
  30. str = str.replace(/>/g, '&gt;');
  31. str = str.replace(/"/g, '&quot;');
  32. str = str.replace(/'/g, '&#39;');
  33. return str;
  34. };
  35.  
  36. Array.prototype.remove=function(dx) {
  37. if(isNaN(dx)||dx>this.length){ return false; }
  38. for(var i=0,n=0;i<this.length;i++) {
  39. if(this[i]!=this[dx]) this[n++]=this[i];
  40. }
  41. this.length-=1;
  42. return true;
  43. };
  44.  
  45.  
  46. !(function(window, $, undefined){
  47.  
  48. var document = window.document;
  49. var pd = window.PageData;
  50.  
  51. if (!pd) {
  52. return;
  53. }
  54.  
  55. var config = {
  56. history: {
  57. title: '',
  58. // url: '',
  59. data: null
  60. },
  61. posts: {
  62. page_url: '',
  63. handle_url: 'http://tieba.baidu.com/f/commit/thread/add',
  64. forum_id: 0,
  65. forum_name: 0,
  66. tbs: '',
  67. floor_num: 0,
  68. content: '',
  69. title: ''
  70. },
  71. post: {
  72. page_url: '',
  73. handle_url: 'http://tieba.baidu.com/f/commit/post/add',
  74. forum_id: 0,
  75. thread_id: 0,
  76. forum_name: '',
  77. tbs: '',
  78. floor_num: 1,
  79. lzl_url: 'http://tieba.baidu.com/p/comment',
  80. lzl_pn: 1,
  81. post_id: '',
  82. see_lz: false
  83. },
  84. captcha: {
  85. url4: 'http://tieba.baidu.com/cgi-bin/genimg',
  86. url4_get: 'http://tieba.baidu.com/f/commit/commonapi/getVcode',
  87. url_check: 'http://tieba.baidu.com/f/commit/commonapi/checkVcode',
  88. type: 0,
  89. code: '',
  90. input: '',
  91. value: []
  92. },
  93. user: {
  94. id: 0,
  95. name: ''
  96. },
  97. depend: [
  98. // {url: 'http://balupton.github.io/history.js/scripts/bundled/html4+html5/jquery.history.js', type: 'js'},
  99. {url: 'http://well.iaceob.name/shell/pace/v0.5.3/pace.min.js', type: 'js'},
  100. {url: 'http://well.iaceob.name/shell/tba/jquery.omniwindow.js', type: 'js'},
  101. {url: 'http://well.iaceob.name/shell/tba/tba_v2.1_alpha.css', type: 'css'},
  102. {url: 'http://well.iaceob.name/shell/bd_um/themes/default/css/umeditor.css', type: 'css'},
  103. {url: 'http://well.iaceob.name/shell/bd_um/umeditor.config.js', type: 'js'},
  104. {url: 'http://well.iaceob.name/shell/bd_um/umeditor.min.js', type: 'js'},
  105. {url: 'http://well.iaceob.name/shell/bd_um/lang/zh-cn/zh-cn.js', type: 'js'},
  106. ],
  107. message: {
  108. url: {
  109. atme: 'http://tieba.baidu.com/i/sys/jump?type=atme',
  110. replay: 'http://tieba.baidu.com/i/sys/jump?type=replyme',
  111. fans: 'http://tieba.baidu.com/i/sys/jump?type=fans',
  112. feature: 'http://tieba.baidu.com/i/sys/jump?type=feature',
  113. recycle: 'http://tieba.baidu.com/pmc/recycle'
  114. },
  115. number: {
  116. atme: 0,
  117. replay: 0,
  118. fans: 0,
  119. feature: 0,
  120. recycle: 0,
  121. total: 0
  122. },
  123. recycle: {
  124. url: 'http://tieba.baidu.com/pmc/userthreadinfo',
  125. currentPage: 1,
  126. pageSize: 20
  127. },
  128. show: false,
  129. constraint: false,
  130. interval: 60*1000
  131. },
  132. editor: null
  133. };
  134.  
  135. var tpl = {};
  136. var tborer = {};
  137. tborer.config = config;
  138. config.user.id = pd.user.user_id;
  139. config.user.name = pd.user.user_name;
  140. window.cfg = config;
  141. tpl.html_header = '<header id="header" class="loop-12 slide-time"></header>';
  142. tpl.html_container = '<div class="span container">{0}</div>';
  143. tpl.html_footer = '<footer id="footer" class="loop-12">Footer</footer>';
  144. tpl.html_footer += '<div class="ow-overlay ow-closed"></div><div class="tba-modal ow-closed">Hello, human!</div>';
  145. tpl.html_box_posts = '<div class="loop-12 box_posts slide-time" id="box_posts"></div>';
  146. tpl.html_box_post = '<div class="loop-12 post_container" id="post_container"></div>';
  147. tpl.html_footer += '<div class="box_pcfg">\
  148. <div class="loop-12 btn_gotop"><span>&#8593;</span></div>\
  149. <div class="loop-12 btn_pl"><span>≡</span></div>\
  150. <div class="loop-12 btn_tb_msg"><span>消息</span><span class="tb-msg-num"></span></div>\
  151. <div class="loop-12 btn_godown"><span>&#8595;</span></div>\
  152. </div>';
  153. // tpl.css = 'http://idc.iaceob.name/tba_style/tba_v1.6_alpha.css';
  154. // tpl.js_omniwindow = 'http://idc.iaceob.name/tba_style/jquery.omniwindow.js';
  155. // getTiebaMessage
  156.  
  157. if (location.href === 'http://tieba.baidu.com/') {
  158. return;
  159. }
  160.  
  161.  
  162. function initBorer() {
  163. if (!!pd.forum.id) {
  164. setPostsConfig($('body').text());
  165. var postsPage = parsePosts($('body'));
  166. initPage();
  167. initPosts(postsPage);
  168. openPosts();
  169. return;
  170. }
  171. if (!!pd.forum.forum_id) {
  172. $.ajax({
  173. url: 'http://tieba.baidu.com/' + pd.forum.forum_name,
  174. dataType: 'html'
  175. }).done(function(data){
  176. config.post.page_url = window.location.href;
  177. setPostConfig($('body').text());
  178. setPostsConfig($(data).text());
  179. var postPage = parsePost($('body'));
  180. initPage();
  181. initPosts(parsePosts($(data)));
  182. initPost(postPage);
  183. openPosts();
  184. });
  185. return;
  186. }
  187. };
  188.  
  189. function initPage() {
  190. var fhtml = parseFooter();
  191. html = tpl.html_header;
  192. html += tpl.html_container.format(tpl.html_box_posts+tpl.html_box_post);
  193. html += tpl.html_footer;
  194. $('body').empty();
  195. $('body').html(html);
  196. // $('#head').html(html);
  197. initHeader();
  198. initFooter(fhtml);
  199. initImport();
  200. bindEvent();
  201. };
  202.  
  203. function initPosts(body) {
  204. $('.posts_paging a').unbind('click');
  205. $('#post_container').empty();
  206. $('#box_posts').html(body);
  207. $('#box_posts').scrollTop(0);
  208. monitorHPage();
  209. };
  210.  
  211. function initPost(body) {
  212. $('.post-page a').unbind('click');
  213. $('#post_container').html(body);
  214. $('#post_container').scrollTop(0);
  215. mointorPPage();
  216. };
  217. function initHeader() {
  218. var hhtml = '<div class="loop-2 tiebalogo"><img src="http://tb2.bdstatic.com/tb/static-common/img/search_logo_7098cbef.png"></div>';
  219. hhtml += '<div class="loop-8">\
  220. <div class="select_box">\
  221. <input type="text" name="query" id="query" class="keyipt" autocomplete="off">\
  222. <div id="search_list" style="display: none"></div>\
  223. </div>\
  224. </div>';
  225. $('#header').html(hhtml);
  226. };
  227.  
  228. function initFooter(fhtml) {
  229. $('#footer').html(fhtml);
  230. };
  231.  
  232. function initImport(){
  233. for(var i=0; i<config.depend.length; i++) {
  234. loadFile(config.depend[i].url, config.depend[i].type);
  235. }
  236. };
  237.  
  238. function monitorHPage() {
  239. $('#btn_posting').bind('click', function(){
  240. var pshtml = '';
  241. pshtml += '<div class="box_modal">\
  242. <div class="modal_container">\
  243. <div class="loop-12"><textarea id="posts_editor" name="content" style="width:100%;height:360px;"></textarea></div>\
  244. <div class="loop-2">贴吧:</div>\
  245. <div class="loop-10 forum_name">' + config.posts.forum_name + '</div>\
  246. <div class="loop12">标题:</div>\
  247. <div class="loop-12"><input type="text" id="posts_title" name="title" autocomplete="off"></div>\
  248. </div>\
  249. <div class="loop-12" id="modal_other"></div>\
  250. <div class="loop-12 modal_result"></div>\
  251. <div class="loop-12"><button class="btn" id="btn_submit">提交</button></div>\
  252. </div>';
  253. $('.tba-modal').html(pshtml);
  254. window.UM.delEditor('posts_editor');
  255. var editor_posts = window.UM.getEditor('posts_editor');
  256. config.editor = editor_posts;
  257. $('.tba-modal').omniWindow().trigger('show');
  258. $('#btn_submit').bind('click', function(){
  259. var title = $('#posts_title').val();
  260. var content = formatEditor(editor_posts.getContent());
  261. executePosting(title, content);
  262. });
  263. });
  264. $('.posts_paging a').bind('click', function(){
  265. handleGetPosts(this.href);
  266. return false;
  267. });
  268. $('.posts_list li').bind('click', function(){
  269. config.history.title = $(this).find('.post_title').text();
  270. // config.history.url = $(this).data('href');
  271. handleGetPost($(this).data('href'));
  272. closePosts();
  273. });
  274. };
  275.  
  276. function mointorPPage() {
  277. $('.post-page a').bind('click', function(){
  278. handleGetPost(this.href);
  279. return false;
  280. });
  281. $('#post_replay').bind('click', function(){
  282. var pshtml = '';
  283. pshtml += '<div class="box_modal">\
  284. <div class="modal_container">\
  285. <div class="loop-12"><textarea id="post_editor" name="content" style="width:100%;height:360px;"></textarea></div>\
  286. <div class="loop-2">贴吧:</div>\
  287. <div class="loop-10 forum_name">' + config.posts.forum_name + '</div>\
  288. </div>\
  289. <div class="loop-12" id="modal_other"></div>\
  290. <div class="loop-12 modal_result"></div>\
  291. <div class="loop-12"><button class="btn" id="btn_submit">提交</button></div>\
  292. </div>';
  293. $('.tba-modal').html(pshtml);
  294. window.UM.delEditor('post_editor');
  295. var editor_post = window.UM.getEditor('post_editor');
  296. config.editor = editor_post;
  297. $('.tba-modal').omniWindow().trigger('show');
  298. $('#btn_submit').bind('click', function(){
  299. var content = formatEditor(editor_post.getContent());
  300. executPostReplay(content);
  301. });
  302. });
  303. $('.btn_replay_lzl').bind('click', function(){
  304. if($(this).data('floor')==1) {
  305. $('#post_replay').click();
  306. return;
  307. }
  308. config.post.lzl_pn = 1;
  309. config.post.floor_num = $(this).data('floor');
  310. config.post.post_id = $(this).data('pid');
  311. handleGetLzlReplay();
  312. });
  313. $('#see_lz').bind('click', function(){
  314. if (config.post.see_lz) {
  315. config.post.see_lz = false;
  316. handleGetPost(config.post.page_url.split('?')[0]);
  317. return;
  318. }
  319. config.post.see_lz = true;
  320. handleGetPost(config.post.page_url.split('?')[0] + '?see_lz=1');
  321. return;
  322. });
  323. };
  324.  
  325. function mointorSearch(){
  326. $.ajax({
  327. url: 'http://tieba.baidu.com/suggestion',
  328. data: $('#query').serialize(),
  329. dataType: 'json',
  330. }).done(function(data){
  331. $('#search_list').html(parseSearch(data));
  332. });
  333. };
  334.  
  335. function mointorLzlReplay(pid, html) {
  336. $('.tba-modal').html(html);
  337. $('.tba-modal').omniWindow().trigger('show');
  338. $('.lzl-page a').bind('click', function(){
  339. config.post.lzl_pn = this.href.split('#')[1];
  340. config.post.post_id = pid;
  341. handleGetLzlReplay();
  342. });
  343. $('.btn_lzl_replay').bind('click', function(){
  344. $('.box_lzl_replay').empty();
  345. var pid = $(this).data('spid');
  346. var aur = $(this).data('author');
  347. var lrp = '<div id="box_lzl_replay_' + pid + '" class="span box_lzl_replay">\
  348. <div class="loop-12 lzl_editor"><textarea id="lzl-editor-' + pid + '">' + (!aur ? '' : '@'+aur+' ') + '</textarea></div>\
  349. <div class="loop-12 lzl_operate">\
  350. <button class="btn" id="btn_handle_replay_lzl" data-pid="' + pid + '">回复</button>\
  351. </div>\
  352. <div class="lzl_replay_other"></div>\
  353. </div>';
  354. $('#box_lzl_rep-' + pid).html(lrp);
  355. monitorBtnLzlReplay();
  356. });
  357. };
  358.  
  359. function monitorBtnLzlReplay() {
  360. $('#btn_handle_replay_lzl').bind('click', function(){
  361. var pid = $(this).data('pid');
  362. var content = $('#lzl-editor-' + pid).val();
  363. $.ajax({
  364. url: config.post.handle_url,
  365. type: 'post',
  366. data: {
  367. anonymous: 0,
  368. fid: config.post.forum_id,
  369. floor_num: config.post.floor_num,
  370. ie: 'utf-8',
  371. kw: config.post.forum_name,
  372. quote_id: config.post.post_id,
  373. repostid: config.post.post_id,
  374. rich_text: 1,
  375. // tag: 11,
  376. tbs: config.post.tbs,
  377. tid: config.post.thread_id,
  378. new_vcode: 1,
  379. content: content,
  380. vcode_md5: config.captcha.code,
  381. vcode: config.captcha.input
  382. },
  383. dataType: 'json'
  384. }).done(function(data){
  385. parseLzlReplay(data, pid);
  386. });
  387. });
  388. };
  389. window.handleSearchResult = function(forum){
  390. var url = 'http://tieba.baidu.com/' + forum;
  391. handleGetPosts(url);
  392. config.history.title = forum;
  393. // config.history.url = url;
  394. window.history.pushState(config.history, null, url);
  395. };
  396.  
  397. function handleGetPosts(postsUrl) {
  398. // History.pushState({mark: 'posts'}, config.history.title, postsUrl);
  399. config.posts.page_url = postsUrl;
  400. window.history.pushState(config.history, null, postsUrl);
  401. $.ajax({
  402. url: postsUrl,
  403. dataType: 'html'
  404. }).done(function(data){
  405. setPostsConfig($(data).text());
  406. initPosts(parsePosts($(data)));
  407. });
  408. };
  409.  
  410. function handleGetLzlReplay() {
  411. $.ajax({
  412. url: config.post.lzl_url,
  413. data: {tid: config.post.thread_id, pid: config.post.post_id, pn: config.post.lzl_pn},
  414. dataType: 'html'
  415. }).done(function(data){
  416. window.da = $(data);
  417. var lhtml = parsePostLzl($(data));
  418. mointorLzlReplay(config.post.post_id, lhtml);
  419. });
  420. };
  421.  
  422. function handleGetPost(postUrl) {
  423. // History.pushState({mark: 'post'}, config.history.title, postUrl);
  424. config.post.page_url = postUrl;
  425. window.history.pushState(config.history, null, postUrl);
  426. $.ajax({
  427. url: postUrl,
  428. dataType: 'html'
  429. }).done(function(data){
  430. initPost(parsePost($(data)));
  431. setPostConfig($(data).text());
  432. });
  433. };
  434.  
  435.  
  436.  
  437. function setPostsConfig(text) {
  438. var tbs = text.match(/PageData.tbs([ ]*)=([ ]*)"(.*?)"/);//[3]
  439. var fid = text.match(/PageData.forum([ ]*)=([ ]*){(.*?)"forum_id":(\d+)/);
  440. var fe = text.match(/PageData.forum([ ]*)=([ ]*){(.*?)"forum_name":"(.*?)"/);
  441. config.posts.tbs = !tbs ? '' : tbs[3];
  442. config.posts.forum_id = !fid ? 0 : fid[4];
  443. config.posts.forum_name = !fe ? '' : decodeUnicode(fe[4]);
  444. config.posts.page_url = 'http://tieba.baidu.com/' + config.posts.forum_name;
  445. };
  446.  
  447. function setPostConfig(text){
  448. var tbs1 = text.match(/PageData([ ]*)=([ ]*){(.*?)'tbs'(.*?):(.*?)"(.*?)"/);
  449. var tbs2 = text.match(/PageData([ ]*)=([ ]*){(.*?)tbs(.*?):(.*?)'(.*?)'/);
  450. var fid = text.match(/PageData.forum([ ]*)=([ ]*){(.*?)"forum_id":(\d+)/);
  451. var fe = text.match(/PageData.forum([ ]*)=([ ]*){(.*?)"forum_name":"(.*?)"/);
  452. var tid = text.match(/PageData.thread([ ]*)=([ ]*){(.*?)thread_id(.*?):(\d+)/);
  453. config.post.tbs = !tbs1 ? tbs2[6] : tbs1[6];
  454. config.post.forum_id = !fid ? 0 : fid[4];
  455. config.post.forum_name = !fe ? '' : decodeUnicode(fe[4]);
  456. config.post.thread_id = !tid ? 0 : tid[5];
  457. };
  458. function bindEvent() {
  459. window.tborer = tborer;
  460. $('#query').bind('keyup', function(event){
  461. $('#search_list').show();
  462. if (event.keyCode != 13) {
  463. mointorSearch();
  464. return;
  465. }
  466. event.cancelBubble = true;
  467. event.returnValue = false;
  468. window.handleSearchResult($(this).val());
  469. });
  470. $('#query').bind('click', function(){
  471. $('#search_list').show();
  472. mointorSearch();
  473. openPosts();
  474. });
  475. $('#search_list').hover(function(){
  476. $(this).show();
  477. }, function(){
  478. $(this).hide();
  479. });
  480. $('.btn_pl').bind('click', function(){
  481. if ($('#box_posts').hasClass('show')) {
  482. closePosts();
  483. return;
  484. }
  485. openPosts();
  486. });
  487. $('#post_container').bind('mousemove', function(event){
  488. var e = event||window.event;
  489. // var h = window.innerHeight;
  490. var y = e.clientY;
  491. // || h-y<100
  492. if(y<20){
  493. $('#header').addClass('show');
  494. return;
  495. }
  496. $('#header').removeClass('show');
  497. });
  498. $('.btn_gotop').bind('click', function(){
  499. $('#post_container').animate({scrollTop:0},1000);
  500. });
  501. $('.btn_godown').bind('click', function(){
  502. $('#post_container').animate({scrollTop:$('#post_container')[0].scrollHeight},1000);
  503. });
  504. $('.btn_tb_msg').bind('click', function(){
  505. config.message.constraint = false;
  506. mointorTiebaMessage();
  507. });
  508. // window.setTimeout(getTiebaMessage(),5000);
  509. window.setTimeout(function(){
  510. window.initItiebaMessage = function(msg){
  511. tborer.parseTiebaMessage(msg);
  512. };
  513. window.tiebaMsgTimer = setInterval(function(){
  514. tborer.handleGetTiebaMessage();
  515. }, config.message.interval);
  516. }, 3000);
  517. /*
  518. window.setTimeout(function(){
  519. History.Adapter.bind(window,'statechange',function(){
  520. tborer.handleHistory(History.getState());
  521. });
  522. }, 3000);
  523. */
  524. };
  525.  
  526. function parseFooter() {
  527. var tf = $('#footer').html();
  528. var fhtml = '<div class="loop-12">' + tf + '</div>';
  529. return fhtml;
  530. };
  531. function parseSearch(data) {
  532. var qms = data.query_match.search_data;
  533. if (qms.length==0) {
  534. return '<p>无数据';
  535. }
  536. var qhtml = '<ul>';
  537. for(var i=0; i<qms.length; i++) {
  538. qhtml += '<li onclick="handleSearchResult(&quot;' + qms[i].fname + '&quot;)">\
  539. <div class="sh_forum_name">' + qms[i].fname + '</div>\
  540. <div class="sh_forum_desc">' + qms[i].forum_desc + '</div>';
  541. }
  542. qhtml += '</ul>';
  543. return qhtml;
  544. };
  545. function parsePosts(postsDom) {
  546. var h_posts = postsDom.find('li.j_thread_list');
  547. var h_paging = postsDom.find('#frs_list_pager');
  548. var h_cur_page = postsDom.find('#frs_list_pager .cur');
  549. var h_cur_url = !h_cur_page.length ? '#?' + window.Math.random() : '/f?kw=' + config.posts.forum_name + '&pn=' + (h_cur_page.text()*50-50);
  550. var ho_pobj = {}, posts_html='';
  551. posts_html='<div class="span"><div class="loop-12 posts_list"><ul>';
  552. for(var i=0; i<h_posts.length; i++) {
  553. var hp = h_posts[i];
  554. var hp_rep_num = $(hp).find('.threadlist_rep_num')[0].textContent;
  555. var hp_title = $(hp).find('.j_th_tit')[1].textContent;
  556. var hp_href = $(hp).find('.j_th_tit')[1].href;
  557. var hp_detail = !$(hp).find('.threadlist_text')[1] ? '' : $(hp).find('.threadlist_text')[1].textContent.filterHtmlTag();
  558. var hp_author = !$(hp).find('.j_user_card')[0] ? '' : $(hp).find('.j_user_card')[0].textContent;
  559. var hp_last_repuser = !$(hp).find('.j_user_card')[1] ? '' : $(hp).find('.j_user_card')[1].textContent;
  560. var hp_last_time = !$(hp).find('.j_reply_data')[0] ? '' : $(hp).find('.j_reply_data')[0].textContent;
  561. posts_html += '<li data-href="' + hp_href + '">\
  562. <div class="span">\
  563. <div class="loop-10 post_title hidefont" title="' + hp_title + '">' + hp_title + '</div>\
  564. <div class="loop-2 post_author hidefont" title="' + hp_author + '">' + hp_author + '</div>\
  565. <div class="loop-12 box_posts_detail">' + hp_detail + '</div>\
  566. <div class="loop-5 post_repuser hidefont">最后回复人:' + hp_last_repuser + '</div>\
  567. <div class="loop-5 post_lasttime">最后回复时间:' + hp_last_time + '</div></div>';
  568. }
  569. posts_html += '</ul></div>';
  570. posts_html += '</div>\
  571. <div class="span">\
  572. <div class="loop-4 posts_paging">' +
  573. (!h_paging.length ? '' : h_paging.html()) +
  574. '<a href="' + h_cur_url + '">刷新</a>\
  575. <span id="btn_posting">发帖</span>\
  576. </div>\
  577. </div>';
  578. return posts_html;
  579. };
  580. function parsePost(postDom) {
  581. var post_title = postDom.find('.core_title_txt').html()
  582. var post_info = postDom.find('.l_post');
  583. var post_content = postDom.find('.p_content cc');
  584. var author_avatar = postDom.find('.p_author_face img');
  585. var lzlbox = postDom.find('j_lzl_c_b_a');
  586. var ppage = postDom.find('.pb_list_pager')[0];
  587. var post_html = '';
  588. post_html += '<div class="loop-12 post_title">' + post_title + '</div>';
  589. for(var i=0; i<post_info.length; i++) {
  590. var pi = $(post_info[i]).data('field');
  591. var pc = post_content[i];
  592. post_html += '<section data-post="' + pi.content.post_id + '" >';
  593. post_html += '<div class="loop-2 post_info">\
  594. <div class="loop-12 post_author" data-user="' + pi.author.user_id + '">\
  595. <div><img src="http://tb.himg.baidu.com/sys/portrait/item/' + pi.author.portrait + '"></div>\
  596. <span>' + pi.author.user_name + '</span>\
  597. </div>\
  598. <div class="loop-12 post_author_level">\
  599. <span>' + (pi.author.level_name||'*') + '</span>\
  600. <span>' + (pi.author.level_id||'0') + '</span>\
  601. </div>\
  602. </div>';
  603. post_html += '<div class="loop-10 post_article">' + pc.innerHTML + '</div>';
  604. post_html += '<div class="loop-10 post_msg"><div class="loop-2 btn_replay_lzl" data-pid="' + pi.content.post_id + '" data-floor="' + pi.content.post_no + '">楼中楼(' + pi.content.comment_num + ')</div><div class="loop-2">' + pi.content.post_no + '楼</div><div class="loop-2">' + pi.content.date + '</div></div>';
  605. post_html += '</section>';
  606. }
  607. post_html += '<div class="loop-4 post-page">' + ppage.innerHTML + '<span id="post_replay">回复</span><span id="see_lz">楼主模式</span></div>';
  608. post_html += '<div class="loop-4 post-url"><span>' + config.post.page_url + '</span></div>';
  609. post_html='<div class="span box_post">' +post_html+ '</div>';
  610. return post_html;
  611. };
  612. function parsePostLzl(data) {
  613. var lzlhtml = '<div class="box_lzl"><ul>';
  614. for(var i=0; i<data.length; i++) {
  615. var lzlinfo = $(data[i]).data('field');
  616. var lzltext = $(data[i]).find('.lzl_cnt span.lzl_content_main').html();
  617. var lzltime = $(data[i]).find('.lzl_cnt span.lzl_time').html();
  618. if (!lzlinfo.spid) {
  619. break;
  620. }
  621. lzlhtml += '<li id="lzl-'+lzlinfo.spid+'">\
  622. <div class="span">\
  623. <div class="loop-4 lzl_author">' + lzlinfo.user_name + '</div>\
  624. <div class="loop-8 lzl_cnt">' + lzltext + '</div>\
  625. <div class="loop-12 lzl_info">\
  626. <span>' + lzltime + '</span>\
  627. <span class="btn_lzl_replay" data-spid="' + lzlinfo.spid + '" data-author="' + lzlinfo.user_name + '">回复</span></div>\
  628. </div>\
  629. <div id="box_lzl_rep-' + lzlinfo.spid + '"></div>';
  630. }
  631. lzlhtml += '</ul>';
  632. lzlhtml += '<div class="span">\
  633. <div class="loop-12">\
  634. <span class="btn_lzl_replay" data-spid="1">回复</span></div>\
  635. </div>\
  636. </div>\
  637. <div id="box_lzl_rep-1"></div>';
  638. var lzlp = $(data[data.length-1]).find('.j_pager');
  639. lzlhtml += !lzlp.length ? '' : '<div class="loop-12 lzl-page">' + lzlp.html() + '</div>';
  640. lzlhtml += '</div>';
  641. return lzlhtml;
  642. };
  643.  
  644.  
  645. function executePosting(title, content){
  646. $.ajax({
  647. url: config.posts.handle_url,
  648. type: 'post',
  649. data: {
  650. content: content,
  651. fid: config.posts.forum_id,
  652. floor_num: config.posts.floor_num,
  653. ie: 'utf-8',
  654. kw: config.posts.forum_name,
  655. rich_text: 1,
  656. tbs: config.posts.tbs,
  657. tid: 0,
  658. title: title,
  659. vcode: config.captcha.input,
  660. vcode_md5: config.captcha.code
  661. },
  662. dataType: 'json'
  663. }).done(function(data){
  664. parsePosting(data);
  665. });
  666. };
  667.  
  668.  
  669. function executPostReplay(content) {
  670. $.ajax({
  671. url: config.post.handle_url,
  672. type: 'post',
  673. data: {
  674. kw: config.post.forum_name,
  675. ie: 'utf-8',
  676. rich_text: 1,
  677. floor_num: config.post.floor_num,
  678. fid: config.post.forum_id,
  679. tid: config.post.thread_id,
  680. content: content,
  681. anonymous: 0,
  682. tbs: config.post.tbs,
  683. vcode_md5: config.captcha.code,
  684. vcode: config.captcha.input
  685. },
  686. dataType: 'json'
  687. }).done(function(data){
  688. parsePostReplay(data);
  689. });
  690. };
  691.  
  692. function parsePosting(data) {
  693. if (!data.no) {
  694. handleGetPosts(config.posts.page_url);
  695. $('.tba-modal').omniWindow().trigger('hide');
  696. return;
  697. }
  698. var vhtml = '', da = data.data;
  699. var captHtml = parsePostCaptcha(da);
  700. if (!captHtml) {
  701. return;
  702. }
  703. $('#modal_other').html(captHtml);
  704. mointorCaptcha();
  705. };
  706.  
  707. function parsePostReplay(data) {
  708. if (!data.no) {
  709. handleGetPost(config.post.page_url);
  710. $('.tba-modal').omniWindow().trigger('hide');
  711. return;
  712. }
  713. var vhtml = '', da = data.data;
  714. var captHtml = parsePostCaptcha(da);
  715. if (!captHtml) {
  716. return;
  717. }
  718. $('#modal_other').html(captHtml);
  719. mointorCaptcha();
  720. };
  721.  
  722. function parseLzlReplay(data, mark) {
  723. if (!data.no) {
  724. handleGetLzlReplay();
  725. return;
  726. }
  727. var vhtml = '', da = data.data;
  728. var captHtml = parsePostCaptcha(da);
  729. if (!captHtml) {
  730. return;
  731. }
  732. $('.lzl_replay_other').html(captHtml);
  733. mointorCaptcha();
  734. };
  735.  
  736. function parsePostCaptcha(data) {
  737. config.captcha.value = [];
  738. var vhtml = '';
  739. if (!data.vcode.need_vcode) {
  740. return null;
  741. }
  742. config.captcha.code = data.vcode.captcha_vcode_str;
  743. config.captcha.type = data.vcode.captcha_code_type;
  744. var img = config.captcha.url4 + '?' + data.vcode.captcha_vcode_str;
  745. vhtml += '<div class="box_captcha">';
  746. vhtml += '<div class="loop-12 captcha"><img src="' + img + '"></div>';
  747. vhtml += '<div class="loop-12 captcha-input">\
  748. <input type="checkbox" class="cait cait-1" data-index="1" value="00000000">\
  749. <input type="checkbox" class="cait cait-2" data-index="2" value="00010000">\
  750. <input type="checkbox" class="cait cait-3" data-index="3" value="00020000">\
  751. <input type="checkbox" class="cait cait-4" data-index="4" value="00000001">\
  752. <input type="checkbox" class="cait cait-5" data-index="5" value="00010001">\
  753. <input type="checkbox" class="cait cait-6" data-index="6" value="00020001">\
  754. <input type="checkbox" class="cait cait-7" data-index="7" value="00000002">\
  755. <input type="checkbox" class="cait cait-8" data-index="8" value="00010002">\
  756. <input type="checkbox" class="cait cait-9" data-index="9" value="00020002">\
  757. </div>';
  758. // vhtml += '<div class="loop-12"><button type="button" id="btn_refre_captcha">换一张</button></div>';
  759. vhtml += '<div class="loop-12"><div class="loop-10" id="captchackr"></div><div class="loop-2" id="delcaptchar">X</div></div>';
  760. vhtml += '<div class="loop-12" id="post-result"></div>';
  761. vhtml += '</div>';
  762. return vhtml;
  763. };
  764.  
  765. function mointorCaptcha() {
  766. $('.cait').bind('click', function(){
  767. if (config.captcha.value.length<4) {
  768. $(this).prop({disabled: true});
  769. config.captcha.value.push({val: $(this).val(), index: $(this).data('index')});
  770. $('#captchackr').append('<span id="checkcaptchar-' + $(this).data('index') + '">' + $(this).data('index') + '</span>');
  771. if (config.captcha.value.length==4) {
  772. var captVal = '';
  773. for(var i=0; i<config.captcha.value.length; i++) {
  774. captVal += config.captcha.value[i].val;
  775. }
  776. config.captcha.input = captVal;
  777. }
  778. return;
  779. }
  780. });
  781. $('#delcaptchar').bind('click', function(){
  782. for(var i=0; i<config.captcha.value.length; i++) {
  783. if ((i+1)==config.captcha.value.length) {
  784. $('#checkcaptchar-' + config.captcha.value[i].index).remove();
  785. $('.cait-' + config.captcha.value[i].index).prop({disabled: false, checked: false});
  786. config.captcha.value.remove((i+1));
  787. }
  788. }
  789. });
  790. /*
  791. $('#btn_refre_captcha').bind('click', function(){
  792. // $('#btn_post').click();
  793. });
  794. */
  795. };
  796.  
  797.  
  798.  
  799. function parseMsgPage(data) {
  800. var msgs = data.find('#feed li');
  801. var atmeuser = msgs.find('.atme_user');
  802. var atmecnt = msgs.find('.atme_content');
  803. var feedfrom = msgs.find('.feed_from');
  804. var replayuser = msgs.find('.replyme_user');
  805. var replaycnt = msgs.find('.replyme_content');
  806. var feature = data.find('#featureList');
  807. var fansbox = data.find('#follow');
  808. var shtml = '';
  809. shtml += '<div class="span box_tbmsg">';
  810. if (atmeuser.length) {
  811. for (var i = 0; i < atmeuser.length; i++) {
  812. shtml += '<div class="msg_cnt">';
  813. shtml += '<div class="loop-2 msg_row_1 atme_user">' + atmeuser[i].innerHTML + '</div>';
  814. shtml += '<div class="loop-10 msg_row_2 atme_content">' + atmecnt[i].innerHTML + '</div>';
  815. shtml += '<div class="loop-12 msg_row_3 feed_from">' + feedfrom[i].innerHTML + '</div>';
  816. shtml += '</div>';
  817. }
  818. }
  819. if (replayuser.length) {
  820. for (var i = 0; i < replayuser.length; i++) {
  821. shtml += '<div class="msg_cnt">\
  822. <div class="loop-2 msg_row_1 replay_user">' + replayuser[i].innerHTML + '</div>\
  823. <div class="loop-10 msg_row_2 replay_content">' + replaycnt[i].innerHTML + '</div>\
  824. <div class="loop-12 msg_row_3 feed_from">' + feedfrom[i].innerHTML + '</div>\
  825. </div>';
  826. }
  827. }
  828. if (feature.length) {
  829. var feature_title = feature.find('.feature_title');
  830. var feature_ext = feature.find('.feature_title_ext');
  831. for (var i = 0; i < feature_title.length; i++) {
  832. shtml += '<div class="msg_cnt">';
  833. shtml += '<div class="loop-12 msg_row_1 feature_title">' + feature_title[i].innerHTML + '</div>';
  834. shtml += '<div class="loop-12 msg_row_2 feature_ext">' + feature_ext[i].innerHTML + '</div>';
  835. shtml += '</div>';
  836. }
  837. }
  838. if (fansbox.length) {
  839. var user = fansbox.find('.user');
  840. var page = fansbox.find('#pagerPanel div.pager');
  841. for(var i=0; i<user.length; i++) {
  842. var avatar = $(user[i]).find('.left img');
  843. var uinfo = $(user[i]).find('.mid');
  844. var ufns = $(user[i]).find('.right');
  845. shtml += '<div class="msg_cnt">';
  846. shtml += '<div class="loop-2 fans_avatar"><img src="' + avatar[0].getAttribute('isrc') + '"></div>';
  847. shtml += '<div class="loop-8 fans_infos">' + (uinfo.text()||'') + '</div>';
  848. shtml += '<div class="loop-2 fans_status">' + (ufns.text()||'') + '</div>';
  849. shtml += '</div>';
  850. }
  851. shtml += '<div class="loop-12 fans_page">' + (page.html()||'') + '</div>';
  852. }
  853. shtml += '</div>';
  854. return shtml;
  855. };
  856.  
  857. function mointorTiebaMessage() {
  858. /*
  859. if (!config.message.number.total) {
  860. return;
  861. }
  862. */
  863. var html = '';
  864. html += '<div class="span">\
  865. <div class="loop-12 tb-msg-btn-group">\
  866. <button class="btn btn-msg-fans">粉丝<span class="msg-num-fans">' + (config.message.number.fans||'') + '</span></button>\
  867. <button class="btn btn-msg-replay">回复<span class="msg-num-replay">' + (config.message.number.replay||'') + '</span></button>\
  868. <button class="btn btn-msg-atme">@我<span class="msg-num-atme">' + (config.message.number.atme||'') + '</span></button>\
  869. <button class="btn btn-msg-feature">精品<span class="msg-num-feature">' + (config.message.number.feature||'') + '</span></button>\
  870. <button class="btn btn-msg-recycle">回收站<span class="msg-num-recycle">' + (config.message.number.recycle||'') + '</span></button>\
  871. </div>\
  872. <div class="loop-12 tb-msg-content"></div>\
  873. </div>';
  874. $('.tba-modal').html(html);
  875. $('.tba-modal').omniWindow().trigger('show');
  876. mointorTiebaMsgBtn();
  877. };
  878.  
  879. function mointorTiebaMsgBtn() {
  880. $('.btn-msg-fans').bind('click', function(){
  881. handleGetMsgFans(config.message.url.fans);
  882. });
  883. $('.btn-msg-replay').bind('click', function(){
  884. $.ajax({
  885. url: config.message.url.replay,
  886. dataType: 'html',
  887. type: 'get'
  888. }).done(function(data){
  889. var shtml = parseMsgPage($(data));
  890. disposeTiebaMessage({category: 2, content: shtml});
  891. });
  892. });
  893. $('.btn-msg-atme').bind('click', function(){
  894. $.ajax({
  895. url: config.message.url.atme,
  896. dataType: 'html',
  897. type: 'get'
  898. }).done(function(data){
  899. var shtml = parseMsgPage($(data));
  900. disposeTiebaMessage({category: 3, content: shtml});
  901. });
  902. });
  903. $('.btn-msg-feature').bind('click', function(){
  904. $.ajax({
  905. url: config.message.url.feature,
  906. dataType: 'html',
  907. type: 'get'
  908. }).done(function(data){
  909. var shtml = parseMsgPage($(data));
  910. disposeTiebaMessage({category: 4, content: shtml});
  911. });
  912. });
  913. $('.btn-msg-recycle').bind('click', function(){
  914. var shtml = '<div class="span"><div class="loop-12">\
  915. <button class="btn btn_recycle" data-who="bawu">吧主团队删贴</button>\
  916. <button class="btn btn_recycle" data-who="system">系统删贴</button>\
  917. <button class="btn btn_recycle" data-who="louzhu">楼主删贴</button>\
  918. <button class="btn btn_recycle" data-who="self">自己删贴</button>\
  919. </div><div class="loop-12 result-recycle"></div><div class="loop-12 detail-recycle"></div></div>';
  920. disposeTiebaMessage({category: 5, content: shtml});
  921. });
  922. };
  923.  
  924. function handleGetMsgFans(url) {
  925. $.ajax({
  926. url: url,
  927. dataType: 'html',
  928. type: 'get'
  929. }).done(function(data){
  930. var shtml = parseMsgPage($(data));
  931. disposeTiebaMessage({category: 1, content: shtml});
  932. });
  933. };
  934.  
  935. function disposeTiebaMessage(data) {
  936. $('.tb-msg-content').html(data.content);
  937. switch(data.category){
  938. case 5:
  939. $('.btn_recycle').bind('click', function(){
  940. config.message.recycle.currentPage = 1;
  941. handleGetRecycle($(this).data('who'));
  942. });
  943. return false;
  944. };
  945. $('.msg_cnt a').bind('click', function(){
  946. try {
  947. if (this.href.match(/\/f\?kw=.*/)) {
  948. handleGetPosts(this.href);
  949. openPosts();
  950. }
  951. if (this.href.match(/\p\/.*/)) {
  952. handleGetPost(this.href);
  953. closePosts();
  954. }
  955. if (this.href.match(/(.*=.*&)/)) {
  956. handleGetPost(this.href);
  957. closePosts();
  958. }
  959. if (this.href.match(/\/i\/.*/)) {
  960.  
  961. }
  962. } catch (e) {
  963. console.log(e);
  964. console.log('...这什么错');
  965. } finally {
  966. $('.tba-modal').omniWindow().trigger('hide');
  967. return false;
  968. }
  969. });
  970. !$('.fans_page').length||$('.fans_page a').bind('click', function(){
  971. handleGetMsgFans(this.href);
  972. return false;
  973. });
  974. return false;
  975. };
  976.  
  977. function handleGetRecycle(who){
  978. $('.detail-recycle').text('');
  979. $.ajax({
  980. url: config.message.recycle.url,
  981. type: 'post',
  982. dataType: 'json',
  983. data: {
  984. bywho: who,
  985. curpage: config.message.recycle.currentPage,
  986. pagenum: config.message.recycle.pageSize
  987. }
  988. }).done(function(data){
  989. var rlrcl = parseRecycle(data);
  990. $('.result-recycle').html(rlrcl.result);
  991. mointorRecycleResult(rlrcl.page);
  992. });
  993. };
  994.  
  995.  
  996. function parseRecycle(data) {
  997. if (data.errno) {
  998. return;
  999. }
  1000. var rfo = null;
  1001. if (data.barServicePosts) {
  1002. rfo = data.barServicePosts.userthreadinfo;
  1003. }
  1004. if (data.systemPosts) {
  1005. rfo=data.systemPosts.userthreadinfo;
  1006. }
  1007. if (data.landlordPosts) {
  1008. rfo=data.landlordPosts.userthreadinfo;
  1009. }
  1010. if (data.selfPosts) {
  1011. rfo = data.selfPosts.userthreadinfo;
  1012. }
  1013. var totalSize = rfo.totalnum;
  1014. var currPage = rfo.curpage;
  1015. var who = rfo.bywho;
  1016. var rfd = rfo.data;
  1017. var page = false;
  1018. var rhtml = '';
  1019. rhtml += '<div class="span box_recycle">';
  1020. rhtml += '<div class="recycle_title">';
  1021. rhtml += '<div class="loop-3">吧名</div>';
  1022. rhtml += '<div class="loop-3">帖子主题</div>';
  1023. rhtml += '<div class="loop-3">贴子内容</div>';
  1024. rhtml += '<div class="loop-3">删贴时间</div>';
  1025. rhtml += '</div>';
  1026. for(var i=0; i<rfd.length; i++) {
  1027. rhtml += '<div class="recyle_items">';
  1028. rhtml += '<div class="loop-3 hidefont del_forum_name">' + rfd[i].forum_name + '</div>';
  1029. rhtml += '<div class="loop-3 hidefont del_post_title">' + rfd[i].title + '</div>';
  1030. rhtml += '<div class="loop-3 hidefont del_post_content">' + rfd[i].content + '</div>';
  1031. rhtml += '<div class="loop-3 hidefont del_time">' + rfd[i].delete_time + '</div>';
  1032. rhtml += '</div>';
  1033. }
  1034. //rhtml ='';
  1035. if (totalSize>config.message.recycle.pageSize) {
  1036. var totalPage = window.Math.ceil(totalSize/config.message.recycle.pageSize);
  1037. rhtml += '<div class="recycle_page">';
  1038. if (config.message.recycle.currentPage>1) {
  1039. rhtml += '<a data-page="' + (config.message.recycle.currentPage-1) + '" data-who="' + who + '">上一页</a>';
  1040. }
  1041. if (config.message.recycle.currentPage<totalPage) {
  1042. rhtml += '<a data-page="' + (config.message.recycle.currentPage+1) + '" data-who="' + who + '">下一页</a>';
  1043. }
  1044. rhtml += '<span>' + config.message.recycle.currentPage + '</span>';
  1045. rhtml += '</div>';
  1046. page = true;
  1047. }
  1048. rhtml += '</div>';
  1049. return {page: page, result: rhtml};
  1050. };
  1051.  
  1052.  
  1053. function mointorRecycleResult(page){
  1054. if (page) {
  1055. $('.recycle_page a').bind('click', function(){
  1056. config.message.recycle.currentPage = $(this).data('page');
  1057. handleGetRecycle($(this).data('who'));
  1058. });
  1059. }
  1060. $('.recyle_items').bind('click', function(){
  1061. var dhtml = '';
  1062. dhtml += '<div class="span">';
  1063. dhtml += '<div class="loop-12 detail-recycle-forum"><label>吧名:</label>' + $(this).find('.del_forum_name').html() + '</div>';
  1064. dhtml += '<div class="loop-12 detail-recycle-title"><label>帖子主题:</label>' + $(this).find('.del_post_title').html() + '</div>';
  1065. dhtml += '<div class="loop-12 detail-recycle-time"><label>删贴时间:</label>' + $(this).find('.del_time').html() + '</div>';
  1066. dhtml += '<div class="loop-12 detail-recycle-content"><label>贴子内容:</label>' + $(this).find('.del_post_content').text() + '</div>';
  1067. dhtml += '</div>';
  1068. $('.detail-recycle').html(dhtml);
  1069. });
  1070. };
  1071.  
  1072.  
  1073.  
  1074. tborer.parseTiebaMessage = function(msg) {
  1075. this.config.message.number.fans = msg[0]||0;
  1076. this.config.message.number.replay = msg[3]||0;
  1077. this.config.message.number.feature = msg[4]||0;
  1078. this.config.message.number.atme = msg[8]||0;
  1079. this.config.message.number.recycle = msg[9]||0;
  1080. this.config.message.number.total =
  1081. this.config.message.number.fans+
  1082. this.config.message.number.replay+
  1083. this.config.message.number.feature+
  1084. this.config.message.number.atme+
  1085. this.config.message.number.recycle;
  1086. $('.btn_tb_msg span.tb-msg-num').text(this.config.message.number.total||'');
  1087. };
  1088. tborer.handleGetTiebaMessage = function(){
  1089. loadFile('http://message.tieba.baidu.com/i/msg/get_data', 'js');
  1090. };
  1091.  
  1092. /*
  1093. tborer.handleHistory = function(state){
  1094. config.history.data = state;
  1095. console.log(state);
  1096. if (state.data.mark == 'post') {
  1097. $.ajax({
  1098. // url: config.history.url,
  1099. url: state.url,
  1100. dataType: 'html'
  1101. }).done(function(data){
  1102. initPost(parsePost($(data)));
  1103. setPostConfig($(data).text());
  1104. });
  1105. };
  1106. if (state.data.mark == 'posts') {
  1107. $.ajax({
  1108. url: state.url,
  1109. dataType: 'html'
  1110. }).done(function(data){
  1111. setPostsConfig($(data).text());
  1112. initPosts(parsePosts($(data)));
  1113. });
  1114. };
  1115. };
  1116. */
  1117.  
  1118. function openPosts() {
  1119. $('#box_posts').addClass('show');
  1120. };
  1121. function closePosts() {
  1122. $('#box_posts').removeClass('show');
  1123. };
  1124.  
  1125. function loadFile(filename,filetype){
  1126. if ('js' == filetype) {
  1127. var fileref = document.createElement('script');
  1128. fileref.setAttribute("type","text/javascript");
  1129. fileref.setAttribute("src",filename);
  1130. }
  1131. if ('css' == filetype) {
  1132. var fileref = document.createElement('link');
  1133. fileref.setAttribute("rel","stylesheet");
  1134. fileref.setAttribute("type","text/css");
  1135. fileref.setAttribute("href",filename);
  1136. }
  1137. if(typeof fileref != "undefined"){
  1138. document.getElementsByTagName("head")[0].appendChild(fileref);
  1139. }
  1140. };
  1141.  
  1142. function encodeUnicode(str){
  1143. return escape(str).toLocaleLowerCase().replace(/%u/gi,'\\u');
  1144. };
  1145.  
  1146. function decodeUnicode(str){
  1147. return unescape(str.replace(/\\u/gi,'%u'));
  1148. };
  1149.  
  1150. function formatEditor(content) {
  1151. return content.replace(/<p>|<br\/>/gi, '').replace(/<\/p>/gi, '[br]').replace(/_src=".*?"/gi, 'class="BDE_Smiley"');
  1152. };
  1153.  
  1154. initBorer();
  1155. })(window, jQuery);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址