diff options
author | SimonBrazell <simon@brazell.com.au> | 2020-05-08 22:40:07 +1000 |
---|---|---|
committer | SimonBrazell <simon@brazell.com.au> | 2020-05-08 22:40:07 +1000 |
commit | 8f82745733ed063a9a14d3176abb59160ded0bc9 (patch) | |
tree | d1743a74d10aa665a978fbcf171ef15122179310 /assets/persist-invidious-prefs.js | |
parent | Fixes #45 - some usersnames caught in instagramReservedPaths (diff) | |
download | libredirect-8f82745733ed063a9a14d3176abb59160ded0bc9.zip |
Closes #36 - added option to persist Invidious prefs
Diffstat (limited to 'assets/persist-invidious-prefs.js')
-rw-r--r-- | assets/persist-invidious-prefs.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/assets/persist-invidious-prefs.js b/assets/persist-invidious-prefs.js new file mode 100644 index 00000000..4c13a310 --- /dev/null +++ b/assets/persist-invidious-prefs.js @@ -0,0 +1,30 @@ +'use strict'; + +window.browser = window.browser || window.chrome; + +function getCookie() { + let ca = document.cookie.split(';'); + for (let i = 0; i < ca.length; i++) { + let c = ca[i]; + while (c.charAt(0) == ' ') c = c.substring(1, c.length); + if (c.indexOf('PREFS=') == 0) { + return JSON.parse( + decodeURIComponent(c.substring('PREFS='.length, c.length)) + ) + }; + } + return {}; +} + +browser.storage.sync.get( + ['alwaysProxy', 'videoQuality', 'invidiousDarkMode', 'persistInvidiousPrefs'], + (result) => { + if (result.persistInvidiousPrefs) { + const prefs = getCookie(); + prefs.local = result.alwaysProxy; + prefs.quality = result.videoQuality; + prefs.dark_mode = result.invidiousDarkMode; + document.cookie = `PREFS=${encodeURIComponent(JSON.stringify(prefs))}`; + } + } +); \ No newline at end of file |