// ==UserScript== // @name tb_borer // @namespace http://wp.stf.iaceob.name // @description tba_style // @include http://tieba.baidu.com/* // @version 1.3 alpha // @grant none // @author 生物烯丙菊 // @downloadURL none // ==/UserScript== /* 00000000 00010000 00020000 00000001 00010001 00020001 00000002 00010002 00020002 http://tieba.baidu.com/f/commit/commonapi/checkVcode captcha_code_type captcha_input_str captcha_vcode_str fid */ 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() { $('.posts_paging a').bind('click', function(){ $.ajax({ url:this.href, dataType: 'html' }).done(function(data){ setPostsConfig($(data).text()); initPosts(parsePosts($(data))); }); 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; }); $('#btn_post').bind('click', function(){ var post_content = $('#post_editor').val(); $.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: post_content, anonymous: 0, tbs: config.post.tbs, vcode_md5: config.captcha.code, vcode: config.captcha.input }, dataType: 'json' }).done(function(data){ parseDoPost(data); }); }); }; function mointorSearch(){ $.ajax({ url: 'http://tieba.baidu.com/suggestion', data: $('#query').serialize(), dataType: 'json', }).done(function(data){ $('#search_list').html(parseSearch(data)); }); }; window.handleSearchResult = function(forum){ $.ajax({ url:'http://tieba.baidu.com/' + forum, dataType: 'html' }).done(function(data){ setPostsConfig($(data).text()); initPosts(parsePosts($(data))); }); }; function handleGetPost(postUrl) { config.post.page_url = postUrl; $.ajax({ url: postUrl, dataType: 'html' }).done(function(data){ initPost(parsePost($(data))); setPostConfig($(data).text()); }); }; function setPostsConfig(text) { window.t=text; var fid = text.match(/PageData.forum([ ]*)=([ ]*){(.*?)"forum_id":(\d+)/); var fe = text.match(/PageData.forum([ ]*)=([ ]*){(.*?)"forum_name":"(.*?)"/); 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.date + '
'; post_html += '
' + getPostLzl(lzlbox, i) + '
'; post_html += ''; } post_html += '