Created
June 22, 2021 11:52
-
-
Save doZennn/687e4923b3029d8fd3fa33944403dc1d 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
// ==UserScript== | |
// @name YouTube auto theme switcher | |
// @namespace https://jozen.blue/ | |
// @version 1.0.0 | |
// @description Switches the YouTube theme cookie based on current time. | |
// @author Zennn | |
// @match https://www.youtube.com/* | |
// @exclude https://www.youtube.com/embed/* | |
// @icon https://www.google.com/s2/favicons?domain=youtube.com | |
// @run-at document-start | |
// @grant GM.cookie | |
// @noframes | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const light = '40080000'; | |
const dark = '40000400'; | |
let mode = light; | |
const today = new Date().getHours(); | |
// Light mode from 7AM until 8PM | |
if (today > 5 && today < 19) { | |
mode = light; | |
} else { | |
mode = dark; | |
} | |
GM.cookie.list({ name: 'PREF' }).then((cookies) => { | |
const { value, expirationDate, httpOnly, secure, domain } = cookies[0]; | |
const params = new URLSearchParams(value); | |
// Stop if already correct theme | |
if (params.get('f6') === mode) { | |
return; | |
} | |
params.set('f6', mode); | |
GM.cookie.set({ | |
name: 'PREF', | |
value: params.toString(), | |
expirationDate, | |
httpOnly, | |
secure, | |
domain | |
}).then(() => { | |
// Won't even notice this reload cause it happens at document-start | |
window.location.reload(); | |
}) | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment