Advertisement
Guest User

Untitled

a guest
May 22nd, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Photopea Resizer
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @include /https?:\/\/(www\.)?photopea\.com\/?($|\?|#).*/
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. let vColumn1Reset;
  12. let vColumn2Reset;
  13.  
  14. new MutationObserver((_, observer) => {
  15. const input = document.querySelector('input[type="file"]');
  16. if (input) {
  17. watchInput(input);
  18. observer.disconnect();
  19. }
  20. }).observe(document, {childList: true, subtree: true});
  21.  
  22. function resetColumns() {
  23. setTimeout(() => {
  24. const vColumn1 = document.querySelector('.rightbar > .vcolumn:first-child');
  25. const vColumn2 = document.querySelector('.rightbar > .vcolumn:nth-child(2)');
  26. if (vColumn1Reset === true) vColumn1.querySelector('.top').click();
  27. if (vColumn2Reset === true) vColumn2.querySelector('.top').click();
  28. vColumn1Reset = false;
  29. vColumn2Reset = false;
  30. }, 100);
  31. }
  32.  
  33. function watchInput(input) {
  34. input.oninput = () => {
  35. const vColumn1 = document.querySelector('.rightbar > .vcolumn[style]:first-child');
  36. const vColumn2 = document.querySelector('.rightbar > .vcolumn[style]:nth-child(2)');
  37. if (vColumn1) {
  38. vColumn1Reset = true;
  39. vColumn1.querySelector('.top').click();
  40. resetColumns();
  41. return;
  42. }
  43. if (vColumn2) {
  44. vColumn2Reset = true;
  45. vColumn2.querySelector('.top').click()
  46. }
  47. resetColumns();
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement