Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to change article color through .css file in the dark reader mode? #2052

Closed
BEST8OY opened this issue Dec 31, 2024 · 7 comments

Comments

@BEST8OY
Copy link

BEST8OY commented Dec 31, 2024

Hello
As stated in the title
Is it possible?
The CSS files only apply when the dark reader mode is off and only changing the background color alone through the CSS and not adjusting other colors doesn't make it look any good!
In some sense I want to be able to change these lines defaults

const DEFAULT_COLORS = {
darkScheme: {
background: "#181a1b",
text: "#e8e6e3"
},
lightScheme: {
background: "#dcdad7",
text: "#181a1b"
}
};

@BEST8OY
Copy link
Author

BEST8OY commented Dec 31, 2024

I checked the .JS file it seems these parameters are also valid for custom .JS file

const themeCacheKeys = [
"mode",
"brightness",
"contrast",
"grayscale",
"sepia",
"darkSchemeBackgroundColor",
"darkSchemeTextColor",
"lightSchemeBackgroundColor",
"lightSchemeTextColor"
];

But why isn't it working?
I also tried using the snippet in this page
https://xiaoyifang.github.io/goldendict-ng/topic_userstyle/
and just to test if those parameters alone work, I changed sepia to 100 but it still didn't apply to GD!
Both latest from git and latest stable release!
image

Update:
Those two added parameters by me seems actually not modifiable!
But still there seems there's a bug with js file not applying because when I use this in a js file

DarkReader.enable({
    brightness: 100,
    contrast: 100,
    sepia: 100,
    grayscale: 0,
});

It doesn't apply but when I do it in inspect element via console it works just fine!

@BEST8OY
Copy link
Author

BEST8OY commented Dec 31, 2024

Github Copilot is really handy :)
I changed this

const DEFAULT_THEME = {
mode: 1,
brightness: 100,
contrast: 100,
grayscale: 0,
sepia: 0,
useFont: false,
fontFamily: isMacOS
? "Helvetica Neue"
: isWindows
? "Segoe UI"
: "Open Sans",
textStroke: 0,
engine: ThemeEngine.dynamicTheme,
stylesheet: "",
darkSchemeBackgroundColor: DEFAULT_COLORS.darkScheme.background,
darkSchemeTextColor: DEFAULT_COLORS.darkScheme.text,
lightSchemeBackgroundColor: DEFAULT_COLORS.lightScheme.background,
lightSchemeTextColor: DEFAULT_COLORS.lightScheme.text,
scrollbarColor: isMacOS ? "" : "auto",
selectionColor: "auto",
styleSystemControls: !isCSSColorSchemePropSupported,
lightColorScheme: "Default",
darkColorScheme: "Default",
immediateModify: false
};

To this

const DEFAULT_THEME = {
    mode: 1,
    brightness: 100,
    contrast: 100,
    grayscale: 0,
    sepia: 0,
    useFont: false,
    fontFamily: isMacOS
        ? "Helvetica Neue"
        : isWindows
            ? "Segoe UI"
            : "Open Sans",
    textStroke: 0,
    engine: ThemeEngine.dynamicTheme,
    stylesheet: "",
    darkSchemeBackgroundColor: "#181a1b", // default value
    darkSchemeTextColor: "#e8e6e3", // default value
    lightSchemeBackgroundColor: DEFAULT_COLORS.lightScheme.background,
    lightSchemeTextColor: DEFAULT_COLORS.lightScheme.text,
    scrollbarColor: isMacOS ? "" : "auto",
    selectionColor: "auto",
    styleSystemControls: !isCSSColorSchemePropSupported,
    lightColorScheme: "Default",
    darkColorScheme: "Default",
    immediateModify: false
};

function enable(themeOptions = {}, fixes = null) {
    const theme = {
        ...DEFAULT_THEME,
        ...themeOptions,
        darkSchemeBackgroundColor: themeOptions.darkSchemeBackgroundColor || DEFAULT_THEME.darkSchemeBackgroundColor,
        darkSchemeTextColor: themeOptions.darkSchemeTextColor || DEFAULT_THEME.darkSchemeTextColor
    };
    if (theme.engine !== ThemeEngine.dynamicTheme) {
        throw new Error("Theme engine is not supported.");
    }
    createOrUpdateDynamicThemeInternal(theme, fixes, isIFrame);
    isDarkReaderEnabled = true;
}

Built it and now it does what I want!
But the custom js file in style folder not applying is still there!

image

@xiaoyifang
Copy link
Owner

xiaoyifang commented Jan 4, 2025

image

article-script.js should not placed under style folder.
image

@BEST8OY
Copy link
Author

BEST8OY commented Jan 4, 2025

article-script.js should not placed under style folder. ![image](https://private-user-

Yeah, sorry for the mistake. I'm not sure How I missed that! :)
If the feature to change those parameter I mentioned is not gonna get implemented, please close the issue.
Thanks

@xiaoyifang
Copy link
Owner

If the feature to change those parameter I mentioned is not gonna get implemented, please close the issue.

you can submit a PR,and illustrate what your changes doing.

@shenlebantongying
Copy link
Collaborator

The code in #2065 already exists somewhere else.

function enable(themeOptions = {}, fixes = null) {
const theme = { ...DEFAULT_THEME, ...themeOptions };
if (theme.engine !== ThemeEngine.dynamicTheme) {
throw new Error("Theme engine is not supported.");
}
createOrUpdateDynamicThemeInternal(theme, fixes, isIFrame);
isDarkReaderEnabled = true;
}

Just put the js file in the correct folder as mentioned in the doc.

@BEST8OY
Copy link
Author

BEST8OY commented Jan 5, 2025

Just put the js file in the correct folder as mentioned in the doc.

Yep, it all stemmed from me not putting it in the correct place!
It would be nice to mention what parameters are customizable in the docs!
Not everyone can actually search the code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants