User:Хацунэ Мику/global.js

/*******************************/ importScriptPage('User:Monchoman45/ChatHacks.js', 'c'); /*******************************/ importScriptPage('w:c:dev:ChatOptions/code.js'); /*******************************/ function loadChatScripts { importArticles({   type: "script",    articles: [        "w:c:dev:ChatOptions/code.js",        "w:c:dev:ChatObject/code.js",        "MediaWiki:CustomChatTags.js",        "MediaWiki:SpamLimit.js",        "MediaWiki:Badwords.js",        "w:c:d97:MediaWiki:TitleNotifications.js"    ]    }); mainRoom.maxCharacterLimit = 3000; $("#join-alert").remove; chatIsLoaded = true; } var loadedTester = setInterval(function {  if(typeof mainRoom !== "undefined") {       importScriptPage("MediaWiki:JacobsLadderSuite.js","d97"); // import the API       setTimeout(function { loadChatScripts; },500);      clearInterval(loadedTester);       console.log("[CHAT.JS] Chat.js loading complete.");   } },100);

function appendTimestamps { if(cwmLoaded === true) { timer = new Date; hours = timer.getHours % 12; if (hours === 0) { hours = 12; } minutes = timer.getMinutes; seconds = timer.getSeconds; if($("#entry-"+JLAPI.mostRecentMessage.cid).hasClass('inline-alert')) { $("#entry-"+JLAPI.mostRecentMessage.cid).append(" "+hours+":"+padDigits(minutes,2)+":"+padDigits(seconds,2)+" "); } else { $("#entry-"+JLAPI.mostRecentMessage.cid+" > span.time").html(hours+":"+padDigits(minutes,2)+":"+padDigits(seconds,2)); }   } } function padDigits(number, digits) { return Array(Math.max(digits - String(number).length + 1, 0)).join(0) + number; } /*Этот скрипт делает то, что я не понимаю*/ (function {   var ChatHelper = function( settings ) {        this.chat = document.getElementsByClassName( 'WikiaPage' )[0];        this.mainChannel = this.chat.getElementsByClassName( 'Chat' )[0];        this.rail = document.getElementsByClassName( 'Rail' )[0];        this.textArea = document.getElementsByTagName( 'textarea' )[0];        this.pingPhrases;        this.sounds = {            main: new Audio( 'http://vignette3.wikia.nocookie.net/siegenax/images/d/de/Sounds-1054-suppressed.ogg/revision/latest?cb=20151214225959&path-prefix=ru' )        };        this.chatObserver = new MutationObserver( this.chatDOMChangesProcessing.bind( this ) );        if ( settings.fastNicknames ) {            this.chat.addEventListener('click', this.addNicknameOfMessage.bind( this ));            this.rail.addEventListener('click', this.addNicknameOfRail.bind( this ));        }        if ( settings.chatNotifications ) { this.pingPhrases = ( localStorage.chatHelper_pingPhrases ) ? JSON.parse( localStorage.chatHelper_pingPhrases ) : [ mw.config.get( 'wgUserName' ) ]; this.chatObserver.observe(this.chat, {                childList: true,                subtree: true            }); }   };    ChatHelper.prototype.addNicknameOfMessage = function( event ) { var target = event.target, message = target.closest( '.Chat li' ), nickname; if ( message && (target.closest( '.username' ) || target.classList.contains( 'avatar' )) ) { nickname = message.dataset.user; this.printNickname( nickname ); }   };    ChatHelper.prototype.addNicknameOfRail = function( event ) { var user = event.target.closest( 'li' ), nickname; if ( user && event.which === 2 ) { nickname = user.dataset.user; this.printNickname( nickname ); }   };    ChatHelper.prototype.printNickname = function( nickname ) { var carriagePosition = this.textArea.selectionStart, text = this.textArea.value, initialSubstring = text.slice( 0, carriagePosition ), finalSubstring = text.slice( carriagePosition ); carriagePosition = initialSubstring.length + nickname.length + 2; text = initialSubstring + nickname + ', ' + finalSubstring; this.textArea.value = text; this.textArea.focus; this.textArea.setSelectionRange( carriagePosition, carriagePosition ); };   ChatHelper.prototype.chatDOMChangesProcessing = function( mutationList ) { var i,           mainChannelSound; for ( i = 0; i < mutationList.length; i++ ) { if ( mutationList[i].target.parentElement && mutationList[i].target.parentElement === this.mainChannel ) { mainChannelSound = mainChannelSound || this.mainChannelMessagesProcessing( mutationList[i] ); }       }        if ( mainChannelSound ) this.sounds.main.play; };   ChatHelper.prototype.mainChannelMessagesProcessing = function( mutationRecord ) { var message, messageText, isSoundNotification, i, j;       for ( i = 0; i < mutationRecord.addedNodes.length; i++ ) { message = mutationRecord.addedNodes[i]; if ( message.dataset.user ) { messageText = message.lastElementChild.textContent; for ( j = 0; j < this.pingPhrases.length; j++ ) { if ( messageText.indexOf( this.pingPhrases[j] ) !== -1 ) { message.classList.add( 'chatHelper_pingMessage' ); isSoundNotification = true; }               }            }        }        if ( isSoundNotification ) return true; };   document.addEventListener('DOMContentLoaded', function {        var helper = new ChatHelper({ fastNicknames: true, chatNotifications: true });   }); }); document.addEventListener('DOMContentLoaded', function { var chat = document.getElementsByClassName( 'WikiaPage' )[0], rail = document.getElementsByClassName( 'Rail' )[0], textArea = document.getElementsByTagName( 'textarea' )[0]; //   var pmAddSound = new Audio( 'http://vignette1.wikia.nocookie.net/siegenax/images/0/02/Jingle-bells-sms.ogg/revision/latest?cb=20151209133611&path-prefix=ru' ), pmMessageSound = new Audio( 'http://vignette1.wikia.nocookie.net/siegenax/images/0/08/Sounds-937-job-done.ogg/revision/latest?cb=20151209142227&path-prefix=ru' ), observeNewPm = function( mutationList ) { var addedNodes, newChat, isSoundNotification, i,           j;            for ( i = 0; i < mutationList.length; i++ ) { addedNodes = mutationList[i].addedNodes; for ( j = 0; j < addedNodes.length; j++ ) { newChat = addedNodes[j]; if ( newChat.classList.contains( 'Chat' ) ) { pmObserver.observe(newChat.firstElementChild, {                           childList: true                        }); if ( newChat.style.display === 'none' ) { newChat.firstMute = true; isSoundNotification = true; }                   }                }            }            if ( isSoundNotification ) { pmAddSound.play; console.dir( mutationList ); }       },        pmTracking = function( mutationList ) { var pmChat, message, isSoundNotification, noMute, i,           j;            for ( i = 0; i < mutationList.length; i++ ) { pmChat = mutationList[i].target.parentElement; for ( j = 0; j < mutationList[i].addedNodes.length; j++ ) { message = mutationList[i].addedNodes[j]; if ( message.dataset.user ) { if ( !pmChat.firstMute && pmChat.style.display === 'none'                            || document.visibilityState === 'hidden') isSoundNotification = true; if ( pmChat.firstMute ) noMute = true; }               }            }            if ( isSoundNotification ) pmMessageSound.play; if ( noMute ) pmChat.firstMute = false; },       chatObserver = new MutationObserver( observeNewPm ), pmObserver = new MutationObserver( pmTracking ); chatObserver.observe(chat, {        childList: true    }); });