Advertisement
caasinehc

asdf

Nov 20th, 2021
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.43 KB | None | 0 0
  1. // ==UserScript==
  2. // @name caasinehc's Skribbl tool
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Useful tools for skribbl.io
  6. // @author Isaac Chen
  7. // @match https://skribbl.io/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. // Elems on the skribbl page
  13. let elems = {};
  14.  
  15. // Current wordlist
  16. let currentTemplate = "";
  17. let possibleWordList = [];
  18. let possibleWordListText = "";
  19.  
  20. // Set the color (red, white, green, black, blue, etc)
  21. var setColor = (function() {
  22. function getColorElem(row, column) {
  23. return document.querySelector(
  24. "#containerBoard "
  25. + "> div.containerToolbar "
  26. + "> div.containerColorbox "
  27. + "> div:nth-child(" + row + ") "
  28. + "> div:nth-child(" + column + ")"
  29. );
  30. }
  31. let colors = {
  32. "white": getColorElem(1, 1),
  33. "silver": getColorElem(1, 2),
  34. "red": getColorElem(1, 3),
  35. "orange": getColorElem(1, 4),
  36. "yellow": getColorElem(1, 5),
  37. "lime": getColorElem(1, 6),
  38. "sky": getColorElem(1, 7),
  39. "blue": getColorElem(1, 8),
  40. "purple": getColorElem(1, 9),
  41. "pink": getColorElem(1, 10),
  42. "tan": getColorElem(1, 11),
  43. "black": getColorElem(2, 1),
  44. "gray": getColorElem(2, 2),
  45. "maroon": getColorElem(2, 3),
  46. "scarlet": getColorElem(2, 4),
  47. "gold": getColorElem(2, 5),
  48. "green": getColorElem(2, 6),
  49. "teal": getColorElem(2, 7),
  50. "navy": getColorElem(2, 8),
  51. "plum": getColorElem(2, 9),
  52. "mauve": getColorElem(2, 10),
  53. "brown": getColorElem(2, 11)
  54. }
  55. return function(color) {
  56. colors[color].click();
  57. }
  58. })();
  59.  
  60. // Set the tool (pen, eraser, fill)
  61. var setTool = (function() {
  62. function getTool(n) {
  63. return document.querySelector(
  64. "#containerBoard "
  65. + "> div.containerToolbar "
  66. + "> div.containerTools "
  67. + "> div:nth-child(" + n + ")"
  68. );
  69. }
  70. let tools = {
  71. "pen": getTool(1),
  72. "eraser": getTool(2),
  73. "fill": getTool(3)
  74. }
  75. return function(tool) {
  76. tools[tool].click();
  77. }
  78. })();
  79.  
  80. // Set the pen size (1, 2, 3, 4)
  81. var setSize = (function() {
  82. function getSize(n) {
  83. return document.querySelector(
  84. "#containerBoard "
  85. + "> div.containerToolbar "
  86. + "> div.containerBrushSizes "
  87. + "> div:nth-child(" + n + ") "
  88. + "> div "
  89. + "> div"
  90. );
  91. }
  92. let sizes = {
  93. 1: getSize(1),
  94. 2: getSize(2),
  95. 3: getSize(3),
  96. 4: getSize(4)
  97. }
  98. return function(size) {
  99. sizes[size].click();
  100. }
  101. })();
  102.  
  103. // Clear the canvas
  104. var clearCanvas = (function() {
  105. let clearCanvasButton = document.querySelector("#buttonClearCanvas");
  106.  
  107. return function() {
  108. clearCanvasButton.click();
  109. }
  110. })();
  111.  
  112. // Votekick
  113. var voteKick = (function() {
  114. let voteKickButton = document.querySelector("#votekickCurrentplayer");
  115.  
  116. return function() {
  117. voteKickButton.click();
  118. }
  119. })();
  120.  
  121. // Thumbs up or down
  122. var rate = (function() {
  123. let ratings = {
  124. "good": document.querySelector("#rateDrawing > div:nth-child(1) > div"),
  125. "bad": document.querySelector("#rateDrawing > div:nth-child(2) > div")
  126. }
  127.  
  128. return function(rating) {
  129. ratings[rating].click();
  130. }
  131. })();
  132.  
  133. // Choose which word to draw
  134. var chooseWord = function(word) {
  135. document.querySelector(
  136. "#overlay "
  137. + "> div "
  138. + "> div.wordContainer "
  139. + "> div:nth-child(" + word + ")"
  140. ).click();
  141. };
  142.  
  143. function isDrawing() {
  144. return document.querySelector("#containerBoard > div.containerToolbar").style.display != "none";
  145. }
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157. // Color wheel
  158. (function() {
  159. let canvas = document.createElement("canvas");
  160. document.body.appendChild(canvas);
  161. canvas.width = window.innerWidth;
  162. canvas.height = window.innerHeight;
  163. canvas.style.position = "absolute";
  164. canvas.style.backgroundColor = "transparent";
  165. canvas.style.zIndex = 10;
  166. canvas.style.top = 0;
  167. canvas.style.left = 0;
  168. canvas.style.pointerEvents = "none";
  169.  
  170. let ctx = canvas.getContext("2d");
  171.  
  172. let colorTable = [0, 1, 12, 11, 21, 13, 10, 14, 2, 3, 15, 4, 5, 16, 18, 17, 7, 6, 19, 8, 20, 9];
  173. let colorCount = colorTable.length;
  174. let sliceAngle = 360 / colorCount;
  175. let width = canvas.width;
  176. let height = canvas.height;
  177.  
  178. let mousePos = {x: 0, y: 0};
  179. let palettePos = {x: 0, y: 0};
  180. let showPalette = false;
  181. let selectedColor = 0;
  182.  
  183. function colorDecoder(color) {
  184. return ["white", "gray", "silver", "gray", "red", "maroon", "orange", "scarlet", "yellow", "gold", "lime", "green", "sky", "teal", "blue", "navy", "purple", "eggplant", "pink", "mauve", "tan", "brown"][color];
  185. }
  186.  
  187. function renderPalette() {
  188. let selectedAngle = (450 - Math.atan2(palettePos.x - mousePos.x, palettePos.y - mousePos.y) * 180 / Math.PI) % 360;
  189. selectedColor = Math.floor(selectedAngle / sliceAngle);
  190.  
  191. ctx.clearRect(0, 0, width, height);
  192.  
  193. ctx.shadowBlur = 50;
  194. ctx.shadowColor = "black";
  195. ctx.beginPath();
  196. ctx.fillStyle = document.getElementsByClassName("colorItem")[colorTable[selectedColor]].style.backgroundColor;
  197. ctx.arc(mousePos.x, mousePos.y, 180, 0, Math.PI * 2);
  198. ctx.lineTo(mousePos.x, mousePos.y);
  199. ctx.closePath;
  200. ctx.fill();
  201. for(let i = 0; i < colorCount; i++) {
  202. ctx.shadowBlur = 5;
  203. ctx.shadowColor = "black";
  204. ctx.beginPath();
  205. ctx.moveTo(mousePos.x, mousePos.y);
  206. ctx.fillStyle = document.getElementsByClassName("colorItem")[colorTable[i]].style.backgroundColor;
  207. ctx.arc(mousePos.x, mousePos.y, 160, Math.PI / 180 * i * sliceAngle, Math.PI / 180 * i * sliceAngle + (Math.PI / 180 * sliceAngle));
  208. ctx.lineTo(mousePos.x, mousePos.y);
  209. ctx.closePath();
  210. ctx.fill();
  211. ctx.stroke();
  212. }
  213. ctx.shadowBlur = 40;
  214. ctx.shadowColor = "white";
  215. ctx.beginPath();
  216. ctx.moveTo(mousePos.x, mousePos.y);
  217. ctx.fillStyle = document.getElementsByClassName("colorItem")[colorTable[selectedColor]].style.backgroundColor; // might have to be wrapped in a try-catch?
  218. ctx.arc(mousePos.x, mousePos.y, 200, Math.PI / 180 * selectedColor * sliceAngle, Math.PI / 180 * selectedColor * sliceAngle + (Math.PI / 180 * sliceAngle));
  219. ctx.lineTo(mousePos.x, mousePos.y);
  220. ctx.closePath();
  221. ctx.fill();
  222. ctx.stroke();
  223. }
  224.  
  225. document.addEventListener("mousedown", function(e) {
  226. if(e.button == 2) {
  227. showPalette = true;
  228. canvas.width = window.innerWidth;
  229. width = canvas.width;
  230. canvas.height = window.innerHeight;
  231. height = canvas.height;
  232. renderPalette();
  233. }
  234. }, false);
  235.  
  236. document.addEventListener("mouseup", function(e) {
  237. if(showPalette) {
  238. showPalette = false;
  239. ctx.clearRect(0, 0, width, height);
  240. document.getElementsByClassName("colorItem")[colorTable[selectedColor]].click();
  241. }
  242. }, false);
  243.  
  244. document.addEventListener("mousemove", function(e) {
  245. let rect = e.target.getBoundingClientRect();
  246. if(!showPalette) {
  247. mousePos.x = e.pageX;
  248. mousePos.y = e.pageY;
  249. }
  250. else {
  251. palettePos.x = e.pageX;
  252. palettePos.y = e.pageY;
  253. renderPalette();
  254. }
  255. }, false)
  256.  
  257. document.addEventListener("contextmenu", function(e) {
  258. e.preventDefault();
  259. return false;
  260. }, false);
  261. })();
  262.  
  263. // All the wordList stuff
  264. (function() {
  265. let wordList = JSON.parse(localStorage.getItem("wordList") || "[]");
  266. let saveWords = true;
  267. let showWordListP = true;
  268.  
  269. // Turns a skribbl template into a regex
  270. function templateToRegex(template) {
  271. return new RegExp("^" + template.split("_").join("[A-Za-z]") + "$");
  272. }
  273.  
  274. // Save the wordlist to localStorage
  275. function saveWordList() {
  276. cleanWordList();
  277. localStorage.setItem("wordList", JSON.stringify(wordList));
  278. }
  279.  
  280. // Remove duplicate words (also sorts)
  281. function cleanWordList() {
  282. let words = {};
  283. let newWordList = wordList.filter(function(item) {
  284. return words.hasOwnProperty(item) ? false : (words[item] = true);
  285. });
  286. wordList = newWordList.sort();
  287. }
  288.  
  289. // Save the wordList on unload
  290. window.addEventListener("unload", saveWordList, false);
  291.  
  292. // When the word is revealed, save the word
  293. function theWordWasCallback() {
  294. let text = theWordWasTarget.innerText;
  295. if(saveWords && text.startsWith("The word was: ")) {
  296. wordList.push(text.replace("The word was: ", ""));
  297. cleanWordList();
  298. }
  299. }
  300. let theWordWasTarget = document.querySelector("#overlay > div > div.text");
  301. let theWordWasObserver = new MutationObserver(theWordWasCallback);
  302. theWordWasObserver.observe(theWordWasTarget, {attributes: true, childList: true, characterData: true, subtree: true});
  303.  
  304. // When choosing a word, save the three options
  305. function chooseAWordCallback() {
  306. if(saveWords) {
  307. wordList.push(chooseAWordTarget.children[0].innerText);
  308. wordList.push(chooseAWordTarget.children[1].innerText);
  309. wordList.push(chooseAWordTarget.children[2].innerText);
  310. cleanWordList();
  311. }
  312. }
  313. let chooseAWordTarget = document.querySelector("#overlay > div > div.wordContainer");
  314. let chooseAWordObserver = new MutationObserver(chooseAWordCallback);
  315. chooseAWordObserver.observe(chooseAWordTarget, {attributes: true, childList: true, characterData: true, subtree: true});
  316.  
  317. // Update the list of possible words from template
  318. function updatePossibleWords() {
  319. currentTemplate = templateToRegex(document.querySelector("#currentWord").innerText);
  320. possibleWordList = [];
  321. for(let word of wordList) {
  322. if(currentTemplate.test(word)) possibleWordList.push(word.toLowerCase());
  323. }
  324. // possibleWordList.sort(); // Shouldn't be necessary?
  325. possibleWordListText = possibleWordList.length > 0 ? "Possible words: \n" + possibleWordList.join(", ") : "No matches found in your database!";
  326. possibleWordsP.innerText = possibleWordListText;
  327. }
  328.  
  329. // The text display of possible words
  330. let possibleWordsP = document.createElement("P");
  331. possibleWordsP.appendChild(document.createTextNode(""));
  332. document.querySelector("#screenGame").appendChild(possibleWordsP);
  333. possibleWordsP.style.margin = "4px";
  334. possibleWordsP.style.background = "white";
  335.  
  336. // When the list of possible words changes, do stuff
  337. let observer = new MutationObserver(mutations => {
  338. updatePossibleWords();
  339.  
  340. // If guessing and showing box, show the box
  341. if(!isDrawing() && showWordListP) {
  342. possibleWordsP.style.display = "initial";
  343. }
  344. // If drawing or hiding box, hide the box
  345. else {
  346. possibleWordsP.style.display = "none";
  347. }
  348. });
  349. observer.observe(document.querySelector("#currentWord"), {attributes: true, childList: true, characterData: true, subtree: true});
  350.  
  351. // turn the chatbox green if the guess matches the hint
  352. (function() {
  353. function templateToRegex(template) {
  354. return new RegExp("^" + template.split("_").join("[A-Za-z]") + "$");
  355. }
  356.  
  357. let inputBox = document.querySelector("#inputChat");
  358. let hintDisplay = document.querySelector("#currentWord");
  359. setInterval(function() {
  360. let text = inputBox.value.toLowerCase();
  361. let regex = templateToRegex(hintDisplay.innerText);
  362. if(regex.test(text) && text.length) {
  363. if(possibleWordList.includes(text)) {
  364. inputBox.style.backgroundColor = "lime";
  365. }
  366. else inputBox.style.backgroundColor = "#80FF80";
  367. }
  368. else {
  369. inputBox.style.backgroundColor = "white";
  370. }
  371. }, 1000 / 60)
  372. })();
  373.  
  374. document.addEventListener("keydown", function(e) {
  375. if(e.altKey) {
  376. // Toggle word list box
  377. if(e.key == "l") {
  378. if(showWordListP) {
  379. showWordListP = false;
  380. possibleWordsP.style.display = "none";
  381. }
  382. else {
  383. showWordListP = true;
  384. possibleWordsP.style.display = "initial";
  385. }
  386. }
  387. // Toggle saving words
  388. else if(e.key == "s") {
  389. if(saveWords) {
  390. alert("Stopped saving words to database!");
  391. saveWords = false;
  392. }
  393. else {
  394. alert("Resumed saving words to database!");
  395. saveWords = true;
  396. }
  397. }
  398. // Clear canvas
  399. else if(e.key == "c") {
  400. clearCanvas();
  401. }
  402. // Rate good
  403. else if(e.key == "g") {
  404. rate("good");
  405. }
  406. // Rate bad
  407. else if(e.key == "b") {
  408. rate("bad");
  409. }
  410. // Vote kick
  411. else if(e.key == "v") {
  412. voteKick();
  413. }
  414. }
  415. }, false);
  416. })();
  417.  
  418. function wordScrape() {
  419. function startGame() {
  420. document.querySelector("#modalIdle > div > div > div.modal-header > button").click();
  421. if(document.querySelector("#screenLogin").style.display != "none") {
  422. document.querySelector("#modalKicked > div > div > div.modal-footer > button").click();
  423. document.querySelector("#modalDisconnect > div > div > div.modal-footer > button").click();
  424. document.querySelector("#inputName").value = "Word Scraper";
  425. document.querySelector("#formLogin > button").click();
  426. }
  427. }
  428. setInterval(startGame, 1000);
  429. }
  430.  
  431. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement