// -------------------------------------------------------------------- // // ==UserScript== // @name hjj_tidy // @namespace http://abbypan.github.io/ // @version 0.2 // @license MIT // @author Abby Pan (abbypan@gmail.com) // @description 红晋江( http://bbs.jjwxc.net ) 贴子整理,去广告,加跳转,只看楼主,最少字数等等 // @copyright 2014, Abby Pan (http://abbypan.github.io/) // @include *://bbs.jjwxc.net/showmsg.php?board=*&id=* // @include *://bbs.jjwxc.com/showmsg.php?board=*&id=* // @grant none // @downloadURL https://update.greasyfork.icu/scripts/502141/hjj_tidy.user.js // @updateURL https://update.greasyfork.icu/scripts/502141/hjj_tidy.meta.js // ==/UserScript== // // -------------------------------------------------------------------- function extract_floor_info(info) { var c = info.html() .replace(/^\s*[^<]+<\/font>
/,'') ; var w = info.text().length; var meta = info.parents("tr:eq(1)").next().text(); var m = meta.match(/№(\d+).+?☆☆☆(.*?)于([\d\s:-]+)留言☆☆☆/); return { content: c, word_num: w, id: parseInt(m[1]), poster: m[2] || ' ', time: m[3] }; } function format_floor_content(f) { var html = '
' + '
' + f.content + '
' + '№' + f.id + '☆☆☆' + f.poster + '' + f.time + '留言☆☆☆' + '   ' + '»' + '   ' + '' + '   ' + '' + '   ' + '' + '   ' + '' + '   ' + '' + '   ' + '' + '
'; //'' + //'   ' + //'' + //'   ' + return html; } function extract_showmsg_content(d){ var res = {}; var tm = $('title').text(); res["title"] = tm.replace(/―― 晋江文学城网友交流区/,'').replace(/^\s+/,'').replace(/\s+$/, ''); var pm = d.match(/\>(共\d+页:.+?)<\/div>/); res["pager"] = pm ? pm[1].replace(/<\/a>/g, ' ') : ''; var h = $.parseHTML(d); res["banner"] = $(h).find('a').eq(0).parent().html(); res["banner_reverse"] = res["banner"].replace(/^(.*?)(→.*?→)(.*)/, "$3$2$1"); res["reply_form"] = $(h).find('input[name="last_floor"]').parent().prop('outerHTML'); var poster = ''; var floors_info = new Array(); $(h).find('td[class="read"]').each(function() { var bot = $(this); var f_i = extract_floor_info(bot); if(!poster) poster = f_i.poster; var html = format_floor_content(f_i); floors_info.push(html); }).promise().done(function(){ var all_floor = floors_info.join("\n"); res["floor_list"] = all_floor; res["poster"] = poster; }); return res; } function get_css(){ return ' \ '; } function div_thread_action(){ return '
\ \ 字数 \   \ 抽取 \   过滤 \       \ 楼主 \   看图 \   倒序 \   全部 \ \
'; } (function(){ $ = unsafeWindow.jQuery; var d = $('body').html(); var res = extract_showmsg_content(d); var reply_thread_floor = function (){ $("#reply").find("textarea").val(""); var reply_type = $(this).attr("reply_type"); var c = $(this).parent().children(".chapter").text().replace(/\\n/g, " "); if(reply_type=="cite") c = "" + $(this).parent().children(".flcontent").text().replace(/(\\s*\\n)+/g, "\n").trim().substr(0, 300) + "......\n\n" + c ; $("#reply").find("textarea").val(c.trim()+"\n"); var pos = $("#reply").offset().top; $("html,body").animate({ scrollTop : pos },500); }; var filter_floor = function(is_to_filter,msg) { var i = 0; $(".floor").each(function() { if(i>0 && is_to_filter($(this))) $(this).hide(); i=1; }); if(msg) $("#thread_action_temp").html(msg); } ; $('head').html( '' + res["title"] + '' + get_css() ); $('body').html( '
' + res["banner"] + '

' + '
' + res["title"] + "

" + div_thread_action() + '

' + '
' + res["pager"] + '
' + '
' + res["floor_list"] + '
' + '
' + res["pager"] + '
' + '' + '
' + res["reply_form"] + '
' ); $('body').on('click', '.jump_to_top', function(){ $('html,body').animate({ 'scrollTop': 0 }, 500); }); $('body').on('click', '.jump_to_bottom', function(){ var f = $('#pager_bottom').offset(); $("html,body").animate({ scrollTop : f.top },500); }); $('body').on('click','.jump_to_next', function(){ var x = $(this).parent().nextAll(); var i = 50-1; if(x[i]) { var pos = $(x[i]).offset().top; $("html,body").animate({ scrollTop : pos },500); } }); $('body').on('click','.jump_to_prev', function(){ var x = $(this).parent().prevAll(); var i = 50-1; if(x[i]) { var pos = $(x[i]).offset().top; $("html,body").animate({ scrollTop : pos },500); } }); $('body').on('click', '.reply_thread_floor',function(){ $('#reply').find('textarea').val(''); var reply_type = $(this).attr("reply_type"); var c = $(this).parent().children('.chapter').text().replace(/\n/g, ' '); if(reply_type=="cite") c = "" + $(this).parent().children('.flcontent').text().replace(/(\s*\n)+/g, "\n").trim().substr(0, 300) + "......\n\n" + c ; $('#reply').find('textarea').val(c.trim()+"\n"); var pos = $('#reply').offset().top; $("html,body").animate({ scrollTop : pos },500); }); $('body').on('click', '#view_all_floor', function(){ $(".floor").each(function() { $(this).show(); }); $("#thread_action_temp").html("全部"); }); $('body').on('click', '#view_img', function(){ var is_to_filter = function(f){ var c = f.find(".flcontent").eq(0).html(); return c.match(/\0){ return $(".floor").eq(0).find(".floor_poster").text(); } return; }; $('body').on('click', '#only_poster', function(){ var poster = get_showmsg_poster(); var is_to_filter = function(f){ var flposter = f.find(".floor_poster").text(); return flposter!=poster ; }; filter_floor(is_to_filter, "只看楼主"); }); $('body').on('click', '#min_word_num',function(){ var min = $("#min_word_num_input").val(); var is_to_filter = function(f){ var c = f.find(".flcontent").attr("word_num"); return c