GM_getResourceURL
From GreaseSpot
Contents |
[edit] Description
Given a defined @resource, this method returns it as a URL.
Compatibility: Greasemonkey 0.8.0+
[edit] Syntax
function GM_getResourceURL( resourceName )
[edit] Arguments
-
resourceName -
StringThe name provided when the @resource was defined, follow that link for valid naming restrictions.
[edit] Returns
String.
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]
[edit] Raises
Throws an Error when the named resource does not exist.
[edit] 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);