Advertisement
Guest User

loltactics

a guest
Oct 16th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. // ==UserScript==
  2. // @name ChangeDrawColorAndOtherThings
  3. // @namespace xd
  4. // @version 1.0
  5. // @description Change draw color on gametactic.org
  6. // @author Renkee
  7. // @match https://en.wottactic.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. const drawAndLineEndKeys = [
  13. "1", // regular
  14. "2", // arrow
  15. "3" // T
  16. ];
  17. const toolChangeKeybinds = {
  18. "q": "draw_context",
  19. "w": "line_context",
  20. "e": "eraser_context",
  21. "r": "note_context"
  22. };
  23. const keyColorPairs = {
  24. "a": 0xff0000, // a -> red
  25. "s": 0x0000ff, // s -> blue
  26. "d": 0xffff00 // d -> yellow
  27. };
  28. function changeDrawLineEnds(key) {
  29. for(let i = 0;i<3;i++) {
  30. if (i == (key - 1)) {
  31. $("#draw_end_type").children()[i].classList.add("active");
  32. $("#line_end_type").children()[i].classList.add("active");
  33. } else {
  34. $("#draw_end_type").children()[i].classList.remove("active");
  35. $("#line_end_type").children()[i].classList.remove("active");
  36. }
  37. }
  38. }
  39.  
  40. // Event handlers
  41. $(window).on('load', (e) => { changeDrawLineEnds(1); }); // Set default draw/line end to regular
  42. $(window).keypress((event) => {
  43. // if not in text field
  44. if (!$(event.target).is('input, textarea')) {
  45. const key = event.key;
  46. if (keyColorPairs.hasOwnProperty(key)) {
  47. window.draw_color = keyColorPairs[key];
  48. window.line_color = keyColorPairs[key];
  49. } else if (toolChangeKeybinds.hasOwnProperty(key)) {
  50. window.active_context = toolChangeKeybinds[key];
  51. window.active_menu = toolChangeKeybinds[key];
  52. if (toolChangeKeybinds[key] == "eraser_context" || toolChangeKeybinds[key] == "note_context") window.enable_dragging(); else window.disable_dragging();
  53. } else if (key == "c") {
  54. window.clear();
  55. } else if (drawAndLineEndKeys.includes(key)) {
  56. changeDrawLineEnds(key);
  57. }
  58. }
  59. });
  60. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement