Skribbl.io Helper

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

当前为 2018-11-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Skribbl.io Helper
  3. // @version 0.1
  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. //check if wordlist localstorage exists
  15. if (localStorage.getItem('wordlist') === null) {
  16. localStorage.setItem('wordlist','"eye"');
  17. }
  18.  
  19. var wordhint;
  20. var wordRGX;
  21.  
  22. document.getElementById('inputChat').setAttribute('placeholder', 'Press ALT to open matching words'); // input wordhint into chat
  23.  
  24. document.getElementsByTagName("body")[0].onkeyup = function() {
  25. if (parseInt(event.keyCode) == 18 ){
  26. chatbot();
  27. }};
  28.  
  29. //mutationObserver > trigger wordCapture
  30. var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  31. var element = document.querySelector('.revealReason');
  32. var observer = new MutationObserver(function(mutations) {
  33. mutations.forEach(function(mutation) {
  34. if (mutation.type == 'attributes') {
  35. wordCapture();
  36. }
  37. });
  38. });
  39. observer.observe(element, {
  40. attributes: true
  41. });
  42.  
  43. //capture word from skribbl.io after round
  44. function wordCapture() {
  45. var word = document.querySelector('#overlay > div > div.text').textContent.slice(14);
  46. if (localStorage.wordlist.search(word) === -1){
  47. if (word.endsWith('word!') === false){
  48. localStorage.setItem('wordlist',localStorage.wordlist + ',"' + word + '"'); //updates localstorage
  49. }
  50. }
  51. }
  52.  
  53. function chatbot(){
  54. var wordRGX = document.getElementById('currentWord').textContent;
  55.  
  56. while (wordRGX.charAt(0) === '_' || wordRGX.charAt(wordRGX.length-1) === '_'){
  57. if (wordRGX.charAt(0) === '_'){
  58. wordRGX = wordRGX.replace('_','\\w');
  59. } else if(wordRGX.charAt(wordRGX.length-1) === '_'){
  60. wordRGX = wordRGX.replace(/_$/,'\\w');
  61. }
  62. }
  63. wordRGX = wordRGX.replace(/_/g,'.');
  64. wordRGX = '"'.concat(wordRGX,'"');
  65. wordRGX = new RegExp(wordRGX, 'g');
  66.  
  67. var wordhint = localStorage.wordlist.match(wordRGX).filter(function(f){return !f.includes(',');}).toString().replace(/"/g,'').replace(/,/g,', '); // clean up result for bot chat
  68.  
  69. //create message element
  70. var a = document.createElement('p');
  71. a.setAttribute('style', 'color: rgb(206, 79, 10);');
  72. var b = document.createElement('b');
  73. a.appendChild(b);
  74. var c = document.createElement('span');
  75. c.setAttribute('id','hint');
  76. a.appendChild(c);
  77. var d = document.createTextNode('bot: ');
  78. b.appendChild(d);
  79. var e =document.createTextNode(wordhint);
  80. c.appendChild(e);
  81.  
  82. //insert bot chat
  83. document.getElementById('boxMessages').appendChild(a); //insert bot chat
  84. document.getElementById('boxMessages').scrollTop = document.getElementById('boxMessages').scrollHeight; //scrollto bottom of chat
  85.  
  86. }
  87. })();