Modify the `theme` value inside the cookie so reddit can switch dark mode automatically
当前为
// ==UserScript==
// @name Reddit Theme Cookie Modifier
// @namespace http://tampermonkey.net/
// @version 0.11
// @description Modify the `theme` value inside the cookie so reddit can switch dark mode automatically
// @author Orthon Jiang
// @match *://*.reddit.com/*
// @icon https://www.reddit.com/favicon.ico
// @grant none
// @license MIT
// ==/UserScript==
(function () {
'use strict';
function setThemeValue() {
const cookieStr = document.cookie.split('; ').find(row => row.startsWith('theme='));
if (!cookieStr) {
return;
}
let value = cookieStr.split('=')[1];
try {
const obj = JSON.parse(value);
obj.theme = 0;
value = JSON.stringify(obj);
} catch (e) {
value = 0;
}
document.cookie = "theme=" + value + "; path=/";
}
setThemeValue();
setInterval(setThemeValue, 2000);
})();