GM.getResourceText: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
Marti (talk | contribs)
m →‎Description: Need to expand on these descriptions, but that seems to be the intent.
Update for 4.0
 
(31 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+]]


:{| border="1" cellpadding="5"
; resourceName
|+ Parameters
: <code>String</code> The name provided when the [[Metadata Block#.40resource|@resource]] was defined, follow that link for valid naming restrictions.
!|'''Properties'''
|-
| <code>[[#resourceName |resourceName]]</code>
|}
:* All properties are optional except [[#resourceName|resourceName]].


[[#top|top]]
=== Returns ===
=== Properties ===
----
==== <code>resourceName</code> ====
:Value: String
:Usage: <code>'''resourceName''' = "metadata-resource-name";</code>


:* This value is used to retrieve the [[Metadata_block |metadata block @resource]] name URI which will be retrieved, unformatted, and 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]]
== See Also ==


== Notes ==
* [[GM_getResourceURL]]
[[#top|top]]


[[Category:API_Reference|G]]
[[Category:API_Reference|G]]
-->

Latest revision as of 14:33, 3 November 2017

As of Greasemonkey 4.0, this method does not exist.