GM.getResourceText: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
m (Undo revision 4134 by Aavindraa (Talk) Restored "sensical" statement)
(Update for 4.0)
 
(17 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{underscore|title=GM_getResourceText}}
As of Greasemonkey 4.0, this method does not exist.
__NOTOC__
{{Greasemonkey Manual TOC}}


<!-- 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.20080609.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_block_resourceName";</code>
:* While the resourceName is non-semantic, it is suggested that it should be compatible with JavaScript variable naming conventions and XML/CSS naming conventions to help keep things consistent.
:* This value is used in retrieval of the same-named resource specified in the corresponding metadata block [[Metadata_block#.40resource |@resource]] key. After it is retrieved, no formatting on the resource will occur, and it will be returned upon completion of this API method.


[[#top|top]] | [[#Syntax|back]]''
<code>String</code>
 
=== Raises ===
 
Throws an <code>Error</code> when the named resource does not exist.


== Examples ==
== Examples ==
{{Core samp |1=<pre style="border: none; margin: inherit;">
 
<pre class='sample'>
// ==UserScript==
// ==UserScript==
// @name          My Script
// @resource prototype http://www.example.com/prototype.js
// @namespace    <nowiki>http://www.example.com/gmscripts/</nowiki>
// @description  Scripting is fun
// @include      <nowiki>http://www.example.com/*</nowiki>
// @resource     prototype http://www.example.com/prototype.js
// ==/UserScript==
// ==/UserScript==


(function() {
var prototypeSource = GM_getResourceText("prototype");
  // some code
</pre>
 
  var myPrototype = GM_getResourceText("prototype");
 
  // some code
 
})();
</pre>}}
 
[[#top|top]]


== Notes ==
== See Also ==


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


[[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.