Skribbl.io Helper

Learns the wordlist each round and outputs possible words in chat.

当前为 2019-02-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Skribbl.io Helper
  3. // @version 0.21
  4. // @description Learns the wordlist each round and outputs possible words in chat.
  5. // @author n0thing
  6. // @match https://skribbl.io/*
  7. // @grant none
  8. // @namespace https://greasyfork.org/users/90770
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. if (localStorage.getItem('wordlist') !== null) {
  15. window.alert('Hello from n0thing! I am the developer of Skribbl.io Helper, and I\'ve just updated the script from 0.12 to 0.20.\nThis new update allows for multi-language support, but your current WORDLIST will be affected!\nPlease transfer your current wordlist to wordlist[Lang] so Skribbl.io helper can use your current wordlist.\nSee this this forum (greasyfork.org/en/forum/discussion/48865/) for more information and how to transfer!\n\n This popup will stop appearing once the transfer is complete.');
  16. }
  17.  
  18. //create wordlist name, check if wordlist localstorage exists upon joining game
  19. var wordlist; //declare global scope wordlist var
  20. document.querySelector('#formLogin > button').onclick = function(){
  21. wordlist = 'wordlist' + document.querySelector('#loginLanguage').value;
  22. if (localStorage.getItem(wordlist) === null) {
  23. localStorage.setItem(wordlist,'""');
  24. }
  25. };
  26.  
  27. var wordhint;
  28. var wordRGX;
  29.  
  30. //create message element
  31. var messageelement = document.createElement('p');
  32. messageelement.setAttribute('style', 'display: none');
  33. messageelement.setAttribute('id','botChat');
  34. var c = document.createElement('span');
  35. c.setAttribute('id','hint');
  36. messageelement.appendChild(c);
  37. document.getElementById('containerSidebar').insertBefore(messageelement, document.getElementById('containerSidebar').childNodes[0]); //insert bot chat
  38.  
  39. document.getElementById('containerFreespace').setAttribute('style','display: none');
  40.  
  41. var css = document.createElement('style');
  42. 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);}';
  43. document.body.appendChild(css);
  44.  
  45. document.getElementById('inputChat').setAttribute('placeholder', 'Press ALT to open matching words'); // input wordhint into chat
  46.  
  47. document.getElementsByTagName("body")[0].onkeyup = function() {
  48. if (parseInt(event.keyCode) == 18 ){
  49. chatbot();
  50. }};
  51.  
  52. //mutationObserver > trigger wordCapture
  53. var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  54. var element = document.querySelector('#overlay > div > div.text');
  55. var observer = new MutationObserver(function(mutations) {
  56. mutations.forEach(function(mutation) {
  57. if (mutation.type == 'childList') {
  58. if (document.querySelector('#overlay > div > div.text').textContent.startsWith("Choose a word")){wordchoiceCapture();}; //trigger wordCatupre() when turn ends
  59. if (document.querySelector('#overlay > div > div.text').textContent.startsWith("The word was")){wordCapture();};
  60. }
  61. });
  62. });
  63. observer.observe(element, {
  64. childList: true
  65. });
  66.  
  67. //capture word from skribbl.io after round
  68. function wordCapture() {
  69. var word = document.querySelector('#overlay > div > div.text').textContent.slice(14);
  70. if (localStorage.getItem(wordlist).search(word) === -1){
  71. if (word.endsWith('word!') === false){
  72. localStorage.setItem(wordlist,localStorage.getItem(wordlist) + ',"' + word + '"'); //updates localstorage
  73. }
  74. }
  75. }
  76.  
  77. function wordchoiceCapture() {
  78. for (i = 0; i < document.getElementsByClassName("word").length; i++){
  79. var wordChoice = wordChoice + ',"' + document.getElementsByClassName("word")[i].textContent + '"'; //collects words from word options when it's the player's turn to draw.
  80. };
  81. localStorage.setItem(wordlist,localStorage.getItem(wordlist) + wordChoice); // add to wordlist
  82. }
  83.  
  84. function chatbot(){
  85. var wordRGX = document.getElementById('currentWord').textContent;
  86.  
  87. while (wordRGX.charAt(0) === '_' || wordRGX.charAt(wordRGX.length-1) === '_'){
  88. if (wordRGX.charAt(0) === '_'){
  89. wordRGX = wordRGX.replace('_','[^ ]');
  90. } else if(wordRGX.charAt(wordRGX.length-1) === '_'){
  91. wordRGX = wordRGX.replace(/_$/,'[^ ]');
  92. }
  93. }
  94. wordRGX = wordRGX.replace(/_/g,'[^ ]');
  95. wordRGX = '"'.concat(wordRGX,'"');
  96. wordRGX = new RegExp(wordRGX, 'g');
  97.  
  98. var wordhint = localStorage.getItem(wordlist).match(wordRGX).filter(function(f){return !f.includes(',');}).sort().toString().replace(/"/g,'').replace(/,/g,', '); // clean up result for bot chat
  99.  
  100. if (document.getElementById('botChat').attributes[0].value.search('display: none') != -1){//if hidden
  101. document.getElementById('hint').innerHTML = wordhint;
  102. document.getElementById('botChat').setAttribute('style','display:');
  103. } else {document.getElementById('botChat').setAttribute('style','display: none');}
  104.  
  105. document.getElementById('boxMessages').scrollTop = document.getElementById('boxMessages').scrollHeight; //scrollto bottom of chat
  106. }
  107. })();