GM.getResourceUrl: Difference between revisions
From GreaseSpot Wiki
Jump to navigationJump to search
→Returns: greasemonkey-script: protocol |
m Arantius moved page GM getResourceURL to GM.getResourceUrl: Greasemonkey 4.0 |
(No difference)
|
Revision as of 14:34, 3 November 2017
Description
Given a defined @resource, this method returns it as a URL.
Compatibility: Greasemonkey 0.8.0+
Syntax
function GM_getResourceURL( resourceName )
Arguments
resourceName
String
The name provided when the @resource was defined, follow that link for valid naming restrictions.
Returns
String
.
greasemonkey-script:[script uuid]/[resource name]
i.e.
greasemonkey-script:94242686-1400-4dce-982a-090cbfef7ba1/image
Prior to Greasemonkey 1.0
Returns string containing a base64 encoded data:
URI.
Note: This can be used anywhere a data:
URI will work (E.G. <img>
or <script>
).
This does not include <object>
or <embed>
.
The result is a base64 encoded URI, which is then also URI encoded, as suggested by Wikipedia, because of "+" and "/" characters in the base64 alphabet. Thus, for certain usage, this URI encoding may need to be removed. [1]
Raises
Throws an Error
when the named resource does not exist.
Examples
// ==UserScript== // @resource logo http://www.example.com/logo.png // ==/UserScript== var img = document.createElement('img'); img.src = GM_getResourceURL("logo"); document.body.appendChild(img);