GM.getResourceText: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
m (Notated a concern about the resourceName variable... note I extrapolated this variable name from the developer group when I created this article... so I didn't do it ;D)
(Update for 4.0)
 
(30 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<sup>[[#Notes|[1]]]</sup>";</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") + ")";
== See Also ==
</pre></code>


[[#top|top]]
* [[GM_getResourceURL]]


== Notes ==
[[Category:API_Reference|G]]
[[Category:API_Reference|G]]
<sup>[[#resourceName|[1]]]</sup> While the variable name described here has hyphens in it, 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]]

Latest revision as of 14:33, 3 November 2017

As of Greasemonkey 4.0, this method does not exist.