Last active
January 12, 2017 02:35
-
-
Save jamesmanning/df149235ba039bb1c03e0d37a95d588f to your computer and use it in GitHub Desktop.
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
// NOTE: Firefox doesn't add async/await support until version 52. Stable is version 50 currently as of this writing. | |
// step 1: open the BPM extension's 'options' page | |
// step 2: open chrome devtools console. On Windows and Linux: Ctrl + Shift + J. On Mac: Cmd + Option + J. | |
// step 3: copy-paste the below code. Make sure to hit enter after pasting so that it runs | |
// step 4: close and re-open the BPM options page, scroll down to the bottom to see the list of custom CSS subreddits to confirm it now includes the berrymotes ones | |
// NOTE: because of a message handler that runs inside BPM that's expecting this to run inside the context of a | |
// particular message, there will be an error shown in the console after this runs, but ***IT CAN BE SAFELY IGNORED***. | |
// It will look something like this: | |
// | |
// Error in event handler for (unknown): TypeError: Cannot read property 'method' of undefined | |
// at Object._message_handler (chrome-extension://bkkmhlceghomaajdimmejkhldnpleoea/options.js:137:27) | |
(async() => { | |
const response = await fetch('http://berrymotes.com/assets/berrymotes_json_data.json'); | |
const jsondata = await response.json(); | |
const subs = jsondata.map(entry => entry.sr); | |
const uniqueSubs = new Set(subs); | |
console.log(`discovered ${uniqueSubs.size} subreddits from ${jsondata.length} emotes`); | |
// remove any subs that are already present in the list | |
const subsToAdd = new Set(uniqueSubs); | |
for (const existingSub in bpm_prefs.prefs.customCSSSubreddits) { | |
subsToAdd.delete(existingSub); | |
} | |
if (subsToAdd.size == 0) { | |
console.log(`all ${uniqueSubs.size} subreddits are already present in custom css subreddit list`); | |
return; | |
} | |
console.log(`adding ${subsToAdd.size} subreddits not already present in custom css subreddit list`); | |
for (const subToAdd of subsToAdd) { | |
console.log(`adding missing sub '${subToAdd}'`); | |
bpm_prefs.prefs.customCSSSubreddits[subToAdd] = 0; | |
} | |
console.log(`all ${subsToAdd.size} missing subs have been added, calling sync_key`); | |
console.warn(`NOTE: IGNORE THE ERROR TypeError: Cannot read property 'method' of undefined`); | |
bpm_prefs.sync_key("customCSSSubreddits"); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment