User:Asqueella/JEP 107: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
mNo edit summary
Line 1: Line 1:
This is an edited version of [[Labs/Jetpack/Reboot/JEP/107]].
This is an alternative version of [[Labs/Jetpack/Reboot/JEP/107]] ('''page mods''').
 
----


= Page Mods =
There are two common ways to modify web pages from the browser:
There are two common ways to modify web pages from the browser:
* by specifying custom CSS to apply to specific pages, sites, or all web content. (This is what [https://addons.mozilla.org/en-US/firefox/addon/2108 Stylish extension] does.)
* by specifying custom CSS to apply to specific pages, sites, or all web content. (This is what [https://addons.mozilla.org/en-US/firefox/addon/2108 Stylish extension] does.)
Line 62: Line 63:
** 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 enables it, so that the script mod takes effect on any matching pages that start to load after it's created.
Creating a <code>ScriptMod</code> instance automatically [[#scriptMod-enable|enables it]].
 
Enabling a script mod does not apply it to existing matching pages.
 
To stop a script mod from running on further pages, call <code>scriptMod.disable()</code>. This does not undo the mod's effects on already loaded pages.


===== ISSUE: What format should be chosen for <code>include</code> rules? =====
===== ISSUE: What format should be chosen for <code>include</code> rules? =====
Line 90: Line 87:


==== <code>ScriptMod</code> APIs ====
==== <code>ScriptMod</code> APIs ====
* Instance properties
** <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.
** <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.
* Helper functions available as properties on the <code>ScriptMod</code> constructor
** <code>ScriptMod.onDOMContentLoaded(''callback'')</code> - when passed as one of the <code>scripts</code> in the <code>ScriptMod</code> constructor options, calls the <code>callback</code> on matching pages when their DOM is available (on the [http://wiki.greasespot.net/DOMContentLoaded <code>DOMContentLoaded</code>] event).


=== Style mods ===
=== Style mods ===
TBD
TBD
== Use Cases ==
# Creation of CSS-based add-ons like Stylish, EditCSS, etc...
# Creation of JS-based add-ons like Execute JS, JS Exec etc...
# In General: Any Greasemonky-style add-on, with the advantage that this API would allow for far greater flexibility - turning on and off only certain parts of a mod, automatically flashing a new url/web-page with the active parts of a mod by using the <i>add</i> method to include a new match to the matches white-list
=== Common Actions ===
The API, if done in this fashion, give the developer the ability to dramatically simplify application actions such as:
* Creating an instance of Page Mods that adds script or styles to a set of matched urls
* Further extending and existing instance of Page Mods with additional styles and script
* Toggling on and off specific styles or script within a Page Mods instance
* Adding new matches to a Page Mods instance, which in turn instantly applies active styles and script within that instance to the newly added matches.
* Multiple instances of Page Mods can be instantiated, which enables a whole cadre of functionality that the object-bound 'singleton' implementation neglects.
Confirmed users
161

edits

Navigation menu