Skip to content

Instantly share code, notes, and snippets.

@StefanoChiodino
Last active August 10, 2020 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StefanoChiodino/b674fa3af99002cb12cc08a3e66fd12d to your computer and use it in GitHub Desktop.
Save StefanoChiodino/b674fa3af99002cb12cc08a3e66fd12d to your computer and use it in GitHub Desktop.
let get_sponsored_context = () => document.querySelector("div[aria-label=Sponsored]").parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.querySelector("div[aria-label='Actions for this post']");
let get_hide_this_ad = () => document.querySelector("[role=menuitem]");
let get_close_dialog = () => document.querySelector("div[role=dialog] [aria-label=Close]");
function click_close_dialog() {
let close_dialog = undefined;
try { close_dialog = get_close_dialog(); } catch{ }
if (close_dialog) {
console.log("Close dialog found.")
close_dialog.click();
// Start again.
setTimeout(() => { click_sponsored_context(); }, 100);
}
else
setTimeout(() => { click_close_dialog(); }, 100);
}
function click_hide_this_ad() {
let hide_this_ad = undefined;
try { hide_this_ad = get_hide_this_ad(); } catch{ }
if (hide_this_ad) {
console.log("Hide this ad found.")
hide_this_ad.click();
click_close_dialog();
}
setTimeout(() => { click_hide_this_ad(); }, 100);
}
function remove_ads() {
// Click on the context menu for sponsored post.
let context_of_sponsored = undefined;
try { context_of_sponsored = get_sponsored_context(); } catch{ }
if (context_of_sponsored) {
console.log("Context of sponsored post found.")
context_of_sponsored.click();
click_hide_this_ad();
}
else
setTimeout(() => { remove_ads(); }, 100);
}
remove_ads();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment