// ==UserScript== // @name Skribbl.io Helper // @version 0.12 // @description Learns the wordlist each round and outputs possible words in chat. // @author n0thing // @match https://skribbl.io/* // @grant none // @namespace https://greasyfork.org/users/90770 // @downloadURL none // ==/UserScript== (function() { 'use strict'; //check if wordlist localstorage exists if (localStorage.getItem('wordlist') === null) { localStorage.setItem('wordlist','""'); } var wordhint; var wordRGX; //create message element var messageelement = document.createElement('p'); messageelement.setAttribute('style', 'display: none'); messageelement.setAttribute('id','botChat'); var c = document.createElement('span'); c.setAttribute('id','hint'); messageelement.appendChild(c); document.getElementById('containerSidebar').insertBefore(messageelement, document.getElementById('containerSidebar').childNodes[0]); //insert bot chat document.getElementById('containerFreespace').setAttribute('style','display: none'); var css = document.createElement('style'); css.innerHTML = '#botChat{ border-radius: 2px; background: rgb(238, 238, 238); width:inherit-5px; overflow-wrap: break-word; position:absolute;right:0;top:3px;left:3px; color: rgb(206, 79, 10);}'; document.body.appendChild(css); document.getElementById('inputChat').setAttribute('placeholder', 'Press ALT to open matching words'); // input wordhint into chat document.getElementsByTagName("body")[0].onkeyup = function() { if (parseInt(event.keyCode) == 18 ){ chatbot(); }}; //mutationObserver > trigger wordCapture var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; var element = document.querySelector('.revealReason'); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.type == 'attributes') { wordCapture(); } }); }); observer.observe(element, { attributes: true }); //capture word from skribbl.io after round function wordCapture() { var word = document.querySelector('#overlay > div > div.text').textContent.slice(14); if (localStorage.wordlist.search(word) === -1){ if (word.endsWith('word!') === false){ localStorage.setItem('wordlist',localStorage.wordlist + ',"' + word + '"'); //updates localstorage } } } function chatbot(){ var wordRGX = document.getElementById('currentWord').textContent; while (wordRGX.charAt(0) === '_' || wordRGX.charAt(wordRGX.length-1) === '_'){ if (wordRGX.charAt(0) === '_'){ wordRGX = wordRGX.replace('_','\\w'); } else if(wordRGX.charAt(wordRGX.length-1) === '_'){ wordRGX = wordRGX.replace(/_$/,'\\w'); } } wordRGX = wordRGX.replace(/_/g,'\\w'); wordRGX = '"'.concat(wordRGX,'"'); wordRGX = new RegExp(wordRGX, 'g'); var wordhint = localStorage.wordlist.match(wordRGX).filter(function(f){return !f.includes(',');}).sort().toString().replace(/"/g,'').replace(/,/g,', '); // clean up result for bot chat if (document.getElementById('botChat').attributes[0].value.search('display: none') != -1){//if hidden document.getElementById('hint').innerHTML = wordhint; document.getElementById('botChat').setAttribute('style','display:'); } else {document.getElementById('botChat').setAttribute('style','display: none');} document.getElementById('boxMessages').scrollTop = document.getElementById('boxMessages').scrollHeight; //scrollto bottom of chat } })();