tb_borer

tba_style

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

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