THIS IS A STATIC MIRROR OF USERSCRIPTS.ORG - LOGINS DO NOT WORK

GM_setStyle

By Marti Last update Oct 10, 2013 — Installed 14,855 times.

Script Summary: Alternative to GM_addStyle for Greasemonkey



Version: 0.0.15

Copyright: 2011+, Marti Martz (http://userscripts.org/users/37004)

License: GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html

[Script homepage](https://github.com/Martii/UserScripts/tree/master/lib/GM_setStyle)

[⬆](#top) [⬇](#footer)

NOTES

  • The API is not frozen yet
  • Return values may not be present with @run-at document-start in this implementation depending on the status of [greasemonkey#1384](http://github.com/greasemonkey/greasemonkey/issues/1384)... In these situations use the callback object parameter instead.
  • Comments are removed from CSS by design during validation. :)

[⬆](#top) [⬇](#footer)

Description

Compatibility Matrix
This Script is compatible with...
[Mozilla Firefox](http://www.getfirefox.com/)
[Mozilla Seamonkey](http://www.seamonkey-project.org/)
[Apple Safari](http://www.apple.com/safari/)
[Opera Software Opera](http://www.opera.com/)
[Microsoft Internet Explorer](http://www.microsoft.com/windows/internet-explorer/)
[Google Chromium](http://dev.chromium.org/chromium-projects)[Google Chrome (Intel Only)](http://www.google.com/chrome/)
Linux
[Greasemonkey](https://addons.mozilla.org/firefox/addon/748)
[Greasemonkey Port](https://sourceforge.net/projects/gmport/files/)
Macintosh
[Greasemonkey](https://addons.mozilla.org/firefox/addon/748)
[Greasemonkey Port](https://sourceforge.net/projects/gmport/files/)
Windows
[Greasemonkey](https://addons.mozilla.org/firefox/addon/748)
[Greasemonkey Port](https://sourceforge.net/projects/gmport/files/)
(TIP: Hover your mouse over an icon)

Alternative to using [GM_addStyle](http://sf.net/apps/mediawiki/greasemonkey/index.php?title=GM_addStyle) with validation and "pretty" simple formatting

To be used with [@require](http://sf.net/apps/mediawiki/greasemonkey/index.php?title=Metadata_Block#.40require). It won't do any good if installed directly.

NOTE: Firefox 3.6.x has some issues so validation and formatting will not occur if the ability is not present.

More details to come as they develop. :)

[⬆](#top) [⬇](#footer)

Syntax

Quick example(s) until full API listing can be created (possibly some more features too)
let styleNode = GM_setStyle({

  // OPTIONAL: Set the node to reuse... use null to return cssText instead of styleNode
  node: styleNode,

  // OPTIONAL: Set the media attribute
  media: "screen, projection",

  // OPTIONAL: The CSS to use... supports CDATA Multi-line XMLLists DIRECTLY!
  data: ".selectorA { rule: value; } #selectorB { position: fixed }",

  // OPTIONAL: How to reassemble the rules... default is newline character
  space: "\n",

  // OPTIONAL: Callback usually for use with @run-at document-start
  callback: function () {
    GM_log([
      this.node,
      this.data
    ].join('\n'));
  }

});