Reddit Theme Cookie Modifier

Modify the `theme` value inside the cookie so reddit can switch dark mode automatically

目前為 2025-11-17 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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);
})();