Marti / GM_setStyle

Published:

Version: 0.0.17.005b updated

Summary: Alternative to GM_addStyle for Greasemonkey

Copyright: 2011+, Marti Martz (https://openuserjs.org/users/Marti)

License: GPL-3.0+; http://www.gnu.org/licenses/gpl-3.0.txt

License: CC-BY-NC-SA-4.0; https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode

Collaborator: sizzle

CHANGELOG

  • No miscellaneous notes at this time

NOTES

  • This API library is not frozen yet
  • Return values may not be present with @run-at document-start in this implementation depending on the status of upstream#1384... In these situations use the callback object parameter instead.
  • Comments are removed from CSS by design during validation. :)

Overview

Alternative to using GM_addStyle with validation and "pretty" simple formatting.

To be used with @require. 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. :)

Compatibility Matrix

Mozilla Firefox Mozilla Seamonkey Apple Safari Opera Software Opera Microsoft Internet Explorer Chromium Projects ChromiumGoogle Chrome                     
Linux Greasemonkey Greasemonkey prc Greasemonkey Port
Macintosh Greasemonkey Greasemonkey prc Greasemonkey Port
Windows Greasemonkey Greasemonkey prc Greasemonkey Port
  • Use this compatibility matrix to determine if this script is right for your system. Find the platform on the left and find your browser on the top. Where they intersect is the compatibility.

Syntax

Quick example 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 () {
    console.log([
      this.node,
      this.data
    ].join('\n'));
  }

});

Userscripts Using This Library

Rating: 3

5 Votes
-4