GM addStyle: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
m Reverted edits by Mapzkie05 (Talk) to last revision by Arantius
link to @require helper
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:GM_addStyle}}
{{DISPLAYTITLE:GM_addStyle}}  


== Description ==
As of Greasemonkey 4.0, this method has been removed.


This method adds a string of CSS to the document.
You can `@require` a helper script to provide the same functionality, for example [https://gist.github.com/arantius/eec890c9ce4ff2f7abee896c0bba664d gm-addstyle.js].
It creates a new <code><style></code> element, adds the given CSS to it, and inserts it into the <code><head></code>.
 
Compatibility: [[Version_history#0.6.1|Greasemonkey 0.6.1+]]
 
== Syntax ==
 
{{Function|GM_addStyle|css}}
 
=== Arguments ===
 
; <code>css</code>
: <code>String</code> A string of CSS.
 
== Examples ==
 
<pre class='sample'>
GM_addStyle("body { color: white; background-color: black; } img { border: 0; }");
</pre>
 
== Notes ==
 
* Add <code>!important</code> at the end of a CSS declaration to override an existing value (i.e. values the page specifies).
* Using [[Multi Line Strings]] may be helpful.
 
[[Category:API_Reference|A]]

Latest revision as of 15:12, 8 November 2023


As of Greasemonkey 4.0, this method has been removed.

You can `@require` a helper script to provide the same functionality, for example gm-addstyle.js.