themoeway / yomitan

Japanese pop-up dictionary browser extension. Successor to Yomichan.
https://chromewebstore.google.com/detail/yomitan/likgccmbimhjbgkjambclfkhldnlhbnn
GNU General Public License v3.0
989 stars 76 forks source link

Custom CSS Distributed With Dictionaries #542

Closed MarvNC closed 1 month ago

MarvNC commented 6 months ago

LGTM. (Though why does this work like this at all...? Wouldn't it make more sense for a dictionary to distribute some CSS (maybe with basic filtering to avoid remote resources) and then just refer to class names in the structured content...?)

Originally posted by @djahandarie in https://github.com/themoeway/yomitan/pull/527#pullrequestreview-1821463382

I always thought the same, it seemed quite limiting. Maybe the reason is compatibility with light and dark themes and ensuring a consistent experience by limiting what can be styled:

Correct, this is the rationale for not originally adding them. That and they can't be themed easily by custom CSS, which leads to an inconsistent UI/UX. There is probably a better way to support this, such as by having the extension expose custom CSS vars for dictionaries to use for colors, but ultimately that would still just involve using custom string values for color/background-color.

Originally posted by @toasted-nutbread in https://github.com/themoeway/yomitan/issues/450#issuecomment-1869227125

toasted-nutbread commented 6 months ago

CSS scoping is an issue, if dictionaries are basically just injecting a <style> node with rules. If the CSS classes are defined in a way that is more similar to structured content, but having common type definitions for common classes, the issue is a bit different, in that there suddenly needs to be a way to store and retrieve that in the database.

Again the reason why it is currently set up that way is because when I designed it, I did not foresee it growing into such a broadly used feature as it is today.

djahandarie commented 6 months ago

I think we have three options for scoping:

toasted-nutbread commented 6 months ago

Shadow dom is possible but probably very ugly. Problems with Anki export though.