From 630c87753e632f9885802d2f1c184b25075aa347 Mon Sep 17 00:00:00 2001
From: teramako
Date: Mon, 12 Jan 2009 05:28:01 +0000
Subject: new add
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@28312 d0d07461-0603-4401-acd4-de1884942a52
---
notifier/observer_nsIAlertService.js | 118 +++++++++++++++++++++++++++++++++++
1 file changed, 118 insertions(+)
create mode 100644 notifier/observer_nsIAlertService.js
(limited to 'notifier')
diff --git a/notifier/observer_nsIAlertService.js b/notifier/observer_nsIAlertService.js
new file mode 100644
index 0000000..0c13293
--- /dev/null
+++ b/notifier/observer_nsIAlertService.js
@@ -0,0 +1,118 @@
+var PLUGIN_INFO =
+
+ {NAME}
+ notification using nsIAlertService
+ nsIAlertServiceを使用したnotifier用通知プラグイン
+ teramako
+ 0.1
+ MPL 1.1/GPL 2.0/LGPL 2.1
+ 2.0pre
+ 2.0pre
+ ||
+ :js Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator).getMostRecentWindow("alert:alert").close()
+ ||<
+ ]]>
+;
+//}}}
+(function() {
+
+var notifier = liberator.plugins.notifier;
+if (!notifier) {
+ return;
+}
+
+var libly = notifier.libly;
+var $U = libly.$U;
+var logger = $U.getLogger('observer_alert');
+
+const alertService = Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
+const ICON_URL = "chrome://vimperator/skin/icon.png";
+var observer = {
+ observe: function(aSubject, aTopic, aData){
+ if(aTopic == "alertclickcallback" && aData){
+ liberator.open(aData, liberator.NEW_TAB);
+ }
+ }
+};
+function getAlertWindows(){
+ return Cc["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Ci.nsIWindowMediator)
+ .getXULWindowEnumerator("alert:alert");
+}
+function alertNotify(count, message){
+ alertService.showAlertNotification(
+ ICON_URL,
+ count + ': ' + message.title,
+ "",
+ message.link ? true : false,
+ message.link,
+ observer
+ );
+ (function(){
+ var fixed = false;
+ var winEnum = getAlertWindows();
+ var win;
+ while (winEnum.hasMoreElements()){
+ win = winEnum.getNext()
+ .QueryInterface(Ci.nsIXULWindow).docShell
+ .QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindow);
+ if (win.arguments[1] == count + ": " + message.title){
+ var box = win.document.getElementById('alertTextBox');
+ var t = box.firstChild;
+ if (box.lastChild.hasAttribute('clickable')){
+ t.style.cursor = "pointer";
+ t.style.color = "#1455D6";
+ t.style.textDecoration = "underline";
+ }
+ t.setAttribute('onclick',"onAlertClick();");
+ box.removeChild(box.lastChild);
+ box.appendChild($U.xmlToDom(new XMLList(
+ '
'+message.message+'
'),
+ document
+ ));
+ win.onAlertLoad();
+ fixed = true;
+ }
+ }
+ if (!fixed) setTimeout(arguments.callee,10);
+ })();
+}
+
+notifier.observer.register(notifier.Observer, {
+ initialize: function () {
+ this.count = 1;
+ },
+ update: function(message) {
+ alertNotify(this.count, message);
+ this.count++;
+ },
+});
+
+})();
+// vim: set fdm=marker sw=4 ts=4 sts=0 et:
+
--
cgit v1.2.3