Skip to content

Instantly share code, notes, and snippets.

@ackerleytng
Last active November 29, 2020 18:42
Show Gist options
  • Save ackerleytng/ee3fcf2d62f8a3b7c8eee7548a874786 to your computer and use it in GitHub Desktop.
Save ackerleytng/ee3fcf2d62f8a3b7c8eee7548a874786 to your computer and use it in GitHub Desktop.
UserScript that allows you to toggle ads on OfferUp
// ==UserScript==
// @name OfferUp Toggle Ads
// @namespace https://offerup.com/
// @version 0.1
// @description Allows you to toggle ads on OfferUp
// @author ackerleytng
// @match https://offerup.com/search/*
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
var shouldShowAds = false;
const toggleAdState = function() {
shouldShowAds = !shouldShowAds;
}
const applyAdState = function () {
for (const e of document.querySelectorAll('a[data-impression-feedback-url]')) {
if (shouldShowAds) {
e.style.display = 'block';
} else {
e.style.display = 'none';
}
}
}
const toggleAndApply = function () {
toggleAdState();
applyAdState();
}
const addButton = function() {
const d = document.createElement('div');
d.innerHTML = '<button id="myButton" type="button">Toggle Ads</button>';
d.setAttribute ('id', 'myContainer');
document.body.appendChild(d);
document.getElementById("myButton").addEventListener("click", toggleAndApply, false);
GM_addStyle ( `
#myContainer {
position: fixed;
top: 0;
left: 0;
font-size: 20px;
background: orange;
border: 3px solid black;
margin: 5px;
opacity: 0.9;
z-index: 1100;
padding: 5px;
}
#myButton {
margin: 0;
padding: 5px;
}
` );
}
addButton();
applyAdState();
// So that on scrolling, new ads will either be shown or hidden
window.addEventListener('load', applyAdState, false);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment