// ==UserScript== // @name tb_borer // @namespace iaceob_tborer // @description tba_style // @include http://tieba.baidu.com/* // @version 2.2 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+"), ""); }; String.prototype.filterHtmlTag = function(){ var str = this.toString(); str = str.replace(//g, '>'); str = str.replace(/"/g, '"'); str = str.replace(/'/g, '''); return str; }; Array.prototype.remove=function(dx) { if(isNaN(dx)||dx>this.length){ return false; } for(var i=0,n=0;i\
标题:
\
\ \ \ \
\ '; $('.tba-modal').html(pshtml); window.UM.delEditor('posts_editor'); var editor_posts = window.UM.getEditor('posts_editor'); config.editor = editor_posts; $('.tba-modal').omniWindow().trigger('show'); $('#btn_submit').bind('click', function(){ var title = $('#posts_title').val(); var content = formatEditor(editor_posts.getContent()); executePosting(title, content); }); }); $('.posts_paging a').bind('click', function(){ handleGetPosts(this.href); return false; }); $('.posts_list li').bind('click', function(){ config.history.title = $(this).find('.post_title').text(); // config.history.url = $(this).data('href'); handleGetPost($(this).data('href')); closePosts(); }); }; 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); window.UM.delEditor('post_editor'); var editor_post = window.UM.getEditor('post_editor'); config.editor = editor_post; $('.tba-modal').omniWindow().trigger('show'); $('#btn_submit').bind('click', function(){ var content = formatEditor(editor_post.getContent()); executPostReplay(content); }); }); $('.btn_replay_lzl').bind('click', function(){ if($(this).data('floor')==1) { $('#post_replay').click(); return; } config.post.lzl_pn = 1; config.post.floor_num = $(this).data('floor'); config.post.post_id = $(this).data('pid'); handleGetLzlReplay(); }); $('#see_lz').bind('click', function(){ if (config.post.see_lz) { config.post.see_lz = false; handleGetPost(config.post.page_url.split('?')[0]); return; } config.post.see_lz = true; handleGetPost(config.post.page_url.split('?')[0] + '?see_lz=1'); return; }); }; 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]; config.post.post_id = pid; handleGetLzlReplay(); }); $('.btn_lzl_replay').bind('click', function(){ $('.box_lzl_replay').empty(); var pid = $(this).data('spid'); var aur = $(this).data('author'); var lrp = '
\
\
\ \
\
\
'; $('#box_lzl_rep-' + pid).html(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, pid); }); }); }; window.handleSearchResult = function(forum){ var url = 'http://tieba.baidu.com/' + forum; handleGetPosts(url); config.history.title = forum; // config.history.url = url; window.history.pushState(config.history, null, url); }; function handleGetPosts(postsUrl) { // History.pushState({mark: 'posts'}, config.history.title, 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() { $.ajax({ url: config.post.lzl_url, data: {tid: config.post.thread_id, pid: config.post.post_id, pn: config.post.lzl_pn}, dataType: 'html' }).done(function(data){ window.da = $(data); var lhtml = parsePostLzl($(data)); mointorLzlReplay(config.post.post_id, lhtml); }); }; function handleGetPost(postUrl) { // History.pushState({mark: 'post'}, config.history.title, 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) { 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]); config.posts.page_url = 'http://tieba.baidu.com/' + config.posts.forum_name; }; 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() { window.tborer = tborer; $('#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(); openPosts(); }); $('#search_list').hover(function(){ $(this).show(); }, function(){ $(this).hide(); }); $('.btn_pl').bind('click', function(){ if ($('#box_posts').hasClass('show')) { closePosts(); return; } openPosts(); }); $('#post_container').bind('mousemove', function(event){ var e = event||window.event; // var h = window.innerHeight; var y = e.clientY; // || h-y<100 if(y<20){ $('#header').addClass('show'); return; } $('#header').removeClass('show'); }); $('.btn_gotop').bind('click', function(){ $('#post_container').animate({scrollTop:0},1000); }); $('.btn_godown').bind('click', function(){ $('#post_container').animate({scrollTop:$('#post_container')[0].scrollHeight},1000); }); $('.btn_tb_msg').bind('click', function(){ config.message.constraint = false; mointorTiebaMessage(); }); // window.setTimeout(getTiebaMessage(),5000); window.setTimeout(function(){ window.initItiebaMessage = function(msg){ tborer.parseTiebaMessage(msg); }; window.tiebaMsgTimer = setInterval(function(){ tborer.handleGetTiebaMessage(); }, config.message.interval); }, 3000); /* window.setTimeout(function(){ History.Adapter.bind(window,'statechange',function(){ tborer.handleHistory(History.getState()); }); }, 3000); */ }; 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.comment_num + ')
' + 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 + '\ 回复
    \
    \
    '; } lzlhtml += '
'; lzlhtml += '
\
\ 回复
\
\
\
'; var lzlp = $(data[data.length-1]).find('.j_pager'); lzlhtml += !lzlp.length ? '' : '
' + lzlp.html() + '
'; lzlhtml += ''; 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, mark) { if (!data.no) { handleGetLzlReplay(); 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'; shtml += '
' + atmecnt[i].innerHTML + '
'; shtml += '
' + feedfrom[i].innerHTML + '
'; shtml += ''; } } if (replayuser.length) { for (var i = 0; i < replayuser.length; i++) { shtml += '
\
' + replayuser[i].innerHTML + '
\
' + replaycnt[i].innerHTML + '
\
' + feedfrom[i].innerHTML + '
\
'; } } if (feature.length) { var feature_title = feature.find('.feature_title'); var feature_ext = feature.find('.feature_title_ext'); for (var i = 0; i < feature_title.length; i++) { shtml += '
'; shtml += '
' + feature_title[i].innerHTML + '
'; shtml += '
' + feature_ext[i].innerHTML + '
'; shtml += '
'; } } if (fansbox.length) { var user = fansbox.find('.user'); var page = fansbox.find('#pagerPanel div.pager'); for(var i=0; i'; shtml += '
' + (uinfo.text()||'') + '
'; shtml += '
' + (ufns.text()||'') + '
'; shtml += ''; } shtml += '
' + (page.html()||'') + '
'; } shtml += ''; return shtml; }; function mointorTiebaMessage() { /* if (!config.message.number.total) { return; } */ var html = ''; html += '
\
\ \ \ \ \ \
\
\
'; $('.tba-modal').html(html); $('.tba-modal').omniWindow().trigger('show'); mointorTiebaMsgBtn(); }; function mointorTiebaMsgBtn() { $('.btn-msg-fans').bind('click', function(){ handleGetMsgFans(config.message.url.fans); }); $('.btn-msg-replay').bind('click', function(){ $.ajax({ url: config.message.url.replay, dataType: 'html', type: 'get' }).done(function(data){ var shtml = parseMsgPage($(data)); disposeTiebaMessage({category: 2, content: shtml}); }); }); $('.btn-msg-atme').bind('click', function(){ $.ajax({ url: config.message.url.atme, dataType: 'html', type: 'get' }).done(function(data){ var shtml = parseMsgPage($(data)); disposeTiebaMessage({category: 3, content: shtml}); }); }); $('.btn-msg-feature').bind('click', function(){ $.ajax({ url: config.message.url.feature, dataType: 'html', type: 'get' }).done(function(data){ var shtml = parseMsgPage($(data)); disposeTiebaMessage({category: 4, content: shtml}); }); }); $('.btn-msg-recycle').bind('click', function(){ var shtml = '
\ \ \ \ \
'; disposeTiebaMessage({category: 5, content: shtml}); }); }; function handleGetMsgFans(url) { $.ajax({ url: url, dataType: 'html', type: 'get' }).done(function(data){ var shtml = parseMsgPage($(data)); disposeTiebaMessage({category: 1, content: shtml}); }); }; function disposeTiebaMessage(data) { $('.tb-msg-content').html(data.content); switch(data.category){ case 5: $('.btn_recycle').bind('click', function(){ config.message.recycle.currentPage = 1; handleGetRecycle($(this).data('who')); }); return false; }; $('.msg_cnt a').bind('click', function(){ try { if (this.href.match(/\/f\?kw=.*/)) { handleGetPosts(this.href); openPosts(); } if (this.href.match(/\p\/.*/)) { handleGetPost(this.href); closePosts(); } if (this.href.match(/(.*=.*&)/)) { handleGetPost(this.href); closePosts(); } if (this.href.match(/\/i\/.*/)) { } } catch (e) { console.log(e); console.log('...这什么错'); } finally { $('.tba-modal').omniWindow().trigger('hide'); return false; } }); !$('.fans_page').length||$('.fans_page a').bind('click', function(){ handleGetMsgFans(this.href); return false; }); return false; }; function handleGetRecycle(who){ $('.detail-recycle').text(''); $.ajax({ url: config.message.recycle.url, type: 'post', dataType: 'json', data: { bywho: who, curpage: config.message.recycle.currentPage, pagenum: config.message.recycle.pageSize } }).done(function(data){ var rlrcl = parseRecycle(data); $('.result-recycle').html(rlrcl.result); mointorRecycleResult(rlrcl.page); }); }; function parseRecycle(data) { if (data.errno) { return; } var rfo = null; if (data.barServicePosts) { rfo = data.barServicePosts.userthreadinfo; } if (data.systemPosts) { rfo=data.systemPosts.userthreadinfo; } if (data.landlordPosts) { rfo=data.landlordPosts.userthreadinfo; } if (data.selfPosts) { rfo = data.selfPosts.userthreadinfo; } var totalSize = rfo.totalnum; var currPage = rfo.curpage; var who = rfo.bywho; var rfd = rfo.data; var page = false; var rhtml = ''; rhtml += '
'; rhtml += '
'; rhtml += '
吧名
'; rhtml += '
帖子主题
'; rhtml += '
贴子内容
'; rhtml += '
删贴时间
'; rhtml += '
'; for(var i=0; i'; rhtml += '
' + rfd[i].title + '
'; rhtml += '
' + rfd[i].content + '
'; rhtml += '
' + rfd[i].delete_time + '
'; rhtml += '
'; } //rhtml =''; if (totalSize>config.message.recycle.pageSize) { var totalPage = window.Math.ceil(totalSize/config.message.recycle.pageSize); rhtml += '
'; if (config.message.recycle.currentPage>1) { rhtml += '上一页'; } if (config.message.recycle.currentPage下一页'; } rhtml += '' + config.message.recycle.currentPage + ''; rhtml += '
'; page = true; } rhtml += ''; return {page: page, result: rhtml}; }; function mointorRecycleResult(page){ if (page) { $('.recycle_page a').bind('click', function(){ config.message.recycle.currentPage = $(this).data('page'); handleGetRecycle($(this).data('who')); }); } $('.recyle_items').bind('click', function(){ var dhtml = ''; dhtml += '
'; dhtml += '
' + $(this).find('.del_forum_name').html() + '
'; dhtml += '
' + $(this).find('.del_post_title').html() + '
'; dhtml += '
' + $(this).find('.del_time').html() + '
'; dhtml += '
' + $(this).find('.del_post_content').text() + '
'; dhtml += '
'; $('.detail-recycle').html(dhtml); }); }; tborer.parseTiebaMessage = function(msg) { this.config.message.number.fans = msg[0]||0; this.config.message.number.replay = msg[3]||0; this.config.message.number.feature = msg[4]||0; this.config.message.number.atme = msg[8]||0; this.config.message.number.recycle = msg[9]||0; this.config.message.number.total = this.config.message.number.fans+ this.config.message.number.replay+ this.config.message.number.feature+ this.config.message.number.atme+ this.config.message.number.recycle; $('.btn_tb_msg span.tb-msg-num').text(this.config.message.number.total||''); }; tborer.handleGetTiebaMessage = function(){ loadFile('http://message.tieba.baidu.com/i/msg/get_data', 'js'); }; /* tborer.handleHistory = function(state){ config.history.data = state; console.log(state); if (state.data.mark == 'post') { $.ajax({ // url: config.history.url, url: state.url, dataType: 'html' }).done(function(data){ initPost(parsePost($(data))); setPostConfig($(data).text()); }); }; if (state.data.mark == 'posts') { $.ajax({ url: state.url, dataType: 'html' }).done(function(data){ setPostsConfig($(data).text()); initPosts(parsePosts($(data))); }); }; }; */ function openPosts() { $('#box_posts').addClass('show'); }; function closePosts() { $('#box_posts').removeClass('show'); }; function loadFile(filename,filetype){ if ('js' == filetype) { var fileref = document.createElement('script'); fileref.setAttribute("type","text/javascript"); fileref.setAttribute("src",filename); } if ('css' == filetype) { var fileref = document.createElement('link'); fileref.setAttribute("rel","stylesheet"); fileref.setAttribute("type","text/css"); fileref.setAttribute("href",filename); } if(typeof fileref != "undefined"){ document.getElementsByTagName("head")[0].appendChild(fileref); } }; function encodeUnicode(str){ return escape(str).toLocaleLowerCase().replace(/%u/gi,'\\u'); }; function decodeUnicode(str){ return unescape(str.replace(/\\u/gi,'%u')); }; function formatEditor(content) { return content.replace(/

|/gi, '').replace(/<\/p>/gi, '[br]').replace(/_src=".*?"/gi, 'class="BDE_Smiley"'); }; initBorer(); })(window, jQuery);