Instantly share code, notes, and snippets.
Last active
May 10, 2021 00:55
-
Star
(1)
1
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save sbolel/7bd93e69c4ced85d0642f105b2cce43e to your computer and use it in GitHub Desktop.
Microsoft Edge: cookies settings - bulk add/remove blocked domains
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
/** | |
* Usage: | |
* - navigate to "edge://settings/content/cookies" and open devtools | |
* - add/remove tlds to `tlds` array below | |
* - copy and paste script into dev console | |
* - finally, call either `addAll()` or `removeAll() | |
* | |
* @example add domains | |
* addAll() | |
* | |
* @example remove domains | |
* removeAll() | |
*/ | |
const tlds = ['aaa.pro', 'ac', 'aca.pro', 'academy', 'acct.pro', 'aero', 'africa', 'ag', 'agency', 'ai', 'am', 'app', 'army', 'asia', 'at', 'audio', 'avocat.pro', 'band', 'bar', 'bar.pro', 'be', 'beer', 'berlin', 'bike', 'bio', 'biz', 'black', 'blog', 'blue', 'br.com', 'build', 'builders', 'business', 'buzz', 'bz', 'ca', 'cafe', 'camera', 'camp', 'capital', 'cards', 'care', 'careers', 'cash', 'cc', 'center', 'ceo', 'ch', 'church', 'city', 'claims', 'click', 'clinic', 'clothing', 'cloud', 'club', 'cm', 'cn.com', 'co', 'co.cm', 'co.in', 'co.ms', 'co.nz', 'co.uk', 'coach', 'codes', 'coffee', 'com', 'com.au', 'com.cm', 'com.co', 'com.de', 'com.es', 'com.ms', 'com.mx', 'com.pe', 'com.sg', 'com.tw', 'community', 'company', 'computer', 'varruction', 'consulting', 'cool', 'cpa.pro', 'credit', 'cz', 'dance', 'date', 'de', 'de.com', 'deals', 'design', 'dev', 'digital', 'direct', 'directory', 'dog', 'domains', 'earth', 'education', 'email', 'energy', 'eng.pro', 'engineer', 'engineering', 'enterprises', 'equipment', 'es', 'eu', 'eu.com', 'events', 'exchange', 'expert', 'fail', 'family', 'fans', 'farm', 'firm.in', 'fish', 'fishing', 'fit', 'fitness', 'fm', 'foundation', 'fr', 'fund', 'fyi', 'gallery', 'games', 'garden', 'gay', 'gen.in', 'gen.nz', 'gives', 'glass', 'global', 'gr.com', 'graphics', 'gripe', 'gs', 'guide', 'guru', 'haus', 'health', 'help', 'horse', 'host', 'hosting', 'house', 'how', 'hu.com', 'idv.tw', 'immo', 'in', 'ind.in', 'industries', 'info', 'ink', 'institute', 'investments', 'io', 'ist', 'it', 'jp', 'jur.pro', 'kitchen', 'kiwi', 'la', 'land', 'law', 'law.pro', 'lawyer', 'legal', 'li', 'life', 'limited', 'link', 'live', 'lol', 'london', 'love', 'ltd', 'ltd.uk', 'market', 'marketing', 'me', 'me.uk', 'med.pro', 'media', 'melbourne', 'menu', 'mobi', 'moe', 'ms', 'mx', 'name', 'net', 'net.au', 'net.cm', 'net.co', 'net.in', 'net.nz', 'net.pe', 'network', 'news', 'ninja', 'nl', 'no.com', 'nom.co', 'nom.es', 'nom.pe', 'nu', 'nyc', 'nz', 'one', 'online', 'org', 'org.au', 'org.es', 'org.in', 'org.ms', 'org.nz', 'org.pe', 'org.tw', 'org.uk', 'page', 'paris', 'parts', 'party', 'pe', 'photo', 'photography', 'photos', 'pics', 'pictures', 'pink', 'pizza', 'pl', 'place', 'plus', 'press', 'pro', 'pub', 'pw', 'qc.com', 'recht.pro', 'red', 'report', 'rest', 'review', 'reviews', 'rocks', 'ru.com', 'run', 'sa.com', 'school', 'science', 'scot', 'se', 'se.com', 'se.net', 'services', 'sexy', 'sg', 'sh', 'shop', 'show', 'site', 'ski', 'social', 'software', 'solutions', 'space', 'store', 'studio', 'study', 'support', 'sydney', 'systems', 'tc', 'team', 'tech', 'technology', 'tel', 'tips', 'tm', 'today', 'tools', 'top', 'tours', 'town', 'trade', 'training', 'travel', 'tv', 'tw', 'uk', 'uk.com', 'uk.net', 'university', 'uno', 'us', 'us.com', 'us.org', 'uy.com', 'ventures', 'vg', 'video', 'vip', 'vision', 'vote', 'watch', 'website', 'wedding', 'wiki', 'win', 'work', 'works', 'world', 'ws', 'wtf', 'xxx', 'xyz', 'za.com', 'zone', ] | |
const timeout = 100 | |
const head = document.head.innerHTML | |
const main = document.querySelector(`[role="main"]`) | |
const addBlockButton = main.querySelector('#CookiesAddblock') | |
const disabledClassIndex = head.indexOf('cursor: not-allowed !important;') | |
const disabledClassSelector = head.slice(disabledClassIndex - 11, disabledClassIndex - 5) | |
const getDialog = () => document.querySelector('[role="dialog"]') | |
const getDomainInput = () => getDialog().querySelector('input#sitePermissionUrl') | |
const getSubmitButton = () => getDialog().querySelector(`[type="submit"]`) | |
const getReactHandlers = (el) => Object.entries(el).find(i => i[0].indexOf('__reactEventHandlers') > -1) | |
function addAll() { | |
const addDomains = async (list) => { | |
if (list.length === 0) { | |
return true | |
} | |
addBlockButton.click() | |
const addFn = async () => { | |
const input = getDomainInput() | |
const url = list.shift() | |
input.value = `[*.]${url}` | |
const [, handlers] = getReactHandlers(input) | |
handlers.onChange({ | |
target: { | |
value: input.value | |
} | |
}) | |
getSubmitButton().click() | |
return new Promise((resolve, reject) => { | |
setTimeout(() => resolve(), timeout) | |
}) | |
} | |
await addFn() | |
return addDomains(list) | |
} | |
addDomains([...tlds]) | |
} | |
function removeAll(list) { | |
const removeDomains = async (list) => { | |
if (list.length === 0) { | |
return true | |
} | |
const moreOptionsButton = list.shift() | |
const removeFn = async () => { | |
moreOptionsButton.click() | |
const container = [ | |
...document.querySelectorAll('[id*="overflow-menu"]') | |
].find(i => i.style.left !== '0px') | |
const remove = container.firstChild.firstChild.firstChild.lastChild | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
remove.click() | |
resolve() | |
}, timeout) | |
}) | |
} | |
await removeFn() | |
return removeAll(list) | |
} | |
const container = main.querySelector('[aria-labelledby="CookiesBlockListActionRow"]') | |
const moreActionsButtons = [...container.querySelectorAll('button[title="More actions"]')] | |
return removeDomains(moreActionsButtons) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment