futaba auto reloader

赤福Firefox版の"リロードの代わりに続きを読む"を有効にして自動更新(実況モードもあるよ!)

当前为 2015-02-22 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name           futaba auto reloader
// @namespace   https://github.com/himuro-majika
// @description    赤福Firefox版の"リロードの代わりに続きを読む"を有効にして自動更新(実況モードもあるよ!)
// @include     http://*.2chan.net/*/res/*
// @include     http://board.futakuro.com/*/res/*
// @require     http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js
// @version     1
// @grant       none
// ==/UserScript==
this.$ = this.jQuery = jQuery.noConflict(true);

(function ($) {

	soudane();
	
	//通常時60秒おきにリロード
	setInterval(rel, 60000);
	var s = true;	//実況モード有効フラグ
	var res = 0;	//新着レス数

	var reloadButton = document.createElement("a");
	reloadButton.id = "relButton";
	reloadButton.style.cursor = 'pointer';
	reloadButton.innerHTML = "実況モード";
	var input, submit;
	input = document.evaluate(
		"//input[@value='返信する' or @value='送信する']",
		document,
		null,
		XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
		null);
	for (var i = 0; i < input.snapshotLength; i++) {
		submit = input.snapshotItem(i);

		var tr = submit.parentNode;
		tr.appendChild(reloadButton);
		reloadButton.addEventListener("click",function autoReload() {
			if (s) {
				//実況モード時5秒おきにリロード
				timerID1 = setInterval(rel_scroll, 5000);
				//timerID1 = setInterval(rel, 7000);
				//自動スクロール15px0.25秒ごと
				timerID2 = setInterval("window.scrollBy(0,2)", 12);
				reloadButton.style.backgroundColor = '#ffa5f0';
				s = false;
			} else {
				clearInterval(timerID1);
				clearInterval(timerID2);
				reloadButton.style.background = 'none';
				s = true;
			}

		},true);
	}
	
	//新着スクロール
	function rel_scroll(){
		$('html, body').animate(
			{scrollTop:window.scrollMaxY},"fast"
		);
		location.reload();
	}

	/*
	 * ページ末尾でスクロールして新着レスをリセット
	 */
	window.addEventListener("DOMMouseScroll",function scroll(event) {
		var window_y = window.scrollY;
		var window_ymax = window.scrollMaxY;
		if (event.detail > 0 && window_y >= window_ymax) {
			res = 0;
			var title_char = title_name();
//			console.log("title_char:" + title_char);
			document.title = title_char;
		}
		return;
	} ,false);

	
	function rel()
	{
		soudane();
		setTimeout(changetitle, 1000);
		location.reload();
	}

	function soudane()
	{
		$("td > .sod").each(function(){
			var sodnum = $(this).text().match(/\d+/);
			if (sodnum){
				var col = "rgb(180, 240," + (Math.round(10 * sodnum + 180)) + ")";
				$(this).parent().css("background-color", col);
			}
		});
	}

	/*
	 * タブタイトルに新着レス数を表示
	 */
	function changetitle() {
		var title_char = title_name();
//		console.log("title_char:" + title_char);
		var newres = $("#akahuku_new_reply_header_number").text();
		var reloadstatus = $("#akahuku_reload_status").text();
//		console.log(reloadstatus);
		if (reloadstatus.match(/スレッドが消えたようです。/)) {
			document.title = "#" + title_char;
		} else {
			if(newres) {
				res += parseInt(newres);
			}
			if ( res != 0) {
				document.title = "(" + res + ")" + title_char;
			}
		}
	}
	
	function title_name(){
		var title = document.title;
		var title_num = title.match(/^(#|\(\d+\))/);
		var title_num_length;
		if(!title_num){
			title_num_length = 0;
		}
		else {
			title_num_length = title_num[0].length;
		}
		var title_name = title.substr(title_num_length);
		return title_name;
	}

})(jQuery);