// ==UserScript== // @name tb_borer // @namespace http://wp.stf.iaceob.name // @description tba_style // @include http://tieba.baidu.com/* // @version 1.6 alpha // @grant none // @author 生物烯丙菊 // @downloadURL none // ==/UserScript== String.prototype.format = function () { var txt = this.toString(); for (var i = 0; i < arguments.length; i++) { var exp = getStringFormatPlaceHolderRegEx(i); txt = txt.replace(exp, (arguments[i] == null ? "" : arguments[i])); } return cleanStringFormatResult(txt); } function getStringFormatPlaceHolderRegEx(placeHolderIndex) { return new RegExp('({)?\\{' + placeHolderIndex + '\\}(?!})', 'gm'); } function cleanStringFormatResult(txt) { if (txt == null) return ""; return txt.replace(getStringFormatPlaceHolderRegEx("\\d+"), ""); } Array.prototype.remove=function(dx) { if(isNaN(dx)||dx>this.length){ return false; } for(var i=0,n=0;i'); $('head').append(''); }; function monitorHPage() { $('#btn_posting').bind('click', function(){ var pshtml = ''; pshtml += '
\ \ \ \
\
'; $('.tba-modal').html(pshtml); $('.tba-modal').omniWindow().trigger('show'); $('#btn_submit').bind('click', function(){ var title = $('#posts_title').val(); var content = $('#posts_editor').val(); executePosting(title, content); }); }); $('.posts_paging a').bind('click', function(){ handleGetPosts(this.href); return false; }); $('.posts_list li').bind('click', function(){ handleGetPost($(this).data('href')); }); }; function mointorPPage() { $('.post-page a').bind('click', function(){ handleGetPost(this.href); return false; }); $('#post_replay').bind('click', function(){ var pshtml = ''; pshtml += '
\ \ \ \
\
'; $('.tba-modal').html(pshtml); $('.tba-modal').omniWindow().trigger('show'); $('#btn_submit').bind('click', function(){ var content = $('#post_editor').val(); executPostReplay(content); }); }); $('.btn_replay_lzl').bind('click', function(){ config.post.lzl_pn = 1; config.post.floor_num = $(this).data('floor'); config.post.post_id = $(this).data('pid'); handleGetLzlReplay($(this).data('pid')); }); }; function mointorSearch(){ $.ajax({ url: 'http://tieba.baidu.com/suggestion', data: $('#query').serialize(), dataType: 'json', }).done(function(data){ $('#search_list').html(parseSearch(data)); }); }; function mointorLzlReplay(pid, html) { $('.tba-modal').html(html); $('.tba-modal').omniWindow().trigger('show'); $('.lzl-page a').bind('click', function(){ config.post.lzl_pn = this.href.split('#')[1]; handleGetLzlReplay(pid); }); $('.btn_lzl_replay').bind('click', function(){ var pid = $(this).data('pid'); var lrp = '
\
\
\ \
\
\
'; $('#lzl-' + pid).append(lrp); monitorBtnLzlReplay(); }); }; function monitorBtnLzlReplay() { $('#btn_handle_replay_lzl').bind('click', function(){ var pid = $(this).data('pid'); var content = $('#lzl-editor-' + pid).val(); $.ajax({ url: config.post.handle_url, type: 'post', data: { anonymous: 0, fid: config.post.forum_id, floor_num: config.post.floor_num, ie: 'utf-8', kw: config.post.forum_name, quote_id: config.post.post_id, repostid: config.post.post_id, rich_text: 1, // tag: 11, tbs: config.post.tbs, tid: config.post.thread_id, new_vcode: 1, content: content, vcode_md5: config.captcha.code, vcode: config.captcha.input }, dataType: 'json' }).done(function(data){ parseLzlReplay(data); }); }); }; window.handleSearchResult = function(forum){ var url = 'http://tieba.baidu.com/' + forum; handleGetPosts(url); window.history.pushState(config.history, null, url); }; function handleGetPosts(postsUrl) { config.posts.page_url = postsUrl; window.history.pushState(config.history, null, postsUrl); $.ajax({ url: postsUrl, dataType: 'html' }).done(function(data){ setPostsConfig($(data).text()); initPosts(parsePosts($(data))); }); }; function handleGetLzlReplay(pid) { $.ajax({ url: config.post.lzl_url, data: {tid: config.post.thread_id, pid: pid, pn: config.post.lzl_pn}, dataType: 'html' }).done(function(data){ window.da = $(data); var lhtml = parsePostLzl($(data)); mointorLzlReplay(pid, lhtml); }); }; function handleGetPost(postUrl) { config.post.page_url = postUrl; window.history.pushState(config.history, null, postUrl); $.ajax({ url: postUrl, dataType: 'html' }).done(function(data){ initPost(parsePost($(data))); setPostConfig($(data).text()); }); }; function setPostsConfig(text) { window.t=text; var tbs = text.match(/PageData.tbs([ ]*)=([ ]*)"(.*?)"/);//[3] var fid = text.match(/PageData.forum([ ]*)=([ ]*){(.*?)"forum_id":(\d+)/); var fe = text.match(/PageData.forum([ ]*)=([ ]*){(.*?)"forum_name":"(.*?)"/); config.posts.tbs = !tbs ? '' : tbs[3]; config.posts.forum_id = !fid ? 0 : fid[4]; config.posts.forum_name = !fe ? '' : decodeUnicode(fe[4]); }; function setPostConfig(text){ var tbs1 = text.match(/PageData([ ]*)=([ ]*){(.*?)'tbs'(.*?):(.*?)"(.*?)"/); var tbs2 = text.match(/PageData([ ]*)=([ ]*){(.*?)tbs(.*?):(.*?)'(.*?)'/); var fid = text.match(/PageData.forum([ ]*)=([ ]*){(.*?)"forum_id":(\d+)/); var fe = text.match(/PageData.forum([ ]*)=([ ]*){(.*?)"forum_name":"(.*?)"/); var tid = text.match(/PageData.thread([ ]*)=([ ]*){(.*?)thread_id(.*?):(\d+)/); config.post.tbs = !tbs1 ? tbs2[6] : tbs1[6]; config.post.forum_id = !fid ? 0 : fid[4]; config.post.forum_name = !fe ? '' : decodeUnicode(fe[4]); config.post.thread_id = !tid ? 0 : tid[5]; }; function bindEvent() { $('#query').bind('keyup', function(event){ $('#search_list').show(); if (event.keyCode != 13) { mointorSearch(); return; } event.cancelBubble = true; event.returnValue = false; window.handleSearchResult($(this).val()); }); $('#query').bind('click', function(){ $('#search_list').show(); mointorSearch(); }); $('#search_list').hover(function(){ $(this).show(); }, function(){ $(this).hide(); }); }; function parseFooter() { var tf = $('#footer').html(); var fhtml = '
' + tf + '
'; return fhtml; }; function parseSearch(data) { var qms = data.query_match.search_data; if (qms.length==0) { return '

无数据'; } var qhtml = '

'; return qhtml; }; function parsePosts(postsDom) { var h_posts = postsDom.find('li.j_thread_list'); var h_paging = postsDom.find('#frs_list_pager'); var h_cur_page = postsDom.find('#frs_list_pager .cur'); var h_cur_url = !h_cur_page.length ? '#?' + window.Math.random() : '/f?kw=' + config.posts.forum_name + '&pn=' + (h_cur_page.text()*50-50); var ho_pobj = {}, posts_html=''; posts_html='
    '; for(var i=0; i\
    \
    ' + hp_title + '
    \ \
    ' + hp_detail + '
    \
    最后回复人:' + hp_last_repuser + '
    \
    最后回复时间:' + hp_last_time + '
    '; } posts_html += '
'; posts_html += '
' + (!h_paging.length ? '' : h_paging.html()) + '刷新发帖
'; return posts_html; }; function parsePost(postDom) { var post_title = postDom.find('.core_title_txt').html() var post_info = postDom.find('.l_post'); var post_content = postDom.find('.p_content cc'); var author_avatar = postDom.find('.p_author_face img'); var lzlbox = postDom.find('j_lzl_c_b_a'); var ppage = postDom.find('.pb_list_pager')[0]; var post_html = ''; post_html += '
' + post_title + '
'; for(var i=0; i'; post_html += ''; post_html += '
' + pc.innerHTML + '
'; post_html += '
楼中楼
' + pi.content.post_no + '楼
' + pi.content.date + '
'; post_html += ''; } post_html += '
' + ppage.innerHTML + '回复
'; post_html += '
' + config.post.page_url + '
'; // 只看楼主 post_html='
' +post_html+ '
'; return post_html; }; function parsePostLzl(data) { var lzlhtml = '
    '; for(var i=0; i\
    \
    ' + lzlinfo.user_name + '
    \
    ' + lzltext + '
    \
    \ ' + lzltime + '\ 回复
    \
    '; } var lzlp = $(data[data.length-1]).find('.j_pager'); lzlhtml += '
'; lzlhtml += !lzlp.length ? '' : '
' + lzlp.html() + '
'; '
'; return lzlhtml; }; function executePosting(title, content){ $.ajax({ url: config.posts.handle_url, type: 'post', data: { content: content, fid: config.posts.forum_id, floor_num: config.posts.floor_num, ie: 'utf-8', kw: config.posts.forum_name, rich_text: 1, tbs: config.posts.tbs, tid: 0, title: title, vcode: config.captcha.input, vcode_md5: config.captcha.code }, dataType: 'json' }).done(function(data){ parsePosting(data); }); }; function executPostReplay(content) { $.ajax({ url: config.post.handle_url, type: 'post', data: { kw: config.post.forum_name, ie: 'utf-8', rich_text: 1, floor_num: config.post.floor_num, fid: config.post.forum_id, tid: config.post.thread_id, content: content, anonymous: 0, tbs: config.post.tbs, vcode_md5: config.captcha.code, vcode: config.captcha.input }, dataType: 'json' }).done(function(data){ parsePostReplay(data); }); }; function parsePosting(data) { if (!data.no) { handleGetPosts(config.posts.page_url); $('.tba-modal').omniWindow().trigger('hide'); return; } var vhtml = '', da = data.data; var captHtml = parsePostCaptcha(da); if (!captHtml) { return; } $('#modal_other').html(captHtml); mointorCaptcha(); }; function parsePostReplay(data) { if (!data.no) { handleGetPost(config.post.page_url); $('.tba-modal').omniWindow().trigger('hide'); return; } var vhtml = '', da = data.data; var captHtml = parsePostCaptcha(da); if (!captHtml) { return; } $('#modal_other').html(captHtml); mointorCaptcha(); }; function parseLzlReplay(data) { if (!data.no) { var rhtml = '
  • \
    笑谈那一指风华
    \
    '+data.data.content+'
    \
    \ 2014-7-28 21:04\ 回复\
    \
    '; $('.box_lzl ul').append(rhtml); $('.lzl_replay_other').empty(); return; } var vhtml = '', da = data.data; var captHtml = parsePostCaptcha(da); if (!captHtml) { return; } $('.lzl_replay_other').html(captHtml); mointorCaptcha(); }; function parsePostCaptcha(data) { config.captcha.value = []; var vhtml = ''; if (!data.vcode.need_vcode) { return null; } config.captcha.code = data.vcode.captcha_vcode_str; config.captcha.type = data.vcode.captcha_code_type; var img = config.captcha.url4 + '?' + data.vcode.captcha_vcode_str; vhtml += '
    '; vhtml += '
    '; vhtml += '
    \ \ \ \ \ \ \ \ \ \
    '; // vhtml += '
    '; vhtml += '
    X
    '; vhtml += '
    '; vhtml += '
    '; return vhtml; }; function mointorCaptcha() { $('.cait').bind('click', function(){ if (config.captcha.value.length<4) { $(this).prop({disabled: true}); config.captcha.value.push({val: $(this).val(), index: $(this).data('index')}); $('#captchackr').append('' + $(this).data('index') + ''); if (config.captcha.value.length==4) { var captVal = ''; for(var i=0; i