Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
initial add of SuperStop code
- Loading branch information
1 parent
42e574f
commit 0a86b95
Showing
3 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,4 +1,6 @@ | |||
SuperStop | SuperStop | ||
========= | ========= | ||
|
|
||
SuperStop | SuperStop is a Firefox addon that adds a Shift+Esc shortcut key that stops any | ||
active animations, WebSocket and XHR requests even with the Firefox stop button | |||
is disabled. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,87 @@ | |||
/* This Source Code Form is subject to the terms of the Mozilla Public | |||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | |||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | |||
|
|||
var Cu = Components.utils; | |||
|
|||
Cu.import("resource://gre/modules/Services.jsm"); | |||
|
|||
function startup(aData, aReason) { | |||
// Install the new shortcut in all browser windows, current and future | |||
watchWindows(function (window) { | |||
let doc = window.document; | |||
|
|||
function makeXUL(type) doc.createElement(type); | |||
|
|||
let keyset = makeXUL("keyset"); | |||
keyset.id = "superstop-keyset"; | |||
|
|||
let key = makeXUL("key"); | |||
key.id = "superstop-key"; | |||
key.setAttribute("keycode", "VK_ESCAPE"); | |||
key.setAttribute("modifiers", "shift"); | |||
key.setAttribute("oncommand", "BrowserStop();"); | |||
doc.getElementById("mainKeyset").appendChild(keyset).appendChild(key); | |||
}); | |||
} | |||
|
|||
function shutdown(aData, aReason) { | |||
if (aReason != APP_SHUTDOWN) { | |||
unloaders.forEach(function (f) { | |||
try { | |||
f(); | |||
} catch (ex) {} | |||
}); | |||
} | |||
} | |||
|
|||
function install(aData, aReason) { } | |||
|
|||
function uninstall(aData, aReason) { } | |||
|
|||
|
|||
/* Code from: https://github.com/Mardak/restartless/blob/watchWindows/bootstrap.js */ | |||
let unloaders = []; | |||
|
|||
function watchWindows(callback) { | |||
// Wrap the callback in a function that ignores failures | |||
function watcher(window) { | |||
try { | |||
// Now that the window has loaded, only handle browser windows | |||
let documentElement = window.document.documentElement; | |||
if (documentElement.getAttribute("windowtype") == "navigator:browser") | |||
callback(window); | |||
} | |||
catch(ex) {} | |||
} | |||
|
|||
// Wait for the window to finish loading before running the callback | |||
function runOnLoad(window) { | |||
// Listen for one load event before checking the window type | |||
window.addEventListener("load", function runOnce() { | |||
window.removeEventListener("load", runOnce, false); | |||
watcher(window); | |||
}, false); | |||
} | |||
|
|||
// Add functionality to existing windows | |||
let windows = Services.wm.getEnumerator(null); | |||
while (windows.hasMoreElements()) { | |||
// Only run the watcher immediately if the window is completely loaded | |||
let window = windows.getNext(); | |||
if (window.document.readyState == "complete") | |||
watcher(window); | |||
// Wait for the window to load before continuing | |||
else | |||
runOnLoad(window); | |||
} | |||
|
|||
// Watch for new browser windows opening then wait for it to load | |||
function windowWatcher(subject, topic) { | |||
if (topic == "domwindowopened") | |||
runOnLoad(subject); | |||
} | |||
Services.ww.registerNotification(windowWatcher); | |||
unloaders.push(function() Services.ww.unregisterNotification(windowWatcher)); | |||
} | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#"> | |||
<Description about="urn:mozilla:install-manifest"> | |||
<em:id>superstop@gavinsharp.com</em:id> | |||
<em:type>2</em:type> | |||
<em:name>SuperStop</em:name> | |||
<em:version>0.1</em:version> | |||
<em:bootstrap>true</em:bootstrap> | |||
<em:creator>Gavin Sharp</em:creator> | |||
<em:targetApplication> | |||
<Description> | |||
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id> | |||
<em:minVersion>20.0</em:minVersion> | |||
<em:maxVersion>21.0a1</em:maxVersion> | |||
</Description> | |||
</em:targetApplication> | |||
</Description> | |||
</RDF> |