|
|
(26 intermediate revisions by 5 users not shown) |
Line 1: |
Line 1: |
| {{underscore|title=GM_getResourceText}}
| | As of Greasemonkey 4.0, this method does not exist. |
| __NOTOC__
| |
|
| |
|
| | <!-- Original text, in case 4.x restores this method? |
| == Description == | | == Description == |
|
| |
|
| This [[API_reference|API]] method loads an external resource, such as an external JavaScript routine, and returns the string for use in the DOM.
| | Given a defined [[Metadata Block#.40resource|@resource]], this method returns it as a string. |
|
| |
|
| [[#Examples|Examples]] | [[#Notes|Notes]] | | Compatibility: [[Version_history#0.8.20080609.0|Greasemonkey 0.8.0+]] |
|
| |
|
| == Syntax == | | == Syntax == |
|
| |
|
| '''GM_getResourceText(''' ''resourceName'' ''')'''
| | {{Function|GM_getResourceText|resourceName}} |
|
| |
|
| :Value: Function
| | === Arguments === |
| :Returns: String
| |
| :Compatibility: [[Version_history#0.8.0|Greasemonkey 0.8.0+]]
| |
|
| |
|
| :{| cellpadding="5" style="border-style:solid; background:#FFFFE0;"
| | ; resourceName |
| |+ Parameters
| | : <code>String</code> The name provided when the [[Metadata Block#.40resource|@resource]] was defined, follow that link for valid naming restrictions. |
| !style="background:#CC9900;"|'''Properties'''
| |
| |-
| |
| | <code><span style="background:#FFFFE0;">[[#resourceName |resourceName]]</span></code>
| |
| |}
| |
| :* All properties are optional except [[#resourceName|resourceName]].
| |
|
| |
|
| [[#top|top]]
| | === Returns === |
| === Properties === | |
| ----
| |
| ==== <code>resourceName</code> ====
| |
| :Value: String
| |
| :Usage: <code>'''resourceName''' = "metadata-resource-name<sup>[[#Notes|[1]]]</sup>";</code>
| |
|
| |
|
| :* This value is used in retrieval of the same named resource specified in the corresponding [[Metadata_block |metadata block @resource]] key. After it is retrieved, no formatting on the resource will occur, and it will be returned upon completion of this API method.
| | <code>String</code> |
|
| |
|
| [[#top|top]] | [[#Syntax|back]]''
| | === Raises === |
| | |
| | Throws an <code>Error</code> when the named resource does not exist. |
|
| |
|
| == Examples == | | == Examples == |
| <code><pre>
| | |
| | <pre class='sample'> |
| // ==UserScript== | | // ==UserScript== |
| // @name My Script | | // @resource prototype http://www.example.com/prototype.js |
| // @namespace http://www.example.com/gmscripts/
| |
| // @description Example GM_getResourceText
| |
| // @include http://www.example.com/*
| |
| // @resource prototype http://www.prototypejs.org/assets/2007/11/6/prototype.js
| |
| // ==/UserScript== | | // ==/UserScript== |
|
| |
|
| /* some code */
| | var prototypeSource = GM_getResourceText("prototype"); |
| | | </pre> |
| location.href = "javascript:void(" + GM_getResourceText("prototype") + ")";
| |
| </pre></code> | |
| | |
| [[#top|top]]
| |
|
| |
|
| == Notes == | | == See Also == |
| <sup>[[#resourceName|[1]]]</sup> While the variable names here are non-semantic, it is assumed that it should be compatible with JavaScript variable naming conventions and XML/CSS naming conventions to help keep things consistent.
| |
|
| |
|
| [[#top|top]] | | * [[GM_getResourceURL]] |
|
| |
|
| [[Category:API_Reference|G]] | | [[Category:API_Reference|G]] |
| | --> |
As of Greasemonkey 4.0, this method does not exist.