Photopea No Ads

Hide Photopea Ads

  1. // ==UserScript==
  2. // @name Photopea No Ads
  3. // @version 0.0.3
  4. // @description Hide Photopea Ads
  5. // @icon https://www.photopea.com/promo/thumb256.png
  6.  
  7. // @author ml98
  8. // @namespace http://tampermonkey.net/
  9. // @license MIT
  10.  
  11. // @match https://www.photopea.com/*
  12. // @grant unsafeWindow
  13. // @run-at document-idle
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. function resize() {
  20. const adWidth = document.querySelector('.app').offsetWidth -
  21. document.querySelector('.app > div').offsetWidth;
  22. Object.defineProperty(unsafeWindow, 'innerWidth', {
  23. get() {
  24. return parseInt(visualViewport.width) + adWidth;
  25. }
  26. });
  27. unsafeWindow.dispatchEvent(new Event('resize'));
  28. }
  29.  
  30. const observer = new MutationObserver((mutations) => {
  31. for (const mutation of mutations) {
  32. for(const node of mutation.addedNodes) {
  33. if(node.nodeType === 1 && node.matches('.app *')) {
  34. observer.disconnect();
  35. resize();
  36. return;
  37. }
  38. }
  39. }
  40. });
  41. observer.observe(document.body, {
  42. childList: true,
  43. subtree: true
  44. });
  45.  
  46. })();
  47.