[Bbs2ch-cvs 208] [190] あぼーんの即時適用

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2007年 8月 6日 (月) 00:25:52 JST


Revision: 190
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=bbs2ch&view=rev&rev=190
Author:   flyson
Date:     2007-08-06 00:25:52 +0900 (Mon, 06 Aug 2007)

Log Message:
-----------
あぼーんの即時適用

Modified Paths:
--------------
    trunk/bbs2chreader/chrome/content/bbs2chreader/ff-overlay.js
    trunk/bbs2chreader/defaults/skin/Header.html

Added Paths:
-----------
    trunk/bbs2chreader/defaults/skin/abone.js

Modified: trunk/bbs2chreader/chrome/content/bbs2chreader/ff-overlay.js
===================================================================
--- trunk/bbs2chreader/chrome/content/bbs2chreader/ff-overlay.js	2007-08-05 14:29:01 UTC (rev 189)
+++ trunk/bbs2chreader/chrome/content/bbs2chreader/ff-overlay.js	2007-08-05 15:25:52 UTC (rev 190)
@@ -162,9 +162,48 @@
 };
 
 
+b2rBrowserOverlay.aboneEvent = {
+	start: function(){
+		var os = Components.classes["@mozilla.org/observer-service;1"]
+					.getService(Components.interfaces.nsIObserverService);
+		os.addObserver(b2rBrowserOverlay.aboneEvent, "b2r-abone-data-add", false);
+	},
 
+	stop: function(){
+		var os = Components.classes["@mozilla.org/observer-service;1"]
+					.getService(Components.interfaces.nsIObserverService);
+		os.removeObserver(b2rBrowserOverlay.aboneEvent, "b2r-abone-data-add", false);
+	},
 
+	observe: function(aSubject, aTopic, aData){
+		var aboneType;
+		switch(aTopic){
+			case "b2r-abone-data-add":
+				aboneType = aSubject.QueryInterface(Components.interfaces.nsISupportsPRInt32).data;
+				break;
+			default:
+				return;
+		}
+		for(var i = 0; i < gBrowser.mPanelContainer.childNodes.length; i++){
+			var currentURI = gBrowser.getBrowserAtIndex(i).currentURI;
+			if((currentURI.scheme=="http") && (currentURI.host=="127.0.0.1")){
+				var doc = gBrowser.getBrowserAtIndex(i).contentDocument;
+				var win = gBrowser.getBrowserAtIndex(i).contentWindow;
+				var sourceEvent = doc.createEvent("Events");
+				sourceEvent.initEvent(aData, false, false);
+				var event = document.createEvent('XULCommandEvents');
+				event.initCommandEvent("b2raboneadd", true, false, win, aboneType,
+										false, false, false, false, sourceEvent);
+				doc.dispatchEvent(event);
+			}
+		}
+	}
+}
+
+
 window.addEventListener("load",   b2rBrowserOverlay.contextMenu.start, false);
 window.addEventListener("unload", b2rBrowserOverlay.contextMenu.stop, false);
 window.addEventListener("load",   b2rBrowserOverlay.statusbar.start, false);
 window.addEventListener("unload", b2rBrowserOverlay.statusbar.stop, false);
+window.addEventListener("load",   b2rBrowserOverlay.aboneEvent.start, false);
+window.addEventListener("unload", b2rBrowserOverlay.aboneEvent.stop, false);
\ No newline at end of file

Modified: trunk/bbs2chreader/defaults/skin/Header.html
===================================================================
--- trunk/bbs2chreader/defaults/skin/Header.html	2007-08-05 14:29:01 UTC (rev 189)
+++ trunk/bbs2chreader/defaults/skin/Header.html	2007-08-05 15:25:52 UTC (rev 190)
@@ -14,9 +14,10 @@
 		}
 	</style>
 	<script type="text/javascript; version=1.7" src="<SKINPATH/>popup.js"></script>
+	<script type="text/javascript; version=1.7" src="<SKINPATH/>abone.js"></script>
 </head>
 
-<body onload="b2rPopup.startup()">
+<body onload="b2rPopup.startup(); b2rAboneHandler.startup()">
 
 
 <h1 id="h1Title"><THREADNAME/></h1>

Added: trunk/bbs2chreader/defaults/skin/abone.js
===================================================================
--- trunk/bbs2chreader/defaults/skin/abone.js	2007-08-05 14:29:01 UTC (rev 189)
+++ trunk/bbs2chreader/defaults/skin/abone.js	2007-08-05 15:25:52 UTC (rev 190)
@@ -0,0 +1,74 @@
+var b2rAboneHandler = {
+
+	startup: function(){
+		document.addEventListener("b2raboneadd", b2rAboneHandler, false);
+
+		this._aboneHTML = <>
+			<dt class="resHeader">
+				<span class="resNumber">XXX</span>
+				<span class="resName">ABONE</span>
+				[<span class="resMail">ABONE</span>]
+				Date:<span class="resDate">ABONE</span>
+				<span class="resID"><span class="id_<ID/>">ID:</span></span>
+				Be:<span class="resBeID"><BEID/></span>
+			</dt>
+			<dd class="resBody">ABONE</dd>
+		</>.toString();
+	},
+
+	handleEvent: function(aEvent){
+		var aboneWord = aEvent.sourceEvent.type;
+		switch(aEvent.detail){
+			case 0:    // Components.interfaces.b2rIAboneManager.ABONE_TYPE_NAME
+				var xpath = "descendant::span[@class='resName']";
+				for(let [index, node] in Iterator(b2rAboneHandler.xpathEvaluate(xpath))){
+					var textContent = node.textContent;
+					if(textContent.indexOf(aboneWord) != -1){
+						node.parentNode.parentNode.innerHTML = b2rAboneHandler._aboneHTML;
+					}
+				}
+				break;
+
+			case 1:    // Components.interfaces.b2rIAboneManager.ABONE_TYPE_MAIL
+				var xpath = "descendant::span[@class='resMail']";
+				for(let [index, node] in Iterator(b2rAboneHandler.xpathEvaluate(xpath))){
+					var textContent = node.textContent;
+					if(textContent.indexOf(aboneWord) != -1){
+						node.parentNode.parentNode.innerHTML = b2rAboneHandler._aboneHTML;
+					}
+				}
+				break;
+
+			case 2:    // Components.interfaces.b2rIAboneManager.ABONE_TYPE_ID
+				var xpath = "descendant::span[@class='resID']/span";
+				for(let [index, node] in Iterator(b2rAboneHandler.xpathEvaluate(xpath))){
+					var textContent = node.className.substring(3);
+					if(textContent.indexOf(aboneWord) != -1){
+						node.parentNode.parentNode.parentNode.innerHTML = b2rAboneHandler._aboneHTML;
+					}
+				}
+				break;
+
+			case 3:    // Components.interfaces.b2rIAboneManager.ABONE_TYPE_WORD
+				var xpath = "descendant::dd[@class='resBody']";
+				for(let [index, node] in Iterator(b2rAboneHandler.xpathEvaluate(xpath))){
+					var textContent = node.textContent;
+					if(textContent.indexOf(aboneWord) != -1){
+						node.parentNode.innerHTML = b2rAboneHandler._aboneHTML;
+					}
+				}
+				break;
+		}
+	},
+
+	xpathEvaluate: function(aXpath){
+		var result = new Array();
+		var xpathResult = document.evaluate(aXpath, document, null,
+				XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
+		for(let i=0; i<xpathResult.snapshotLength; i++){
+			var node = xpathResult.snapshotItem(i);
+			result.push(node);
+		}
+		return result;
+	}
+};
\ No newline at end of file




bbs2ch-cvs メーリングリストの案内
Back to archive index