futaba quick post

shift+enterキーでレス送信

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name           futaba quick post
// @namespace      https://github.com/akoya-tomo
// @description    shift+enterキーでレス送信
// @author         akoya_tomo
// @include        http://*.2chan.net/*/res/*
// @include        https://*.2chan.net/*/res/*
// @require        http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js
// @version        1.0.3
// @grant          none
// @license        MIT
// @noframes
// ==/UserScript==
this.$ = this.jQuery = jQuery.noConflict(true);

(function ($) {
	/*
	 *	設定
	 */
	var enterKey = "13";		//Enterキーのキーコード
	var isWindowActive = true;	// タブのアクティブ状態
	var isFormFocus = false;	// フォームのフォーカス状態

	init();

	function init() {
		setWindowFocusEvent();
		setFormFocusEvent();
		setKeydownEvent();
	}

	// タブのアクティブ状態を取得
	function setWindowFocusEvent() {
		$(window).focus();
		$(window).bind("focus", function() {
			// タブアクティブ時
			isWindowActive = true;
		}).bind("blur", function() {
			// タブ非アクティブ時
			isWindowActive = false;
		});
	}

	// フォームのフォーカス状態を取得
	function setFormFocusEvent() {
		$("#ftbl").focusin(function() {
			// フォームフォーカス時
			isFormFocus = true;
		}).focusout(function() {
			// フォーム非フォーカス時
			isFormFocus = false;
		});
	}

	//フォーム返信ショートカットキー
	function setKeydownEvent() {
		window.addEventListener("keydown",function(e) {
			if (e.shiftKey && e.keyCode == enterKey && isWindowActive && isFormFocus) {
				e.preventDefault();
				clickSubmitButton();
			}
		}, false);
	}

	/*
	 * フォームの[返信する]ボタンをクリック
	 */
	function clickSubmitButton() {
		var submitButton = $("#ftbl input[value='返信する'][type='submit']");	//フォームの[返信する]ボタン取得
		if (submitButton.length) {
			submitButton.trigger("click");
		}
	}

})(jQuery);