?? joeyoverlay.js
字號:
// nsIStreamListener onStartRequest: function (aRequest, aContext) { this.file = Components.classes["@mozilla.org/file/directory_service;1"] .getService(Components.interfaces.nsIProperties) .get("TmpD", Components.interfaces.nsIFile); this.file.append("joeymedia.tmp"); this.file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0664); var fos = Components.classes["@mozilla.org/network/file-output-stream;1"] .createInstance(Components.interfaces.nsIFileOutputStream); fos.init(this.file, 0x02 | 0x08 | 0x20, 0644, 0); this.mstream = Components.classes["@mozilla.org/binaryoutputstream;1"].createInstance(Components.interfaces.nsIBinaryOutputStream); this.mstream.setOutputStream(fos); try { var http = aRequest.QueryInterface(Components.interfaces.nsIHttpChannel); this.mContentType = http.contentType; } catch (ex) { joeyDumpToConsole(ex); } }, onDataAvailable: function (aRequest, aContext, aStream, aSourceOffset, aLength) { var bis = Components.classes["@mozilla.org/binaryinputstream;1"] .createInstance(Components.interfaces.nsIBinaryInputStream); bis.setInputStream(aStream); var n=0; while(n<aLength) { var data = bis.readByteArray( bis.available() ); this.mstream.writeByteArray( data, data.length ); n += data.length; } }, onStopRequest: function (aRequest, aContext, aStatus) { if (Components.isSuccessCode(aStatus)) { this.mstream.close(); this.mCallbackFunc(this.mContentType, this.file); } else { // request failed this.mCallbackFunc(null, null, 0); } }, // nsIChannelEventSink onChannelRedirect: function (aOldChannel, aNewChannel, aFlags) { }, // nsIInterfaceRequestor getInterface: function (aIID) { try { return this.QueryInterface(aIID); } catch (e) {} }, // nsIProgressEventSink (not implementing will cause annoying exceptions) onProgress : function (aRequest, aContext, aProgress, aProgressMax) { g_joey_statusUpdateObject.tellStatus("download", aProgress, aProgressMax); }, onStatus : function (aRequest, aContext, aStatus, aStatusArg) { }, // nsIHttpEventSink (not implementing will cause annoying exceptions) onRedirect : function (aOldChannel, aNewChannel) { }, // we are faking an XPCOM interface, so we need to implement QI QueryInterface : function(aIID) { if (aIID.equals(Components.interfaces.nsISupports) || aIID.equals(Components.interfaces.nsIInterfaceRequestor) || aIID.equals(Components.interfaces.nsIChannelEventSink) || aIID.equals(Components.interfaces.nsIProgressEventSink) || aIID.equals(Components.interfaces.nsIHttpEventSink) || aIID.equals(Components.interfaces.nsIStreamListener)) return this; throw Components.results.NS_NOINTERFACE; }};function joey_selectedImage(){ var focusedWindow = document.commandDispatcher.focusedWindow; g_joey_title = focusedWindow.document.title; g_joey_url = focusedWindow.location.href; g_joey_isfile = true; // g_joey_data, g_joey_content_type // will be filled in when we have the image data. // the IO service var ioService = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); // create an nsIURI var uri = ioService.newURI(gImageSource, null, null); // get an listener var listener = new JoeyMediaFetcherStreamListener(getMediaCallback); // get a channel for that nsIURI var channel = ioService.newChannelFromURI(uri); channel.notificationCallbacks = listener; channel.asyncOpen(listener, null);}function loot_setttings(){ var joey = Components.classes["@mozilla.com/joey;1"] .createInstance(Components.interfaces.mocoJoey); joey.setLoginInfo();}function rev(str) { if (!str) return ''; var revstr=''; for (i=str.length-1;i>=0;i--){revstr+=str.charAt(i)} return revstr; }var httpscanner = { observe: function(subject,topic,data){ var response=subject.QueryInterface(Components.interfaces.nsIHttpChannel); var contentType=response.getResponseHeader('Content-Type'); function testContentType(types){ var isMediaFile = false; for(var i=types.length;i>=0;i--){ if(contentType.indexOf(types[i])>-1 || mediaLocation.indexOf('.'+types[i])>-1) isMediaFile = true; } return isMediaFile; } if(contentType.indexOf('video')>-1 || contentType.indexOf('audio')>-1 || contentType.indexOf('octet')>-1){ var mediaLocation = subject.QueryInterface(Components.interfaces.nsIChannel).URI; mediaLocation=mediaLocation.prePath+mediaLocation.path; if(testContentType(g_joey_mediaContentTypes)){ joeyDumpToConsole("media content found: "+ mediaLocation); document.getElementById("joeyMediaMenuItem").setAttribute("hidden","false"); g_joey_media_type = contentType; g_joey_media_url = mediaLocation; } } }}var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService); observerService.addObserver(httpscanner,"http-on-examine-response",false);function joey_uploadFoundMedia() // refactor with joey_selectedImage{ var focusedWindow = document.commandDispatcher.focusedWindow; g_joey_title = focusedWindow.document.title; g_joey_url = focusedWindow.location.href; g_joey_isfile = true; g_joey_content_type = g_joey_media_type; // g_joey_data, g_joey_content_type // will be filled in when we have the media data. // the IO service var ioService = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); // create an nsIURI var uri = ioService.newURI(g_joey_media_url, null, null); // get an listener var listener = new JoeyMediaFetcherStreamListener(getMediaCallback); // get a channel for that nsIURI var channel = ioService.newChannelFromURI(uri); channel.notificationCallbacks = listener; channel.asyncOpen(listener, null);}/* * This refreshes feed information in the menu. * The currentBrowser.feeds array is populated from the * joeyLinkAddedHandler. */function joeySetCurrentFeed(){ try { var currentFeedURI = g_joey_gBrowser.mCurrentBrowser.feeds; if(currentFeedURI ||currentFeedURI.length>0) { document.getElementById("joey_activeRSSLink").setAttribute("hidden","false"); } } catch(i) { document.getElementById("joey_activeRSSLink").setAttribute("hidden","true"); } }function joeyStartup(){ var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interfaces.nsIWindowMediator); gWin = wm.getMostRecentWindow("navigator:browser"); g_joey_gBrowser = gWin.gBrowser; g_joey_browserStatusHandler = new joeyBrowserStatusHandler(); g_joey_gBrowser.addProgressListener( g_joey_browserStatusHandler , Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT); var psvc = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefBranch); g_joey_statusUpdateObject = new JoeyStatusUpdateClass(); /* * Joey Event Listeners */ window.addEventListener("mousedown",joeyOnMouseDown,false); /* * First Run function.. */ try { if(psvc.getBoolPref("joey.firstRun")) { psvc.setBoolPref("joey.firstRun",false); joeyLaunchPreferences(); } } catch(i) { joeyDumpToConsole(i) } /* * Bundle object for local string access */ g_joey_bundleElement = document.getElementById("joey_properties"); // We can use now joeyString to get strings... }function joeyDumpToConsole(aMessage) { try { var psvc = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefBranch); if(psvc.getBoolPref("joey.enable_logging")) { var cs = Components.classes["@mozilla.org/consoleservice;1"] .getService(Components.interfaces.nsIConsoleService); cs.logStringMessage("joey: " + aMessage); } } catch (i) {}}/* * Prefs launcher */function joeyLaunchPreferences() { window.open("chrome://joey/content/joeyOptions.xul", "welcome", "chrome,resizable=yes");}function joeyBrowserStatusHandler() {}joeyBrowserStatusHandler.prototype = { QueryInterface : function(aIID) { if (aIID.equals(Components.interfaces.nsIWebProgressListener) || aIID.equals(Components.interfaces.nsIXULBrowserWindow) || aIID.equals(Components.interfaces.nsISupportsWeakReference) || aIID.equals(Components.interfaces.nsISupports)) { return this; } throw Components.results.NS_NOINTERFACE; }, init : function() { }, destroy : function() { }, onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus) { /* via state changes we notify our local startDocumentLoad and endDocumentLoad * Joey uses endDocumentLoad to do a little sniffing in the doc, check feeds, * check media items, and possibly more.. */ const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener; const nsIChannel = Components.interfaces.nsIChannel; if (aStateFlags & nsIWebProgressListener.STATE_START) { if (aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK && aRequest && aWebProgress.DOMWindow == content) this.startDocumentLoad(aRequest); } else if (aStateFlags & nsIWebProgressListener.STATE_STOP) { if (aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK) { if (aWebProgress.DOMWindow == content) { if (aRequest) this.endDocumentLoad(aRequest, aStatus); } } } }, onProgressChange : function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress) { }, onLocationChange : function(aWebProgress, aRequest, aLocation) { }, onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage) { }, startDocumentLoad : function(aRequest) { }, endDocumentLoad : function(aRequest, aStatus) { setTimeout(g_joeySelectorService.disable, 0); setTimeout(g_joeyFeedwatcher, 0); }, onSecurityChange : function(aWebProgress, aRequest, aState) { }, setJSStatus : function(status) { }, setJSDefaultStatus : function(status) { }, setDefaultStatus : function(status) { }, setOverLink : function(link, b) { }}function g_joeyFeedwatcher(){ // we need to tie into a way to purge via clear private data! var feedWatchLimit = 10; try { feedWatchLimit = psvc.getIntPref("joey.rss-watch-limit"); } catch(a) {} try { // this will change with Places. var feedLocation = g_joey_gBrowser.mCurrentBrowser.feeds[0].href; // make into a pref name. (slashes have to be removed) feedLocation = feedLocation.replace(/\//g, "s"); var psvc = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefBranch); var seen = 0; try { seen = psvc.getIntPref("joey.rss." + feedLocation + ".seen"); } catch(a) {} seen++; if (seen > feedWatchLimit) { joey_feed(); seen = 0; } psvc.setIntPref("joey.rss." + feedLocation + ".seen", seen); } catch(ignore) {}}/* * Joey Element Selection Service Singleton * ---------------------------------------- * This implementation is to be moved outside * this JS file. This uses the /contrib/uSummaryGenerator.js * This is the UI contextual function that allows and end-user * to pick an area and then the uSummaryGenerator service is * called so that we can wrap the generator XML info and * upload it to Joey!. */var sigmaCall = null;var omegaCall = null;var deltaCall = null;var g_joeySelectorService = { currentEvent :null, previousTargetElement:null, associatedDocument :null, enabled :false, currentElementLeft :null, currentElementTop :null, currentElementRight :null, currentElementBottom :null, timer :null, enable: function () { joeyDumpToConsole("g_joeySelectorService enable"); if (this.enabled == true) this.disable(); this.enabled = true; this.associatedDocument = g_joey_gBrowser.selectedBrowser.contentDocument; this.createBox(); var thisInstance = this; sigmaCall = function(e) { thisInstance.mouseMoveListener(e) };
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -