Created
November 1, 2022 16:09
-
-
Save Fishezzz/346f4288c2162c611c81972167b81a96 to your computer and use it in GitHub Desktop.
Tampermonkey user script to select "view less" for all ad topics in the ads settings on Facebook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Advert topics | |
// @author Fishezzz | |
// @version 0.0.2 | |
// @description Download Facebook & Instagram Album by One Click. | |
// @namespace https://gist.github.com/Fishezzz | |
// @match https://www.facebook.com/adpreferences/ad_topics?run=1 | |
// @icon https://static.xx.fbcdn.net/rsrc.php/yD/r/d4ZIVX-5C-b.ico | |
// @grant none | |
// @run-at document-idle | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
async function main() { | |
await sleep(5000); | |
// Expand categories | |
let show_more = document.getElementsByClassName("x1i10hfl x1qjc9v5 xjbqb8w xjqpnuy xa49m3k xqeqjp1 x2hbi6w x13fuv20 xu3j5b3 x1q0q8m5 x26u7qi x972fbf xcfux6l x1qhh985 xm0m39n x9f619 x1ypdohk xdl72j9 x2lah0s xe8uvvx xdj266r x11i5rnm xat24cr x1mh8g0r xeuugli xexx8yu x4uap5 x18d9i69 xkhd6sd x1n2onr6 x16tdsg8 x1hl2dhg xggy1nq x1ja2u2z x1t137rt x87ps6o x1lku1pv x1a2a7pz x168nmei x13lgxp2 x5pf9jr xo71vjh x78zum5 xdt5ytf x1mq37bv")[3]; | |
show_more.click(); | |
await sleep(500); | |
// Get list with category elements | |
let categories = document.getElementsByClassName("x1i10hfl x1qjc9v5 xjbqb8w xjqpnuy xa49m3k xqeqjp1 x2hbi6w x13fuv20 xu3j5b3 x1q0q8m5 x26u7qi x972fbf xcfux6l x1qhh985 xm0m39n x9f619 x1ypdohk xdl72j9 x2lah0s xe8uvvx xdj266r x11i5rnm xat24cr x1mh8g0r xeuugli xexx8yu x4uap5 x18d9i69 xkhd6sd x1n2onr6 x16tdsg8 x1hl2dhg xggy1nq x1ja2u2z x1t137rt x87ps6o x1lku1pv x1a2a7pz x168nmei x13lgxp2 x5pf9jr xo71vjh x78zum5 xdt5ytf x1mq37bv"); | |
let categories_len = categories.length - 5; | |
console.log('Updating '+categories_len+' categories'); | |
alert('Updating '+categories_len+' categories'); | |
// Iterate categories | |
for (var i = 0; i < categories_len - 1; i++) { | |
console.log('Updating catetgory:', categories[i].children[0].children[0].children[1].children[0].children[0].children[0].textContent); | |
// Open category | |
categories[i].click(); | |
await sleep(300); | |
// Update preference | |
var choices = document.getElementsByClassName("x1qjc9v5 xc1cqh8 xkmajd7 x8g6ph x1azt60i x9f619 x1jfb8zj xdt5ytf xc8icb0 x1nhvcw1 x6ikm8r x10wlt62 x1n2onr6")[2]; | |
await sleep(200); | |
choices.children[1].click(); | |
await sleep(1000); | |
// Close pop-up | |
var close = document.getElementsByClassName("x1i10hfl x1qjc9v5 xjbqb8w xjqpnuy xa49m3k xqeqjp1 x2hbi6w x13fuv20 xu3j5b3 x1q0q8m5 x26u7qi x972fbf xcfux6l x1qhh985 xm0m39n x9f619 x1ypdohk xdl72j9 x2lah0s xe8uvvx xdj266r x11i5rnm xat24cr x1mh8g0r x2lwn1j xeuugli x1n2onr6 x16tdsg8 x1hl2dhg xggy1nq x1ja2u2z x1t137rt x1q0g3np x87ps6o x1lku1pv x1a2a7pz x14yjl9h xudhj91 x18nykt9 xww2gxu x3nfvp2 x1y1aw1k x1sxyh0 xwib8y2 xurb0ha")[0]; | |
close.click(); | |
await sleep(200); | |
} | |
alert('Finished'); | |
} | |
// Execute | |
main(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment