hjj_tidy

红晋江( http://bbs.jjwxc.net ) 贴子整理,去广告,加跳转,只看楼主,最少字数等等

  1. // --------------------------------------------------------------------
  2. //
  3. // ==UserScript==
  4. // @name hjj_tidy
  5. // @namespace http://abbypan.github.io/
  6. // @version 0.2
  7. // @license MIT
  8. // @author Abby Pan (abbypan@gmail.com)
  9. // @description 红晋江( http://bbs.jjwxc.net ) 贴子整理,去广告,加跳转,只看楼主,最少字数等等
  10. // @copyright 2014, Abby Pan (http://abbypan.github.io/)
  11. // @include *://bbs.jjwxc.net/showmsg.php?board=*&id=*
  12. // @include *://bbs.jjwxc.com/showmsg.php?board=*&id=*
  13. // @grant none
  14. // ==/UserScript==
  15. //
  16. // --------------------------------------------------------------------
  17.  
  18.  
  19. function extract_floor_info(info) {
  20. var c = info.html()
  21. .replace(/^\s*<font color='gray' size='-1'>[^<]+<\/font><br>/,'')
  22. ;
  23. var w = info.text().length;
  24. var meta = info.parents("tr:eq(1)").next().text();
  25.  
  26. var m = meta.match(/№(\d+).+?☆☆☆(.*?)于([\d\s:-]+)留言☆☆☆/);
  27. return {
  28. content: c,
  29. word_num: w,
  30. id: parseInt(m[1]),
  31. poster: m[2] || ' ',
  32. time: m[3]
  33. };
  34. }
  35.  
  36. function format_floor_content(f) {
  37. var html = '<div class="floor" id="floor' + f.id + '" fid="'+ f.id +'">' +
  38. '<div class="flcontent" word_num="' + f.word_num + '">' + f.content + '</div>' +
  39. '<span class="chapter">№' + f.id + '<span class="star">☆☆☆</span><span class="floor_poster">' + f.poster + '</span><span class="star">于</span>' + f.time + '留言<span class="star">☆☆☆</span></span>' +
  40. '&nbsp;&nbsp;&nbsp;' +
  41. '<a class="reply_thread_floor" reply_type="cite" href="#">&raquo;</a>' +
  42. '&nbsp;&nbsp;&nbsp;' +
  43. '<a class="reply_thread_floor" reply_type="default" href="#">&rsaquo;</a>' +
  44. '&nbsp;&nbsp;&nbsp;' +
  45. '<a class="jump_to_top" href="#">&uArr;</a>' +
  46. '&nbsp;&nbsp;&nbsp;' +
  47. '<a class="jump_to_bottom" href="#">&dArr;</a>' +
  48. '&nbsp;&nbsp;&nbsp;' +
  49. '<a class="jump_to_prev" href="#">&uarr;</a>' +
  50. '&nbsp;&nbsp;&nbsp;' +
  51. '<a class="jump_to_next" href="#">&darr;</a>' +
  52. '&nbsp;&nbsp;&nbsp;' +
  53. '<span class="temp_floor"></span>' +
  54. '</div>';
  55. //'<a href="#jump_floor" data-rel="popup" data-position-to="window" data-transition="pop">&#9735;</a>' +
  56. //'&nbsp;&nbsp;&nbsp;' +
  57. //'<a class="mark_floor" href="#">&#9875;</a>' +
  58. //'&nbsp;&nbsp;&nbsp;' +
  59. return html;
  60. }
  61.  
  62. function extract_showmsg_content(d){
  63. var res = {};
  64. var tm = $('title').text();
  65. res["title"] = tm.replace(/―― 晋江文学城网友交流区/,'').replace(/^\s+/,'').replace(/\s+$/, '');
  66.  
  67.  
  68. var pm = d.match(/\>(共\d+页:.+?)<\/div>/);
  69. res["pager"] = pm ? pm[1].replace(/<\/a>/g, '</a>&nbsp;') : '';
  70.  
  71. var h = $.parseHTML(d);
  72.  
  73. res["banner"] = $(h).find('a').eq(0).parent().html();
  74. res["banner_reverse"] = res["banner"].replace(/^(.*?)(→.*?→)(.*)/, "$3$2$1");
  75. res["reply_form"] = $(h).find('input[name="last_floor"]').parent().prop('outerHTML');
  76.  
  77. var poster = '';
  78.  
  79. var floors_info = new Array();
  80. $(h).find('td[class="read"]').each(function() {
  81. var bot = $(this);
  82. var f_i = extract_floor_info(bot);
  83. if(!poster) poster = f_i.poster;
  84.  
  85. var html = format_floor_content(f_i);
  86. floors_info.push(html);
  87. }).promise().done(function(){
  88. var all_floor = floors_info.join("\n");
  89. res["floor_list"] = all_floor;
  90. res["poster"] = poster;
  91. });
  92.  
  93. return res;
  94. }
  95.  
  96. function get_css(){
  97. return '<style> \
  98. body { font-size: 150%; line-height: 150%; margin-left : 10%; margin-right: 10% } \
  99. #banner_bottom { text-align: right; } \
  100. .pager,#thread_action { border: 0.1em solid rgb(153, 204, 0); } \
  101. .flcontent { padding-bottom : 0.5em; } \
  102. .floor,.onethread { \
  103. border-bottom: 0.1em solid rgb(153, 204, 0); \
  104. margin: 0.8em 0.2em 1.2em; \
  105. text-indent: 0em; \
  106. padding-bottom: 0.25em; \
  107. } \
  108. #thread_title { font-weight: bold;backgound-color:#E8F3FF; } \
  109. .star { color: #d4db8e; font-weight: bold; } \
  110. </style> \
  111. ';
  112. }
  113.  
  114. function div_thread_action(){
  115. return '<div id="thread_action"> \
  116. <input size="10" type="text" name="word_num" value=50 id="min_word_num_input" > \
  117. <a href="#" id="min_word_num">字数</a> \
  118. &nbsp; <input size="10" type="text" name="floor_keyword" id="floor_keyword_input" placeholder="关键字"> \
  119. <a href="#" id="floor_keyword">抽取</a> \
  120. &nbsp; <a href="#" id="floor_filter">过滤</a> \
  121. &nbsp; &nbsp; &nbsp; \
  122. <a href="#" id="only_poster">楼主</a> \
  123. &nbsp; <a href="#" id="view_img">看图</a> \
  124. &nbsp; <a href="#" id="reverse_floor">倒序</a> \
  125. &nbsp; <a id="view_all_floor" href="#">全部</a> \
  126. <span id="thread_action_temp"></span> \
  127. </div>';
  128. }
  129.  
  130.  
  131. (function(){
  132. $ = unsafeWindow.jQuery;
  133. var d = $('body').html();
  134. var res = extract_showmsg_content(d);
  135. var reply_thread_floor = function (){
  136. $("#reply").find("textarea").val("");
  137. var reply_type = $(this).attr("reply_type");
  138. var c = $(this).parent().children(".chapter").text().replace(/\\n/g, " ");
  139. if(reply_type=="cite")
  140. c = "" +
  141. $(this).parent().children(".flcontent").text().replace(/(\\s*\\n)+/g, "\n").trim().substr(0, 300) +
  142. "......\n\n" + c ;
  143. $("#reply").find("textarea").val(c.trim()+"\n");
  144.  
  145. var pos = $("#reply").offset().top;
  146. $("html,body").animate({ scrollTop : pos },500);
  147. };
  148.  
  149. var filter_floor = function(is_to_filter,msg) {
  150. var i = 0;
  151. $(".floor").each(function() {
  152. if(i>0 && is_to_filter($(this))) $(this).hide();
  153. i=1;
  154. });
  155. if(msg) $("#thread_action_temp").html(msg);
  156. } ;
  157. $('head').html(
  158. '<title>' + res["title"] + '</title>' +
  159. get_css()
  160. );
  161. $('body').html(
  162. '<div id="thread_info">' + res["banner"] + '<br><br>' +
  163. '<div id="thread_title">' + res["title"] + "</div><br>" +
  164. div_thread_action() +
  165. '</div><br>' +
  166. '<div id="pager_top" class="pager">' + res["pager"] + '</div>' +
  167. '<div id="thread_floor_list">' + res["floor_list"] + '</div>' +
  168. '<div id="pager_bottom" class="pager">' + res["pager"] + '</div>' +
  169. '<div id="banner_bottom">' + res["banner_reverse"] + '</div>' +
  170. '<div id="reply">' + res["reply_form"] + '</div>'
  171. );
  172.  
  173. $('body').on('click', '.jump_to_top', function(){
  174. $('html,body').animate({ 'scrollTop': 0 }, 500);
  175. });
  176.  
  177. $('body').on('click', '.jump_to_bottom', function(){
  178. var f = $('#pager_bottom').offset();
  179. $("html,body").animate({ scrollTop : f.top },500);
  180. });
  181.  
  182. $('body').on('click','.jump_to_next', function(){
  183. var x = $(this).parent().nextAll();
  184. var i = 50-1;
  185. if(x[i]) {
  186. var pos = $(x[i]).offset().top;
  187. $("html,body").animate({ scrollTop : pos },500);
  188. }
  189. });
  190.  
  191. $('body').on('click','.jump_to_prev', function(){
  192. var x = $(this).parent().prevAll();
  193. var i = 50-1;
  194. if(x[i]) {
  195. var pos = $(x[i]).offset().top;
  196. $("html,body").animate({ scrollTop : pos },500);
  197. }
  198. });
  199.  
  200.  
  201. $('body').on('click', '.reply_thread_floor',function(){
  202. $('#reply').find('textarea').val('');
  203. var reply_type = $(this).attr("reply_type");
  204. var c = $(this).parent().children('.chapter').text().replace(/\n/g, ' ');
  205. if(reply_type=="cite")
  206. c = "" +
  207. $(this).parent().children('.flcontent').text().replace(/(\s*\n)+/g, "\n").trim().substr(0, 300) +
  208. "......\n\n" + c ;
  209. $('#reply').find('textarea').val(c.trim()+"\n");
  210.  
  211. var pos = $('#reply').offset().top;
  212. $("html,body").animate({ scrollTop : pos },500);
  213. });
  214. $('body').on('click', '#view_all_floor', function(){
  215. $(".floor").each(function() {
  216. $(this).show();
  217. });
  218. $("#thread_action_temp").html("全部");
  219. });
  220.  
  221. $('body').on('click', '#view_img', function(){
  222. var is_to_filter = function(f){
  223. var c = f.find(".flcontent").eq(0).html();
  224. return c.match(/\<img /i) ? 0 : 1;
  225. };
  226.  
  227. filter_floor(is_to_filter, "只看图");
  228. });
  229.  
  230.  
  231. var get_showmsg_poster = function(){
  232. if($(".floor").eq(0).find(".floor_poster").length>0){
  233. return $(".floor").eq(0).find(".floor_poster").text();
  234. }
  235. return;
  236. };
  237.  
  238. $('body').on('click', '#only_poster', function(){
  239.  
  240. var poster = get_showmsg_poster();
  241. var is_to_filter = function(f){
  242. var flposter = f.find(".floor_poster").text();
  243. return flposter!=poster ;
  244. };
  245. filter_floor(is_to_filter, "只看楼主");
  246. });
  247. $('body').on('click', '#min_word_num',function(){
  248. var min = $("#min_word_num_input").val();
  249. var is_to_filter = function(f){
  250. var c = f.find(".flcontent").attr("word_num");
  251. return c<min;
  252. };
  253. filter_floor(is_to_filter, "最少" + min + "字");
  254. });
  255. $('body').on('click', '#floor_keyword',function(){
  256. var k = $("#floor_keyword_input").val();
  257. var is_to_filter = function(f){
  258. var c = f.find(".flcontent").text().match(k);
  259. var p = f.find(".floor_poster").text().match(k);
  260. return (c || p) ? false : true;
  261. };
  262. filter_floor(is_to_filter, "抽取" + k);
  263. });
  264. $('body').on('click', '#floor_filter',function(){
  265. var k = $("#floor_keyword_input").val();
  266. var is_to_filter = function(f){
  267. var c = f.find(".flcontent").text().match(k);
  268. var p = f.find(".floor_poster").text().match(k);
  269. return (c || p) ? true : false;
  270. };
  271. filter_floor(is_to_filter, "过滤" + k);
  272. });
  273. $('body').on('click', '#reverse_floor', function(){
  274. var s = [];
  275. $(".floor").each(function(){
  276. s.push($(this).prop("outerHTML"));
  277. });
  278. var c = s.reverse().join("\n");
  279. $("#thread_floor_list").html(c);
  280. $("#thread_action_temp").html("倒序");
  281. });
  282. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址