Remove Popup Ads on mp4upload.com & aniwave.to

Remove all popup ads on both mp4upload.com and aniwave.to, including within media players

  1. // ==UserScript==
  2. // @name Remove Popup Ads on mp4upload.com & aniwave.to
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.4
  5. // @description Remove all popup ads on both mp4upload.com and aniwave.to, including within media players
  6. // @author Goku
  7. // @match https://www.mp4upload.com/*
  8. // @match https://aniwave.to/*
  9. // @grant GM_config
  10. // @grant GM_registerMenuCommand
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // ============================== CONFIG =================================
  17. var bDisplayMessageOnPopupBlocked = true;
  18. var bDisplayOpenPopupLink = true;
  19. var bDisplayWhiteListThisDomainLink = true;
  20. var LOG_ID = "ultimate_popup_blocker"; // HTML ID in the page
  21.  
  22. // Function to remove popup ads indefinitely
  23. function removePopupAds() {
  24. // Remove popups every second from the whole page
  25. setInterval(function() {
  26. removePopups(document.body);
  27. }, 1000); // Check every 1 second
  28.  
  29. // Remove popups every second from the player wrapper on aniwave.to
  30. if (window.location.hostname === "aniwave.to") {
  31. var playerWrapper = document.getElementById('player-wrapper');
  32. if (playerWrapper) {
  33. setInterval(function() {
  34. removePopups(playerWrapper);
  35. }, 1000); // Check every 1 second
  36. }
  37. }
  38. }
  39.  
  40. // Function to remove popups within a specific container
  41. function removePopups(container) {
  42. var popupAds = container.querySelectorAll('a[href^="http://"]');
  43. popupAds.forEach(function(popupAd) {
  44. popupAd.remove();
  45. });
  46. }
  47.  
  48. // Helper to create a button with inner text @text executing onclick @clickCallback
  49. var putButton = function (logDiv, text, clickCallback, inlineStyle) {
  50. var button = document.createElement("button");
  51. button.innerHTML = text;
  52. button.style.cssText = "text-decoration:none; color:black; cursor:pointer;\
  53. margin: 0 5px; font: 8pt microsoft sans serif; padding: 1px 3px;\
  54. background-color:rgb(212,208,200); border-width:2px; border-style:outset;\
  55. border-color:#eee #555 #555 #eee; color:black;" + inlineStyle;
  56. logDiv.appendChild(button);
  57. button.addEventListener("click", clickCallback);
  58. };
  59.  
  60. // Helper to create a button (child of @logDiv) which onclick whitelists @domain
  61. var putWhitelistButton = function (logDiv, domain) {
  62. putButton(logDiv, domain, function(){
  63. GM_setValue("whitelisted_" + domain, true);
  64. });
  65. };
  66.  
  67. // Helper to create a text node with @text and append to @logDiv
  68. var putText = function (logDiv, text) {
  69. var node = document.createTextNode(text);
  70. logDiv.appendChild(node);
  71. };
  72.  
  73. // Return logger div, or create it ad-hoc.
  74. var getLogDiv = function () {
  75. var logDiv = document.getElementById(LOG_ID);
  76. if(!logDiv){
  77. logDiv = document.createElement("div");
  78. logDiv.setAttribute("id", LOG_ID);
  79. logDiv.style.cssText="position:fixed; top:0; left:0; width:100%;\
  80. padding:5px 5px 5px 29px; font: 8pt microsoft sans serif;\
  81. background-color: linen; color:black; border:1px solid black;\
  82. ";
  83. document.body.appendChild(logDiv);
  84. }
  85. return logDiv;
  86. };
  87.  
  88. // Get array of domains for which it would make sense to whitelist them.
  89. var getDomainsArray = function(documentDomain){
  90. var d1 = documentDomain;
  91. var domainsArr = [];
  92. var lastDot1 = d1.lastIndexOf('.');
  93. if(lastDot1 != -1){
  94. var lastDot2 = d1.lastIndexOf('.', lastDot1-1);
  95. if(lastDot2 != -1 && lastDot2 != lastDot1) {
  96. var d2 = d1.substr(lastDot2 + 1);
  97. domainsArr.push(d2);
  98. var lastDot3 = d1.lastIndexOf('.', lastDot2-1);
  99. if(lastDot3 != -1 && lastDot3 != lastDot2) {
  100. var d3 = d1.substr(lastDot3 + 1);
  101. domainsArr.push(d3);
  102. }
  103. }
  104. }
  105. domainsArr.push(d1);
  106. return domainsArr;
  107. };
  108.  
  109. // Checks if domain we're currently browsing has been whitelisted by the user
  110. var isCurrentDomainWhiteListed = function() {
  111. var domains = getDomainsArray(document.domain);
  112. var whitelisted = domains.some(function(d){
  113. return GM_getValue("whitelisted_" + d);
  114. });
  115. return whitelisted;
  116. };
  117.  
  118. // FakeWindow to prevent popup focusing
  119. var FakeWindow = {
  120. blur: function() {return false;},
  121. focus: function() {return false;}
  122. };
  123.  
  124. // Store a reference to real "window.open" method
  125. var realWindowOpen = window.open;
  126.  
  127. // Override browser's "window.open" with our own implementation
  128. var fakeWindowOpen = function(url){
  129. if(!bDisplayMessageOnPopupBlocked){
  130. return FakeWindow;
  131. }
  132. var logDiv = getLogDiv();
  133. logMessage(logDiv, url);
  134. if(bDisplayOpenPopupLink){
  135. displayOpenPopupLink(logDiv, arguments);
  136. }
  137. if(bDisplayWhiteListThisDomainLink) {
  138. displayWhiteListThisDomainLink(logDiv);
  139. }
  140. displayCloseButton(logDiv);
  141. return FakeWindow;
  142. };
  143.  
  144. var logMessage = function (logDiv, url) {
  145. window.upb_counter = (window.upb_counter || 0);
  146. url = (url[0] == '/') ? document.domain + url : url;
  147. var msg = ["UPB has blocked <b>", ++window.upb_counter, "</b> popup windows, last: <u>", url, "</u>"].join("");
  148. logDiv.innerHTML = msg;
  149. console.log(msg);
  150. logDiv.style.display = "block";
  151. };
  152.  
  153. var displayOpenPopupLink = function (logDiv, realArguments){
  154. putButton (logDiv, "open the popup", function(){
  155. realWindowOpen.apply(null, realArguments);
  156. });
  157. };
  158.  
  159. var displayWhiteListThisDomainLink = function(logDiv) {
  160. var domainsArr = getDomainsArray(document.domain);
  161. putText(logDiv, ' whitelist the domain: ');
  162. putWhitelistButton(logDiv, domainsArr[0]);
  163. if(domainsArr[1]){
  164. putWhitelistButton(logDiv, domainsArr[1]);
  165. }
  166. if(domainsArr[2]){
  167. putWhitelistButton(logDiv, domainsArr[2]);
  168. }
  169. };
  170.  
  171. var displayCloseButton = function(logDiv) {
  172. putButton (logDiv, "x", function(){
  173. logDiv.style.display = 'none';
  174. }, 'background-color: #a00; color:white; margin:0 32px 0 0; float:right');
  175. };
  176.  
  177. // Activate popup blocker
  178. var activateBlocker = function() {
  179. window.open = fakeWindowOpen;
  180. };
  181.  
  182. // ============================ LET'S RUN IT ================================
  183.  
  184. // Function to remove popups from mp4upload.com and aniwave.to
  185. removePopupAds();
  186.  
  187. var disabled = isCurrentDomainWhiteListed();
  188. if(disabled){
  189. console.log('[UPB] Current domain was found on a white list. UPB disabled.');
  190. }else{
  191. activateBlocker();
  192. }
  193. })();