Marti / GM_setStyle

Published:

Version: 0.0.17.007b+fa06e12 updated

Summary: Alternative to GM_addStyle for Greasemonkey

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

License: GPL-3.0-or-later; 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

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. :)

CHANGELOG

  • 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. :)
  • No other miscellaneous notes at this time

Compatibility Matrix

Android iOS Linux macOS Windows
Google Chrome Tampermonkey Tampermonkey Tampermonkey
Chromium Projects Chromium Tampermonkey Tampermonkey Tampermonkey
Microsoft Edge Tampermonkey
David Rosca Falkon yes yes
Mozilla Firefox Greasemonkey Greasemonkey Greasemonkey Greasemonkey
Microsoft Internet Explorer
Maxthon Violentmonkey Violentmonkey Violentmonkey
Opera Software Opera Violentmonkey Violentmonkey Violentmonkey
Moonchild Productions Pale Moon Greasemonkey "Fork" Greasemonkey "Fork"
Apple Safari Tampermonkey
Mozilla SeaMonkey Greasemonkey Port Greasemonkey Port Greasemonkey Port
Яндекс Yandex Tampermonkey Tampermonkey Tampermonkey Tampermonkey
  • Use this compatibility matrix to determine if this script is right for your system. Find the platform on the top and find your browser on the left. Where they intersect is the compatibility.
  • QupZilla/Falkon requires v2.0.0 or better.
  • Firefox 57+ is quite crippled and currently there may be limited support for GM4.
  • Safari 13+ may be unsupported depending on the state of the .user.js engine under that browser.

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'));
  }

});

Rating: 4

4 Votes
-4