Skip to content

Instantly share code, notes, and snippets.

@aaronfc
Created January 7, 2017 18:08
Show Gist options
  • Save aaronfc/fcc1ee1315692b004b91305da48a5b2a to your computer and use it in GitHub Desktop.
Save aaronfc/fcc1ee1315692b004b91305da48a5b2a to your computer and use it in GitHub Desktop.
Remove suspicious click events to avoid first click ads.
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://mail.google.com/mail/u/0/#inbox
// @grant none
// ==/UserScript==
function removeSuspiciousClickEvents(target) {
const events = getEventListeners(target);
if (events.click) {
events.click.forEach(function (e) {
target.removeEventListener("click", e.listener, false);
});
}
if (events.mousedown) {
events.mousedown.forEach(function (e) {
target.removeEventListener("mousedown", e.listener, false);
});
}
if (events.mouseup) {
events.mouseup.forEach(function (e) {
target.removeEventListener("mouseup", e.listener, false);
});
}
}
(function() {
'use strict';
window.addEventListener('load', function() {
removeSuspiciousClickEvents(document);
removeSuspiciousClickEvents(document.body);
removeSuspiciousClickEvents(window);
}, false);
})();
@harryhare
Copy link

getEventListeners(target) give me an error "ReferenceError: getEventListeners is not defined"

@bre7
Copy link

bre7 commented Mar 13, 2020

Because getEventListeners is only available when using DevTools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment