User:Asqueella/JEP 107: Difference between revisions

Jump to navigation Jump to search
→‎API Methods: replace scriptMod.enable/disable with global add/remove, make add() explicit [8:a204bab6d64d]
(→‎ScriptMod constructor: Make 'include' required [7:ff25bb83ffdb in my repo])
(→‎API Methods: replace scriptMod.enable/disable with global add/remove, make add() explicit [8:a204bab6d64d])
Line 32: Line 32:
Here's an example of how the ScriptMod API can be used in a jetpack:
Here's an example of how the ScriptMod API can be used in a jetpack:


<pre class="brush:js;">
<pre class="brush:js; gutter:0">
var ScriptMod = require("page-mod").ScriptMod;
var ScriptMod = require("page-mod").ScriptMod;
var myMod = new ScriptMod({
var myMod = new ScriptMod({
Line 77: Line 77:
** The specified callbacks are called with a single <code>wrappedWindow</code> parameter -- the content's <code>window</code> object wrapped in an XPCNativeWrapper. The callback's <code>this</code> is the page mod object ('''TBD''' not currently implemented). It goes without saying that with this syntax the callbacks are run in the calling module's scope, not in the content page's scope.
** The specified callbacks are called with a single <code>wrappedWindow</code> parameter -- the content's <code>window</code> object wrapped in an XPCNativeWrapper. The callback's <code>this</code> is the page mod object ('''TBD''' not currently implemented). It goes without saying that with this syntax the callbacks are run in the calling module's scope, not in the content page's scope.


Creating a <code>ScriptMod</code> instance automatically [[#scriptMod-enable|enables it]].
Creating a <code>ScriptMod</code> instance does '''not''' automatically [[#global-add|add]] (activate) it.


==== <code>ScriptMod</code> APIs ====
==== <code id="global-add">add()</code> ====
* Instance properties
<pre class="brush:js; gutter:0">
** <code id="scriptMod-disable">scriptMod.disable()</code>. Call this to stop a script mod from running on further pages. This does not undo the mod's effects on already loaded pages.
require("page-mod").add(scriptMod)
** <code id="scriptMod-enable">scriptMod.enable()</code>. Enabling a script mod makes it take effect on any matching pages that start to load after the script mod is enabled. Enabling a script mod does not apply it to existing matching pages.
</pre>
 
* <code>add()</code> makes the specified script mod take effect on any matching pages that start to load after the call. Adding a script mod does not apply it to existing matching pages.
* <code>scriptMod</code> must be a [[#ScriptMod constructor|<code>ScriptMod</code>]] instance.
* Trying to add the same script mod twice throws an exception.
* This method does not have a return value.
 
==== <code id="global-add">remove()</code> ====
<pre class="brush:js; gutter:0">
require("page-mod").remove(scriptMod)
</pre>
* Call <code>remove()</code> to stop a script mod from running on further pages. This does not undo the mod's effects on already loaded pages.
* <code>scriptMod</code> must be a [[#ScriptMod constructor|<code>ScriptMod</code>]] instance, added earlier.
* Trying to remove a script mod, that has not been added, throws.
* This method does not have a return value.


=== Discussion ===
=== Discussion ===
Confirmed users
162

edits

Navigation menu