futaba_thread_highlighter

カタログからスレ本文を検索してハイライト表示しちゃう

目前为 2015-03-15 提交的版本。查看 最新版本

// ==UserScript==
// @name        futaba_thread_highlighter
// @namespace   https://github.com/himuro-majika
// @description カタログからスレ本文を検索してハイライト表示しちゃう
// @include     http://*.2chan.net/b/futaba.php?mode=cat*
// @version     1
// @require     http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js
// @grant       GM_registerMenuCommand
// @grant       GM_getValue
// @grant       GM_setValue
// ==/UserScript==

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

(function ($) {
	/*
	 ***************************************************************************************
	 * 以下jQuery使用可
	 */
	

	console.log(GM_getValue("_futaba_thread_search_words"));
	GM_registerMenuCommand("スレッド検索ワード編集", editWords);
	
	makebutton();
	
	function makebutton(){
		var $button = $("<div>", {
			id: "futaba_thread_highlighter_searchword",
			text: "スレッドタイトル検索ワード編集",
			css: {
				//width: "11em",
				height: "1em",
				backgroundColor: "#F0E0D6",
				position: "absolute",
				top: "0",
				right: "0",
				cursor: "pointer",
				fontWeight: "bolder"
			},
			click: function() {
				editWords();
			}
		});
		$button.hover(function () {
			$(this).css({ backgroundColor:"#EEAA88" });
		}, function () {
			$(this).css({ backgroundColor:"#F0E0D6" });
		});
		$("body").append($button);
	}
	
	var userinput;	//検索文字列入力値
	function editWords(){
		userinput = prompt("スレッド検索文字列(|で複数指定)", GM_getValue("_futaba_thread_search_words") )
		if ( userinput != null ){
			GM_setValue("_futaba_thread_search_words", userinput);
		}
		console.log(GM_getValue("_futaba_thread_search_words"));
	}
	
	makecontainer();
	
	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);
	}
	
	highlight();
	var akahukuloadingflag = false; //赤福更新フラグ
	setInterval(check_akahuku_reloading, "100");
	
	function check_akahuku_reloading() {
		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 relstat;
		if ( $acrs.text().match(/ロード中/) ) {
			relstat = 0;
		}
		else if ( $acrs.text().match(/更新中/) ) {
			relstat = 1;
		}
		else if ( $acrs.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);

		$("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>"));
				}
				$(".futaba_thread_highlighter_matchedword").css("background-color", "#ff0");		//文字の背景色
				$(this).parent().css("background-color", "#FF5C03").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 .pickuped").length ) {
			$("#futaba_thread_highlighter_highlighted_threads .pickuped").remove();
		}
		var highlighted = $("body > table .futaba_thread_highlighter_highlighted").clone();
		$("#futaba_thread_highlighter_highlighted_threads").append(highlighted);
		highlighted.each(function(){
			$(this).replaceWith("<div class='pickuped'>" + $(this).html() + "</div>");
		});
		
		var $pickuped = $(".pickuped");
		$pickuped.css({
			width: "5em",
			//height: "6em",
			margin: "1px",
			overflow: "hidden",
			backgroundColor: "#FF5C03",
			float: "left",
		});

	}

	/*
	 ***************************************************************************************
	 */
})(jQuery);

QingJ © 2025

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