Twitch Confirm Message Send

Confirms Twitch Chat Messages

目前為 2018-10-20 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name          Twitch Confirm Message Send
// @namespace     http://userstyles.org
// @description   Confirms Twitch Chat Messages
// @author        636597
// @include       *://*.twitch.tv/*
// @run-at        document-start
// @version       0.1
// ==/UserScript==

var chat_box_send_button_query_selector = '[data-a-target="chat-send-button"]';
var chat_box_send_button_element = null;
var chat_box_element_query_selector = '[data-a-target="chat-input"]';
var chat_box_element = null;
var chat_box_observer = null;
var observerConfig = {
	attributes: true,
	childList: true,
	characterData: true
};

function loadObserver() {

	// chat_box_observer = new MutationObserver( function( mutations ) {
	// 	mutations.forEach(function( mutation , index ) {
	// 		if ( mutation.type === "childList" ) {
	// 			var addedNode = mutation.addedNodes[ 0 ];
	// 			if( addedNode ) {
	// 				console.log( addedNode );
	// 			}
	// 		}
	// 	});
	// });
	// chat_box_observer.observe( chat_box_element , observerConfig );

	chat_box_element.addEventListener( "keydown" , function( event ) {
		if ( event.key === "Enter" ) {
			if ( confirm( "Do you want to post message?" ) === true ) {
				console.log( "passing" );
			} else {
				event.stopImmediatePropagation();
				event.stopPropagation();
				event.preventDefault();
				return false;
			}
		}
	});
	chat_box_send_button_element.addEventListener( "click" , function( event ) {
		if ( confirm( "Do you want to post message?" ) === true ) {
			console.log( "passing" );
		} else {
			event.stopImmediatePropagation();
			event.stopPropagation();
			event.preventDefault();
			return false;
		}
	});
	console.log( "Twitch Message Confirm Loaded" );
}


(function() {
	var ready = setInterval(function(){
		var x1 = document.querySelectorAll( chat_box_element_query_selector );
		if ( x1 ) { if ( x1[ 0 ] ) {
			chat_box_element = x1[0];
			var x2 = document.querySelectorAll( chat_box_send_button_query_selector );
			if ( x2 ) { if ( x2[ 0 ] ) {
				chat_box_send_button_element = x2[ 0 ];
				clearInterval( ready );
				loadObserver();
			}}
		}}
	} , 2 );
	setTimeout( function() { clearInterval( ready ); } , 20000 );
})();