futaba_thread_highlighter

スレ本文を検索してカタログでスレッド監視しちゃう

当前为 2015-03-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name futaba_thread_highlighter
  3. // @namespace https://github.com/himuro-majika
  4. // @description スレ本文を検索してカタログでスレッド監視しちゃう
  5. // @include http://*.2chan.net/b/futaba.php?mode=cat*
  6. // @version 1
  7. // @require http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js
  8. // @grant GM_registerMenuCommand
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // ==/UserScript==
  12.  
  13. this.$ = this.jQuery = jQuery.noConflict(true);
  14.  
  15. (function ($) {
  16. /*
  17. ***************************************************************************************
  18. * 以下jQuery使用可
  19. */
  20.  
  21. console.log(GM_getValue("_futaba_thread_search_words"));
  22. GM_registerMenuCommand("スレッド検索ワード編集", editWords);
  23. var userinput; //検索文字列入力値
  24. function editWords(){
  25. userinput = prompt("スレ本文に含まれる語句を入力してください。 | を挟むと複数指定できます。正規表現使用可。\n例 : img|dat村|mayちゃん|junくん|dec", GM_getValue("_futaba_thread_search_words") )
  26. if ( userinput != null ){
  27. GM_setValue("_futaba_thread_search_words", userinput);
  28. highlight();
  29. }
  30. console.log(GM_getValue("_futaba_thread_search_words"));
  31. }
  32. makecontainer();
  33. function makecontainer() {
  34. var $pickup_thread_container = $("<div>", {
  35. id: "futaba_thread_highlighter_highlighted_threads",
  36. css: {
  37. "overflow": "hidden"
  38. }
  39. });
  40. $("body > table[align]").before($pickup_thread_container);
  41. var $container_header = $("<div>", {
  42. id: "futaba_thread_highlighter_container_header",
  43. text: "スレッド検索該当スレッド",
  44. css: {
  45. backgroundColor: "#F0E0D6",
  46. fontWeight: "bolder"
  47. }
  48. });
  49. $pickup_thread_container.append($container_header);
  50. }
  51. makebutton();
  52. function makebutton(){
  53. var $button = $("<span>", {
  54. id: "futaba_thread_highlighter_searchword",
  55. text: "[設定]",
  56. css: {
  57. cursor: "pointer",
  58. },
  59. click: function() {
  60. editWords();
  61. }
  62. });
  63. $button.hover(function () {
  64. $(this).css({ backgroundColor:"#EEAA88" });
  65. }, function () {
  66. $(this).css({ backgroundColor:"#F0E0D6" });
  67. });
  68. $("#futaba_thread_highlighter_container_header").append($button);
  69. }
  70. highlight();
  71. var akahukuloadingflag = false; //赤福更新フラグ
  72. var akahukuloadstat;
  73. setInterval(check_akahuku_reloading, "100");
  74. function check_akahuku_reloading() {
  75. if ( get_akahuku_reloading_status() == 0 || get_akahuku_reloading_status() == 1 ) {
  76. akahukuloadstat = true;
  77. }
  78. else if ( get_akahuku_reloading_status() == 2 || get_akahuku_reloading_status() == 3 ) {
  79. if ( akahukuloadstat ) {
  80. highlight();
  81. }
  82. akahukuloadstat = false;
  83. }
  84. }
  85. function get_akahuku_reloading_status() {
  86. var $acrs = $("#akahuku_catalog_reload_status");
  87. var $fvw = $("#fvw_mes");
  88. var relstat;
  89. if ( $acrs.length ) {
  90. //akafuku;
  91. if ( $acrs.text().match(/ロード中/) ) {
  92. relstat = 0;
  93. }
  94. else if ( $acrs.text().match(/更新中/) ) {
  95. relstat = 1;
  96. }
  97. else if ( $acrs.text().match(/完了しました/) ) {
  98. relstat = 2;
  99. }
  100. else {
  101. relstat = 3;
  102. }
  103. }
  104. if ( $fvw.length ){
  105. //futakuro;
  106. if ( $fvw.text().match(/Now Loading/) ) {
  107. relstat = 0;
  108. }
  109. else if ( $fvw.text().match(/更新しました/) ) {
  110. relstat = 2;
  111. }
  112. else {
  113. relstat = 3;
  114. }
  115. }
  116. return relstat;
  117. }
  118. function highlight() {
  119. var Start = new Date().getTime();//count parsing time
  120. var words = GM_getValue("_futaba_thread_search_words")
  121. var re = new RegExp(words, "i");
  122. if ( words != "" ) {
  123. $("body > table[align] td small").each(function(){
  124. if( $(this).text().match(re) ) {
  125. if ( !$(this).children(".futaba_thread_highlighter_matchedword").length ) {
  126. $(this).html($(this).html().replace(re, "<span class='futaba_thread_highlighter_matchedword'>" + $(this).text().match(re) + "</span>"));
  127. }
  128. $(".futaba_thread_highlighter_matchedword").css("background-color", "#ff0"); //文字の背景色
  129. $(this).parent().css("background-color", "#FF5C03").addClass("futaba_thread_highlighter_highlighted"); //セルの背景色
  130. }
  131. });
  132. pickup_highlighted();
  133. }
  134. console.log('Parsing: '+((new Date()).getTime()-Start) +'msec');//log parsing time
  135. }
  136.  
  137. function pickup_highlighted() {
  138. if ( $("#futaba_thread_highlighter_highlighted_threads .pickuped").length ) {
  139. $("#futaba_thread_highlighter_highlighted_threads .pickuped").remove();
  140. }
  141. var highlighted = $("body > table .futaba_thread_highlighter_highlighted").clone();
  142. $("#futaba_thread_highlighter_highlighted_threads").append(highlighted);
  143. highlighted.each(function(){
  144. $(this).replaceWith("<div class='pickuped'>" + $(this).html() + "</div>");
  145. });
  146. var $pickuped = $(".pickuped");
  147. $pickuped.css({
  148. width: "5em",
  149. //height: "6em",
  150. margin: "1px",
  151. overflow: "hidden",
  152. backgroundColor: "#FF5C03",
  153. float: "left",
  154. });
  155.  
  156. }
  157.  
  158. /*
  159. ***************************************************************************************
  160. */
  161. })(jQuery);
  162.