dcinside Automatic Dark Mode

Switches dcinside dark mode on and off according to System Theme (if exposed by browser).

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         dcinside Automatic Dark Mode
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Switches dcinside dark mode on and off according to System Theme (if exposed by browser).
// @author       Orthon Jiang
// @match        *://*.dcinside.com/*
// @icon         https://gall.dcinside.com/favicon.ico
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    const getPreferredTheme = () => window?.matchMedia?.('(prefers-color-scheme:dark)')?.matches ? 'dark' : 'light';
    const getDcinsideTheme = () => document.getElementById("css-darkmode") ? 'dark' : 'light';
    const applyPreferredTheme = () => {
        if (getDcinsideTheme() != getPreferredTheme()) {
            darkmode();
        }
    }
    window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change',applyPreferredTheme);
    // The above event listener is probably not applied on page load, so we do that manually once. Also we need to wait a bit since reddit seems to set the theme manually after a bit.
    setTimeout(applyPreferredTheme, 2000); //Two seconds will elapse and Code will execute.

})();