Confirms Twitch Chat Messages
当前为
// ==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 );
})();