Permalink
Browse files

Closes #498 Adding a 'Install User Script' context menu item for .use…

…r.js links
  • Loading branch information...
1 parent eb5a0ef commit 40fd4f8bda3b225a5f2f33a9f98462cdb1e3c4a2 @erikvold erikvold committed Aug 27, 2011
@@ -1,5 +1,3 @@
-
-var erik = "";
(function(inc, tools, global){
inc("resource://scriptish/constants.js", tools);
@@ -11,14 +9,14 @@ lazyImport(global, "resource://scriptish/utils/Scriptish_isURLExcluded.js", [
"Scriptish_setExcludes"
]);
-Scriptish_log("step 2a");
+lazyUtil(global, "installUri");
+Scriptish_log("step 2a");
function updateExcludes({json}) {
Scriptish_setExcludes(json);
}
-
var configJSON = sendSyncMessage("Scriptish:FrameSetup", "")[0];
(function(configJSON) {
@@ -43,6 +41,11 @@ Scriptish_log("step 2b");
})(Components.utils.import, {}, this);
-addEventListener("DOMContentLoaded", function() {
- //content.alert(erik);
+addEventListener("load", function() {
+ ContextHandler.registerType("userscript-install", function(popupState, element) {
+ if (/\.user\.js$/.test(element.href)) {
+ return true;
+ }
+ return false;
+ });
}, true);
@@ -6,6 +6,8 @@
lazyImport(global, "resource://scriptish/manager.js", ["Scriptish_manager"]);
lazyImport(global, "resource://scriptish/config.js", ["Scriptish_config"]);
+ lazyUtil(global, "installUri");
+
Scriptish_log("step 1a");
addEventListener("load", function() {
// Check if Scriptish has been updated/installed
@@ -1,4 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<overlay id="scriptish-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://scriptish/content/e10s/browser.js"/>
+
+ <richlistbox id="context-commands">
+ <richlistitem id="scriptish-userscript-install-context-command"
+ class="context-command"
+ type="userscript-install"
+ onclick="Scriptish_installUri(ContextHelper.popupState.linkURL);">
+ <label value="Install User Script"/>
+ </richlistitem>
+ </richlistbox>
</overlay>
@@ -2,9 +2,11 @@ var EXPORTED_SYMBOLS = [];
Components.utils.import("resource://scriptish/constants.js");
lazyImport(this, "resource://scriptish/config.js", ["Scriptish_config"]);
+lazyImport(this, "resource://scriptish/logging.js", ["Scriptish_log"]);
lazyImport(this, "resource://scriptish/scriptish.js", ["Scriptish"]);
lazyImport(this, "resource://gre/modules/AddonManager.jsm", ["AddonManager", "AddonManagerPrivate"]);
+lazyUtil(this, "notification");
lazyUtil(this, "openManager");
lazyUtil(this, "popupNotification");
lazyUtil(this, "stringBundle");
@@ -24,7 +26,7 @@ const Scriptish_ScriptProvider = {
msg += "' " + Scriptish_stringBundle("statusbar.installed");
var callback = Scriptish_openManager;
- Scriptish_popupNotification({
+ var showedMsg = Scriptish_popupNotification({
id: "scriptish-install-popup-notification",
message: msg,
mainAction: {
@@ -37,6 +39,11 @@ const Scriptish_ScriptProvider = {
persistWhileVisible: true
}
});
+
+ if (!showedMsg) {
+ Scriptish_notification(msg, null, null, callback);
+ }
+
break;
case "scriptish-script-edit-enabling":
AddonManagerPrivate.callAddonListeners(
@@ -62,7 +69,7 @@ const Scriptish_ScriptProvider = {
: Scriptish_stringBundle("statusbar.modified"));
var callback = Scriptish_openManager;
- Scriptish_popupNotification({
+ var showedMsg = Scriptish_popupNotification({
id: "scriptish-install-popup-notification",
message: msg,
mainAction: {
@@ -75,6 +82,11 @@ const Scriptish_ScriptProvider = {
persistWhileVisible: true
}
});
+
+ if (!showedMsg) {
+ Scriptish_notification(msg, null, null, callback);
+ }
+
break;
case "scriptish-script-uninstalling":
AddonManagerPrivate.callAddonListeners("onUninstalling", script, false);
@@ -1,8 +1,11 @@
var EXPORTED_SYMBOLS = ["Scriptish_installUri"];
Components.utils.import("resource://scriptish/constants.js");
+lazyImport(this, "resource://scriptish/logging.js", ["Scriptish_log"]);
lazyImport(this, "resource://scriptish/config/configdownloader.js", ["Scriptish_configDownloader"]);
function Scriptish_installUri(aURI) {
+ aURI = (typeof aURI == "string") ? NetUtil.newURI(aURI) : aURI;
+
// docs for nsicontentpolicy say we're not supposed to block, so short timer.
timeout(function() {
Scriptish_configDownloader.startInstall(aURI);
@@ -3,6 +3,17 @@ Components.utils.import("resource://scriptish/constants.js");
lazyImport(this, "resource://scriptish/prefmanager.js", ["Scriptish_prefRoot"]);
lazyImport(this, "resource://scriptish/logging.js", ["Scriptish_log"]);
+function showAlertNotification() {
+ if ("Fennec" == Services.appinfo.name) {
+ return showAlertNotification =
+ Cc["@mozilla.org/toaster-alerts-service;1"]
+ .getService(Ci.nsIAlertsService)
+ .showAlertNotification;
+ }
+
+ return Services.as.showAlertNotification;
+}
+
function Scriptish_notification(aMsg, aTitle, aIconURL, aCallback) {
if (!Scriptish_prefRoot.getValue("enabledNotifications.sliding"))
return Scriptish_log(aMsg);
@@ -20,7 +31,7 @@ function Scriptish_notification(aMsg, aTitle, aIconURL, aCallback) {
// if Growl is not installed or disabled on OSX, then use a fallback
try {
- Services.as.showAlertNotification.apply(null, args);
+ showAlertNotification().apply(null, args);
} catch (e) {
let win = Services.ww.openWindow(
null, 'chrome://global/content/alerts/alert.xul',
@@ -1,4 +1,3 @@
-
var EXPORTED_SYMBOLS = ["Scriptish_popupNotification"];
Components.utils.import("resource://gre/modules/PopupNotifications.jsm");
Components.utils.import("resource://scriptish/constants.js");
@@ -10,8 +9,9 @@ function Scriptish_popupNotification(details) {
if (!Scriptish_prefRoot.getValue("enabledNotifications.popup"))
return Scriptish_log(details.message);
- timeout(function() {
- var win = Scriptish.getMostRecentWindow();
+ var win = Scriptish.getMostRecentWindow();
+ if (win.PopupNotifications) {
+ timeout(function() {
win.PopupNotifications.show(
win.gBrowser.selectedBrowser,
details.id,
@@ -27,5 +27,10 @@ function Scriptish_popupNotification(details) {
null /* secondary action */,
details.options
);
- });
+ });
+
+ return true;
+ }
+
+ return false;
};

0 comments on commit 40fd4f8

Please sign in to comment.