GM.getResourceUrl
From GreaseSpot Wiki
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); })();