Difference between revisions of "GM.getResourceUrl"

From GreaseSpot Wiki
Jump to navigationJump to search
(Update for 4.0)
(→‎Syntax: use GM.* not GM_* now)
 
Line 7: Line 7:
== Syntax ==
== Syntax ==


{{Function|GM_getResourceUrl|resourceName}}
{{Function|GM.getResourceUrl|resourceName}}


=== Arguments ===
=== Arguments ===

Latest revision as of 01:10, 12 December 2019

Description

Given a defined @resource, this method returns it as a URL.

Compatibility: Greasemonkey 4.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

A Promise, rejected on failure and resolved with a String URL on success. Treat the result as opaque string. It will work where you need a URL (for a <link> or <style> for CSS, for an <img> tag, or similar).

Examples

// ==UserScript==
// @name Image resource example
// @resource logo ../icons/laptop.png
// @grant GM.getResourceUrl
// ==/UserScript==

(async function() {
let img = document.createElement("img");
img.src = await GM.getResourceUrl("logo");
document.body.appendChild(img);
})();