futaba_thread_highlighter

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

目前为 2015-05-18 提交的版本。查看 最新版本

// ==UserScript==
// @name        futaba_thread_highlighter
// @namespace   https://github.com/himuro-majika
// @description スレ本文を検索してカタログでスレッド監視しちゃう
// @include     http://*.2chan.net/*/futaba.php?mode=cat*
// @version     1.2
// @require     http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js
// @grant       GM_registerMenuCommand
// @grant       GM_getValue
// @grant       GM_setValue
// @grant       GM_addStyle
// ==/UserScript==

this.$ = this.jQuery = jQuery.noConflict(true);

(function ($) {
	var akahukuloadstat;
	
	init();
	
	function init(){
		console.log("futaba_thread_highlighter: " + GM_getValue("_futaba_thread_search_words"));
		GM_registerMenuCommand("スレッド検索ワード編集", editWords);
		setStyle();
		makecontainer();
		highlight();
		setInterval(check_akahuku_reload, "100");
	}
	
	/*
	 *検索文字列の設定
	 */
	function editWords(){
		var userinput;	//検索文字列入力値
		userinput = prompt("スレ本文に含まれる語句を入力してください。 | を挟むと複数指定できます。正規表現使用可。\n例 : img|dat村|mayちゃん|junくん|dec",
						   GM_getValue("_futaba_thread_search_words") )
		if ( userinput != null ){
			GM_setValue("_futaba_thread_search_words", userinput);
			highlight();
		}
		console.log("futaba_thread_highlighter: " + GM_getValue("_futaba_thread_search_words"));
	}
	
	/*
	 *スレピックアップ表示エリアの設定
	 */
	function makecontainer() {
		var $pickup_thread_container = $("<div>", {
			id: "futaba_thread_highlighter_highlighted_threads",
			css: {
				"overflow": "hidden"
			}
		});
		$("body > table[align]").before($pickup_thread_container);
		
		var $container_header = $("<div>", {
			id: "futaba_thread_highlighter_container_header",
			text: "スレッド検索該当スレッド",
			css: {
				backgroundColor: "#F0E0D6",
				fontWeight: "bolder"
			}
		});
		$pickup_thread_container.append($container_header);
		//設定ボタン
		var $button = $("<span>", {
			id: "futaba_thread_highlighter_searchword",
			text: "[設定]",
			css: {
				cursor: "pointer",
			},
			click: function() {
				editWords();
			}
		});
		$button.hover(function () {
			$(this).css({ backgroundColor:"#EEAA88" });
		}, function () {
			$(this).css({ backgroundColor:"#F0E0D6" });
		});
		$container_header.append($button);
	}
	
	/*
	 *赤福の動的リロードの状態を取得
	 */
	function check_akahuku_reload() {
		if ( get_akahuku_reloading_status() == 0 || get_akahuku_reloading_status() == 1 ) {
			akahukuloadstat = true;
		}
		else if ( get_akahuku_reloading_status() == 2 || get_akahuku_reloading_status() == 3 ) {
			if ( akahukuloadstat ) {
				highlight();
			}
			akahukuloadstat = false;
		}
		function get_akahuku_reloading_status() {
			var $acrs = $("#akahuku_catalog_reload_status");	//赤福
			var $fvw = $("#fvw_mes");							//ふたクロ
			var relstat;
			if ( $acrs.length ) {
				//赤福
				if ( $acrs.text().match(/ロード中/) ) {
					relstat = 0;
				}
				else if ( $acrs.text().match(/更新中/) ) {
					relstat = 1;
				}
				else if ( $acrs.text().match(/完了しました/) ) {
					relstat = 2;
				}
				else {
					relstat = 3;
				}
			}
			if ( $fvw.length ){
				//ふたクロ
				if ( $fvw.text().match(/Now Loading/) ) {
					relstat = 0;
				}
				else if ( $fvw.text().match(/更新しました/) ) {
					relstat = 2;
				}
				else {
					relstat = 3;
				}
			}
			return relstat;
		}
	}
	
	/*
	 *カタログを検索して強調表示
	 */
	function highlight() {
		var Start = new Date().getTime();//count parsing time
		var words = GM_getValue("_futaba_thread_search_words")
		var re = new RegExp(words, "i");
		if ( words != "" ) {
			$(".futaba_thread_highlighter_highlighted").removeClass("futaba_thread_highlighter_highlighted");
			$("body > table[align] td small").each(function(){
				if( $(this).text().match(re) ) {
					if ( !$(this).children(".futaba_thread_highlighter_matchedword").length ) {
						$(this).html($(this).html().replace(re, "<span class='futaba_thread_highlighter_matchedword'>" +
															$(this).text().match(re) + "</span>"));
					}
					if ( $(this).parent("a").length ) {		//文字スレ
						$(this).parent().parent("td").addClass("futaba_thread_highlighter_highlighted");
					} else {
						$(this).parent("td").addClass("futaba_thread_highlighter_highlighted");
					}
				}
			});
			pickup_highlighted();
		}
		console.log('Parsing: '+((new Date()).getTime()-Start) +'msec');//log parsing time
	}

	/*
	 *強調表示したスレを先頭にピックアップ
	 */
	function pickup_highlighted() {
		if ( $("#futaba_thread_highlighter_highlighted_threads .futaba_thread_highlighter_pickuped").length ) {
			$("#futaba_thread_highlighter_highlighted_threads .futaba_thread_highlighter_pickuped").remove();
		}
		var highlighted = $("body > table .futaba_thread_highlighter_highlighted").clone();
		$("#futaba_thread_highlighter_highlighted_threads").append(highlighted);
		//要素の中身を整形
		highlighted.each(function(){
			if ( !$(this).children("small").length ) {		//文字スレ
				//console.log($(this).children("a").html());
				//$(this).children("a").replaceWith("<div class='futaba_thread_highlighter_pickuped_caption'>" + $(this).html() + "</div>");
			} else {
				$(this).children("small").replaceWith("<div class='futaba_thread_highlighter_pickuped_caption'>" +
													  $(this).children("small").html() + "</div>");
				$(this).children("br").replaceWith();
			}
			$(this).replaceWith("<div class='futaba_thread_highlighter_pickuped'>" + $(this).html() + "</div>");
		});
		set_img_height_width();
		/*
		 *ピックアップしたスレ画像の高さと幅に合わせる
		 */
		function set_img_height_width(){
			var $pickuped = $(".futaba_thread_highlighter_pickuped");
			var img_height_ary = new Array;
			$pickuped.each(function(){
				var height = $(this).find("img").attr("height");
				if (height) {
					img_height_ary.push(parseInt(height));
				}
				var width = $(this).find("img").attr("width");
				$(this).css({
					//スレ画の幅に合わせる
					width: width,
				});
				$(this).children("div").css({
					width: width,
				});
			});
			//画像の高さの最大値を取得
			var max_height_num = Math.max.apply(null, img_height_ary);
			$pickuped.css({
				height: (max_height_num + 110) + "px",
			});
		}
	}
	
	/*
	 *スタイル設定
	 */
	function setStyle() {
		var css =
			//マッチ文字列の背景色
			".futaba_thread_highlighter_matchedword {" +
			"  background-color: #ff0;" +
			"}" +
			//セルの背景色
			".futaba_thread_highlighter_highlighted {" +
			"  background-color: #FFDFE9;" +
			"}" +
			//ピックアップスレ
			".futaba_thread_highlighter_pickuped {" +
			"  min-width: 70px;" +
			"  margin: 1px;" +
			"  background-color: #FFDFE9;" +
			"  border-radius: 5px;" +
			"  float: left;" +
			"  word-wrap: break-word;" +
			"}" +
			//ピックアップスレ本文
			".futaba_thread_highlighter_pickuped_caption {" +
			"  min-width: 70px;" +
			"  font-size: 12px;" +
			"  background-color: #ffdfe9;" +
			"  height: 80px;" +
			"  overflow: hidden;" +
			"}" +
			".futaba_thread_highlighter_pickuped_caption:hover {" +
			"  position: absolute;" +
			"  height: auto;" +
			"  z-index: 100;" +
			"}";
		GM_addStyle(css);
	}
})(jQuery);

QingJ © 2025

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