futaba_thread_highlighter

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

当前为 2015-05-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name futaba_thread_highlighter
  3. // @namespace https://github.com/himuro-majika
  4. // @description スレ本文を検索してカタログでスレッド監視しちゃう
  5. // @include http://*.2chan.net/*/futaba.php?mode=cat*
  6. // @version 1.2
  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. // @grant GM_addStyle
  12. // ==/UserScript==
  13.  
  14. this.$ = this.jQuery = jQuery.noConflict(true);
  15.  
  16. (function ($) {
  17. var akahukuloadstat;
  18. init();
  19. function init(){
  20. console.log("futaba_thread_highlighter: " + GM_getValue("_futaba_thread_search_words"));
  21. GM_registerMenuCommand("スレッド検索ワード編集", editWords);
  22. setStyle();
  23. makecontainer();
  24. highlight();
  25. setInterval(check_akahuku_reload, "100");
  26. }
  27. /*
  28. *検索文字列の設定
  29. */
  30. function editWords(){
  31. var userinput; //検索文字列入力値
  32. userinput = prompt("スレ本文に含まれる語句を入力してください。 | を挟むと複数指定できます。正規表現使用可。\n例 : img|dat村|mayちゃん|junくん|dec",
  33. GM_getValue("_futaba_thread_search_words") )
  34. if ( userinput != null ){
  35. GM_setValue("_futaba_thread_search_words", userinput);
  36. highlight();
  37. }
  38. console.log("futaba_thread_highlighter: " + GM_getValue("_futaba_thread_search_words"));
  39. }
  40. /*
  41. *スレピックアップ表示エリアの設定
  42. */
  43. function makecontainer() {
  44. var $pickup_thread_container = $("<div>", {
  45. id: "futaba_thread_highlighter_highlighted_threads",
  46. css: {
  47. "overflow": "hidden"
  48. }
  49. });
  50. $("body > table[align]").before($pickup_thread_container);
  51. var $container_header = $("<div>", {
  52. id: "futaba_thread_highlighter_container_header",
  53. text: "スレッド検索該当スレッド",
  54. css: {
  55. backgroundColor: "#F0E0D6",
  56. fontWeight: "bolder"
  57. }
  58. });
  59. $pickup_thread_container.append($container_header);
  60. //設定ボタン
  61. var $button = $("<span>", {
  62. id: "futaba_thread_highlighter_searchword",
  63. text: "[設定]",
  64. css: {
  65. cursor: "pointer",
  66. },
  67. click: function() {
  68. editWords();
  69. }
  70. });
  71. $button.hover(function () {
  72. $(this).css({ backgroundColor:"#EEAA88" });
  73. }, function () {
  74. $(this).css({ backgroundColor:"#F0E0D6" });
  75. });
  76. $container_header.append($button);
  77. }
  78. /*
  79. *赤福の動的リロードの状態を取得
  80. */
  81. function check_akahuku_reload() {
  82. if ( get_akahuku_reloading_status() == 0 || get_akahuku_reloading_status() == 1 ) {
  83. akahukuloadstat = true;
  84. }
  85. else if ( get_akahuku_reloading_status() == 2 || get_akahuku_reloading_status() == 3 ) {
  86. if ( akahukuloadstat ) {
  87. highlight();
  88. }
  89. akahukuloadstat = false;
  90. }
  91. function get_akahuku_reloading_status() {
  92. var $acrs = $("#akahuku_catalog_reload_status"); //赤福
  93. var $fvw = $("#fvw_mes"); //ふたクロ
  94. var relstat;
  95. if ( $acrs.length ) {
  96. //赤福
  97. if ( $acrs.text().match(/ロード中/) ) {
  98. relstat = 0;
  99. }
  100. else if ( $acrs.text().match(/更新中/) ) {
  101. relstat = 1;
  102. }
  103. else if ( $acrs.text().match(/完了しました/) ) {
  104. relstat = 2;
  105. }
  106. else {
  107. relstat = 3;
  108. }
  109. }
  110. if ( $fvw.length ){
  111. //ふたクロ
  112. if ( $fvw.text().match(/Now Loading/) ) {
  113. relstat = 0;
  114. }
  115. else if ( $fvw.text().match(/更新しました/) ) {
  116. relstat = 2;
  117. }
  118. else {
  119. relstat = 3;
  120. }
  121. }
  122. return relstat;
  123. }
  124. }
  125. /*
  126. *カタログを検索して強調表示
  127. */
  128. function highlight() {
  129. var Start = new Date().getTime();//count parsing time
  130. var words = GM_getValue("_futaba_thread_search_words")
  131. var re = new RegExp(words, "i");
  132. if ( words != "" ) {
  133. $(".futaba_thread_highlighter_highlighted").removeClass("futaba_thread_highlighter_highlighted");
  134. $("body > table[align] td small").each(function(){
  135. if( $(this).text().match(re) ) {
  136. if ( !$(this).children(".futaba_thread_highlighter_matchedword").length ) {
  137. $(this).html($(this).html().replace(re, "<span class='futaba_thread_highlighter_matchedword'>" +
  138. $(this).text().match(re) + "</span>"));
  139. }
  140. if ( $(this).parent("a").length ) { //文字スレ
  141. $(this).parent().parent("td").addClass("futaba_thread_highlighter_highlighted");
  142. } else {
  143. $(this).parent("td").addClass("futaba_thread_highlighter_highlighted");
  144. }
  145. }
  146. });
  147. pickup_highlighted();
  148. }
  149. console.log('Parsing: '+((new Date()).getTime()-Start) +'msec');//log parsing time
  150. }
  151.  
  152. /*
  153. *強調表示したスレを先頭にピックアップ
  154. */
  155. function pickup_highlighted() {
  156. if ( $("#futaba_thread_highlighter_highlighted_threads .futaba_thread_highlighter_pickuped").length ) {
  157. $("#futaba_thread_highlighter_highlighted_threads .futaba_thread_highlighter_pickuped").remove();
  158. }
  159. var highlighted = $("body > table .futaba_thread_highlighter_highlighted").clone();
  160. $("#futaba_thread_highlighter_highlighted_threads").append(highlighted);
  161. //要素の中身を整形
  162. highlighted.each(function(){
  163. if ( !$(this).children("small").length ) { //文字スレ
  164. //console.log($(this).children("a").html());
  165. //$(this).children("a").replaceWith("<div class='futaba_thread_highlighter_pickuped_caption'>" + $(this).html() + "</div>");
  166. } else {
  167. $(this).children("small").replaceWith("<div class='futaba_thread_highlighter_pickuped_caption'>" +
  168. $(this).children("small").html() + "</div>");
  169. $(this).children("br").replaceWith();
  170. }
  171. $(this).replaceWith("<div class='futaba_thread_highlighter_pickuped'>" + $(this).html() + "</div>");
  172. });
  173. set_img_height_width();
  174. /*
  175. *ピックアップしたスレ画像の高さと幅に合わせる
  176. */
  177. function set_img_height_width(){
  178. var $pickuped = $(".futaba_thread_highlighter_pickuped");
  179. var img_height_ary = new Array;
  180. $pickuped.each(function(){
  181. var height = $(this).find("img").attr("height");
  182. if (height) {
  183. img_height_ary.push(parseInt(height));
  184. }
  185. var width = $(this).find("img").attr("width");
  186. $(this).css({
  187. //スレ画の幅に合わせる
  188. width: width,
  189. });
  190. $(this).children("div").css({
  191. width: width,
  192. });
  193. });
  194. //画像の高さの最大値を取得
  195. var max_height_num = Math.max.apply(null, img_height_ary);
  196. $pickuped.css({
  197. height: (max_height_num + 110) + "px",
  198. });
  199. }
  200. }
  201. /*
  202. *スタイル設定
  203. */
  204. function setStyle() {
  205. var css =
  206. //マッチ文字列の背景色
  207. ".futaba_thread_highlighter_matchedword {" +
  208. " background-color: #ff0;" +
  209. "}" +
  210. //セルの背景色
  211. ".futaba_thread_highlighter_highlighted {" +
  212. " background-color: #FFDFE9;" +
  213. "}" +
  214. //ピックアップスレ
  215. ".futaba_thread_highlighter_pickuped {" +
  216. " min-width: 70px;" +
  217. " margin: 1px;" +
  218. " background-color: #FFDFE9;" +
  219. " border-radius: 5px;" +
  220. " float: left;" +
  221. " word-wrap: break-word;" +
  222. "}" +
  223. //ピックアップスレ本文
  224. ".futaba_thread_highlighter_pickuped_caption {" +
  225. " min-width: 70px;" +
  226. " font-size: 12px;" +
  227. " background-color: #ffdfe9;" +
  228. " height: 80px;" +
  229. " overflow: hidden;" +
  230. "}" +
  231. ".futaba_thread_highlighter_pickuped_caption:hover {" +
  232. " position: absolute;" +
  233. " height: auto;" +
  234. " z-index: 100;" +
  235. "}";
  236. GM_addStyle(css);
  237. }
  238. })(jQuery);
  239.