ortiza5 / modding-vivaldi

A not-even-WIP-anymore collection of guides about modifying the Vivaldi browser
The Unlicense
7 stars 1 forks source link

Inserting css #30

Closed code3z closed 3 years ago

code3z commented 3 years ago

Is it good? Should it be included at all? Should I move the file into a different folder?

Resolves #26

ghost commented 3 years ago

You’re too verbose. Sorry, I think I’ll do it myself; it’ll take less effort for us both.

code3z commented 3 years ago

You mean, just include this?

Injecting CSS with JavaScript

Author(s): code3z (code3 on the forum) and tiosgz (potmeklecbohdan on the forum)

CSS styles are fairly easy to add to Vivaldi, and most of the time you will probably use Vivaldi's native CSS mods manager. But for JS mods that require a little bit of CSS, you may want to combine the CSS in Javascript.

The benefit is that it's all in one file, and easier for users to install. The downsides are that the CSS is harder to customize, and the code is a bit harder to write.

JavaScript Template


(function () {
  let styles = document.createElement("style");
  styles.type = "text/css";
  styles.setAttribute("data-id", "<name-of-mod>-styles");
styles.innerHTML = `/* Add CSS styles here.
They can take up multiple lines. Example: */
* {
  color: #00ff00 !important;
}

`;
document.head.append(styles);
})();
ghost commented 3 years ago

Wrt length, yes. But at this point suggesting a reword is like writing it anew…

code3z commented 3 years ago

If the code is bad, could you tell me what I should do next time?

ghost commented 3 years ago

See #31 for how I’d imagine it (feel free to criticise)