home *** CD-ROM | disk | FTP | other *** search
Wrap
var videosurf_enhanced_enabled_sites_cache = {}; var VS_VID_REGS = []; var VS_CACHED_RELATED_VIDEOS = []; var VS_LOCAL_IMAGES = []; var VideoSurfEnhancer = { prefManager: null, getPrefManager: function(prefix) { if(!prefix) { prefix = "extensions.videosurf_enhanced."; } pm = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch).getBranch(prefix); return pm; }, //getPrefManager getPref: function(name, prefix) { var pref = VideoSurfEnhancer.getPrefManager(prefix); var prefType=pref.getPrefType(name); if (prefType==pref.PREF_INVALID) { return null; } switch (prefType) { case pref.PREF_STRING: return pref.getCharPref(name); case pref.PREF_BOOL: return pref.getBoolPref(name); case pref.PREF_INT: return pref.getIntPref(name); } }, //getPref setPref: function(name, value, prefix) { var pref = VideoSurfEnhancer.getPrefManager(prefix); var prefType=typeof(value); switch (prefType) { case "string": case "boolean": break; case "number": if (value % 1 != 0) { throw new Error("Cannot set preference to non integral number"); } break; default: throw new Error("Cannot set preference with datatype: " + prefType); } // set new value using correct method switch (prefType) { case "string": pref.setCharPref(name, value); break; case "boolean": pref.setBoolPref(name, value); break; case "number": pref.setIntPref(name, Math.floor(value)); break; } videosurf_enhanced_enabled_sites_cache = {} //Bust the cache when preferences change to be safe }, //setPref getUrlContents: function(aUrl){ var ioService=Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); var scriptableStream=Components .classes["@mozilla.org/scriptableinputstream;1"] .getService(Components.interfaces.nsIScriptableInputStream); var channel=ioService.newChannel(aUrl, null, null); var input=channel.open(); scriptableStream.init(input); var str=scriptableStream.read(input.available()); scriptableStream.close(); input.close(); return str; }, apiLeakCheck: function(allowedCaller) { var stack=Components.stack; var leaked=false; do { if (2==stack.language) { if ('chrome'!=stack.filename.substr(0, 6) && allowedCaller!=stack.filename ) { leaked=true; break; } } stack=stack.caller; } while (stack); return leaked; }, hitch: function(obj, meth) { if (!obj[meth]) { throw "method '" + meth + "' does not exist on object '" + obj + "'"; } var hitchCaller=Components.stack.caller.filename; var staticArgs = Array.prototype.splice.call(arguments, 2, arguments.length); return function() { if (VideoSurfEnhancer.apiLeakCheck(hitchCaller)) { return; } // make a copy of staticArgs (don't modify it because it gets reused for // every invocation). var args = staticArgs.concat(); // add all the new arguments for (var i = 0; i < arguments.length; i++) { args.push(arguments[i]); } // invoke the original function with the correct this obj and the combined // list of static and dynamic arguments. return obj[meth].apply(obj, args); }; }, addStyle: function(doc, css) { var head, style; head = doc.getElementsByTagName('head')[0]; if(!head) { return; } style = doc.createElement('style'); style.type = 'text/css'; style.innerHTML = css; head.appendChild(style); }, injectScript: function(script, unsafeContentWin) { if (unsafeContentWin.wrappedJSObject) unsafeContentWin=unsafeContentWin.wrappedJSObject; var unsafeLoc=new XPCNativeWrapper(unsafeContentWin, "location").location; var url=new XPCNativeWrapper(unsafeLoc, "href").href; var sandbox, script, logger, xmlhttpRequester; var safeWin=new XPCNativeWrapper(unsafeContentWin); sandbox=new Components.utils.Sandbox(safeWin); xmlhttpRequester=new vs_xmlhttpRequester( unsafeContentWin, window//appSvc.hiddenDOMWindow ); sandbox.window=safeWin; sandbox.document=sandbox.window.document; sandbox.unsafeWindow=unsafeContentWin; sandbox.VS_VID_REGS = VS_VID_REGS; sandbox.VS_CACHED_RELATED_VIDEOS = VS_CACHED_RELATED_VIDEOS; sandbox.VS_LOCAL_IMAGES = VS_LOCAL_IMAGES; sandbox.VS_getPref = VideoSurfEnhancer.getPref; sandbox.VS_setPref = VideoSurfEnhancer.setPref; sandbox.VS_getUrlContents = VideoSurfEnhancer.getUrlContents; sandbox.VS_gBrowser = gBrowser; sandbox.VS_addStyle=function(css) { VideoSurfEnhancer.addStyle(sandbox.document, css) }; sandbox.VS_xmlhttpRequest=VideoSurfEnhancer.hitch( xmlhttpRequester, "contentStartRequest" ); sandbox.__proto__=sandbox.window; sandbox.VS_isVideoPageUrl = VideoSurfEnhancer.isVideoPageUrl; try { this.evalInSandbox( "(function(){"+script+"})()", url, sandbox); } catch (e) { var e2=new Error(typeof e=="string" ? e : e.message); e2.fileName=script.filename; e2.lineNumber=0; //GM_logError(e2); alert(e2); } return sandbox; }, evalInSandbox: function(code, codebase, sandbox) { if (Components.utils && Components.utils.Sandbox) { // DP beta+ Components.utils.evalInSandbox(code, sandbox); } else if (Components.utils && Components.utils.evalInSandbox) { // DP alphas Components.utils.evalInSandbox(code, codebase, sandbox); } else if (Sandbox) { // 1.0.x evalInSandbox(code, sandbox, codebase); } else { throw new Error("Could not create sandbox."); } }, getActiveSite: function(url) { if(!url) { var document = gBrowser.selectedBrowser.contentDocument; var url = document.location.href; } var activeSite = null; var enabled = false; var summaries_enabled = false; var related_enabled = false; if(videosurf_enhanced_enabled_sites_cache[url]) { return videosurf_enhanced_enabled_sites_cache[url]; //Use this so switching back and forth between tabs and refreshing pages has no cost } else { var activeSites = VideoSurfEnhancer.getPref("enabled_sites"); var activeSitesSummaries = VideoSurfEnhancer.getPref("search_sites_summaries_enabled"); var activeSitesRelated = VideoSurfEnhancer.getPref("search_sites_related_enabled"); var sites = VideoSurfEnhancer.getPref("sites_info").split(","); for(var i = 0 ; i < sites.length ; i++) { var site = sites[i].split("||"); var urlStructure = site[2]; var re = new RegExp(urlStructure); if(re.test(url)) { activeSite = sites[i]; enabled = VideoSurfEnhancer.checkListPresence(activeSites, site[0]); summaries_enabled = VideoSurfEnhancer.checkListPresence(activeSitesSummaries, site[0]); related_enabled = VideoSurfEnhancer.checkListPresence(activeSitesRelated, site[0]); break; } } videosurf_enhanced_enabled_sites_cache[url] = { "active_site" : activeSite, "slug" : activeSite ? activeSite.split("||")[0] : null, "site_enabled" : enabled, "summaries_enabled" : summaries_enabled, "related_enabled" : related_enabled, "is_generic_video_page" : url && VideoSurfEnhancer.isVideoPageUrl(url) && url.indexOf("videosurf.com/") == -1 }; return videosurf_enhanced_enabled_sites_cache[url]; } }, go: function(e) { if(e.originalTarget instanceof HTMLDocument && !e.originalTarget.VideoSurfEnhanced && !e.originalTarget.defaultView.frameElement) { var script = ""; var as = VideoSurfEnhancer.getActiveSite(e.target.location.href); var isVideoPage = as.is_generic_video_page && VideoSurfEnhancer.getPref("external_site_related_videos"); var isSpecialPage = (as['active_site'] != null && as['site_enabled']); VideoSurfEnhancer.setIconDisplay(); //var ConsSrv = Components.classes['@mozilla.org/consoleservice;1'].getService(Components.interfaces.nsIConsoleService); //ConsSrv.logStringMessage(e.originalTarget); if(isSpecialPage) { activeSite = as['active_site']; if(activeSite == null) { activeSite = "embedded_video_summaries||||||"; //Yea yea, this is messy } script += "VS_ACTIVE_SITE = '" + activeSite + "';"; script += "VS_ACTIVE_SITE_ENABLED = " + as['site_enabled'] + ";"; script += "VS_ACTIVE_SITE_SUMMARIES_ENABLED = " + as['summaries_enabled'] + ";"; script += "VS_ACTIVE_SITE_RELATED_ENABLED = " + as['related_enabled'] + ";"; } script += "VS_IS_VIDEO_PAGE = " + isVideoPage + ";"; script += "VS_IS_SPECIAL_PAGE = " + isSpecialPage + ";"; if(isVideoPage || isSpecialPage) { script += VideoSurfEnhancer.getUrlContents('chrome://videosurf_enhanced/content/jquery-1.3.2.min.js'); script += VideoSurfEnhancer.getUrlContents('chrome://videosurf_enhanced/content/video_summary.js'); script += VideoSurfEnhancer.getUrlContents('chrome://videosurf_enhanced/content/go.js'); //Do most of the work in here so we can develop quickly without restarting FF } VideoSurfEnhancer.injectScript(script, e.target.defaultView); e.originalTarget.VideoSurfEnhanced = true; } }, isVideoPageUrl: function(urlToValidate) { url = VideoSurfEnhancer.cleanRedirectURL(urlToValidate.toLowerCase()); var parts = VideoSurfEnhancer.parse_url(url); try { var host = VideoSurfEnhancer.explode('.', parts.host.replace(/\.go\./, 'go.')); var p = host.length; for(var i = p - 2; i >= 0 && p[i] != 'www'; i--) { if(VS_VID_REGS[host[i]]) { for(var j = 0; j < VS_VID_REGS[host[i]]['expressions'].length; j++) { if(VS_VID_REGS[host[i]]['expressions'][j]['regexp'].test(url)) { return true; } } } } } catch(e) {} return false; }, cleanRedirectURL: function(urlString) { if(VideoSurfEnhancer.substr_count(urlString, 'http') > 1) { var url = VideoSurfEnhancer.explode('http', urlString); var knownRedirectors = [ 'google', 'yahoo' ]; for(var index in knownRedirectors) { if(VideoSurfEnhancer.substr_count(url[1], knownRedirectors[index]) > 0) { return 'http' + VideoSurfEnhancer.urldecode(url[2]); } } } return urlString; }, parse_url: function(str, component) { return {host:VideoSurfEnhancer.explode('/', str)[2]}; }, substr_count: function(haystack, needle, offset, length) { // Returns the number of times a substring occurs in the string // // version: 909.322 // discuss at: http://phpjs.org/functions/substr_count // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + bugfixed by: Onno Marsman // * example 1: substr_count('Kevin van Zonneveld', 'e'); // * returns 1: 3 // * example 2: substr_count('Kevin van Zonneveld', 'K', 1); // * returns 2: 0 // * example 3: substr_count('Kevin van Zonneveld', 'Z', 0, 10); // * returns 3: false var pos = 0, cnt = 0; haystack += ''; needle += ''; if (isNaN(offset)) {offset = 0;} if (isNaN(length)) {length = 0;} offset--; while ((offset = haystack.indexOf(needle, offset+1)) != -1){ if (length > 0 && (offset+needle.length) > length){ return false; } else{ cnt++; } } return cnt; }, explode: function(delimiter, string, limit) { return string.split(delimiter); }, urldecode: function(str) { // Decodes URL-encoded string // // version: 909.322 // discuss at: http://phpjs.org/functions/urldecode // + original by: Philip Peterson // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + input by: AJ // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + improved by: Brett Zamir (http://brett-zamir.me) // + input by: travc // + input by: Brett Zamir (http://brett-zamir.me) // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + improved by: Lars Fischer // + input by: Ratheous // + improved by: Orlando // % note 1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/ // * example 1: urldecode('Kevin+van+Zonneveld%21'); // * returns 1: 'Kevin van Zonneveld!' // * example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F'); // * returns 2: 'http://kevin.vanzonneveld.net/' // * example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'); // * returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a' var hash_map = {}, ret = str.toString(), unicodeStr='', hexEscStr=''; var replacer = function (search, replace, str) { var tmp_arr = []; tmp_arr = str.split(search); return tmp_arr.join(replace); }; // The hash_map is identical to the one in urlencode. hash_map["'"] = '%27'; hash_map['('] = '%28'; hash_map[')'] = '%29'; hash_map['*'] = '%2A'; hash_map['~'] = '%7E'; hash_map['!'] = '%21'; hash_map['%20'] = '+'; hash_map['\u00DC'] = '%DC'; hash_map['\u00FC'] = '%FC'; hash_map['\u00C4'] = '%D4'; hash_map['\u00E4'] = '%E4'; hash_map['\u00D6'] = '%D6'; hash_map['\u00F6'] = '%F6'; hash_map['\u00DF'] = '%DF'; hash_map['\u20AC'] = '%80'; hash_map['\u0081'] = '%81'; hash_map['\u201A'] = '%82'; hash_map['\u0192'] = '%83'; hash_map['\u201E'] = '%84'; hash_map['\u2026'] = '%85'; hash_map['\u2020'] = '%86'; hash_map['\u2021'] = '%87'; hash_map['\u02C6'] = '%88'; hash_map['\u2030'] = '%89'; hash_map['\u0160'] = '%8A'; hash_map['\u2039'] = '%8B'; hash_map['\u0152'] = '%8C'; hash_map['\u008D'] = '%8D'; hash_map['\u017D'] = '%8E'; hash_map['\u008F'] = '%8F'; hash_map['\u0090'] = '%90'; hash_map['\u2018'] = '%91'; hash_map['\u2019'] = '%92'; hash_map['\u201C'] = '%93'; hash_map['\u201D'] = '%94'; hash_map['\u2022'] = '%95'; hash_map['\u2013'] = '%96'; hash_map['\u2014'] = '%97'; hash_map['\u02DC'] = '%98'; hash_map['\u2122'] = '%99'; hash_map['\u0161'] = '%9A'; hash_map['\u203A'] = '%9B'; hash_map['\u0153'] = '%9C'; hash_map['\u009D'] = '%9D'; hash_map['\u017E'] = '%9E'; hash_map['\u0178'] = '%9F'; hash_map['\u00C6'] = '%C3%86'; hash_map['\u00D8'] = '%C3%98'; hash_map['\u00C5'] = '%C3%85'; for (unicodeStr in hash_map) { hexEscStr = hash_map[unicodeStr]; // Switch order when decoding ret = replacer(hexEscStr, unicodeStr, ret); // Custom replace. No regexing } // End with decodeURIComponent, which most resembles PHP's encoding functions ret = decodeURIComponent(ret); return ret; }, convertImgToDataUrl: function(imagePath) { if(!imagePath) { return null; } try{ var ioserv = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService); var channel = ioserv.newChannel(imagePath, 0, null); var stream = channel.open(); if(channel instanceof Components.interfaces.nsIHttpChannel && channel.responseStatus != 200) { return null; } var bstream = Components.classes["@mozilla.org/binaryinputstream;1"].createInstance(Components.interfaces.nsIBinaryInputStream); bstream.setInputStream(stream); var size = 0; var file_data = ""; while(size = bstream.available()) { file_data += bstream.readBytes(size); } var data = btoa(file_data); return "data:image;base64," + data; } catch(e) { } return null; }, setIconDisplay: function() { var as = VideoSurfEnhancer.getActiveSite(); var enhanceable = (as != null && (as['active_site'] != null || as.is_generic_video_page)) ? true : false; var disabled = (as != null && as['active_site'] != null && !as['site_enabled']) ? true : false; var icon = document.getElementById("videosurf_enhanced-status-bar-icon"); icon.className = "statusbarpanel-iconic"; icon.setAttribute("src", "chrome://videosurf_enhanced/content/images/favicon_16.gif"); if(!enhanceable) { icon.className += " not-supported "; icon.setAttribute("src", "chrome://videosurf_enhanced/content/images/favicon_16_desaturated.gif"); } if(disabled) { icon.className += " disabled "; } if(VideoSurfEnhancer.getPref("hide_status_bar_icon")) { icon.className = " hidden "; } }, openMorePreferences: function() { window.openDialog("chrome://videosurf_enhanced/content/options.xul", "videosurf_enhanced-prefs", "centerscreen,chrome,modal,resizable"); }, toggleExtensionEnabled: function() { var enabled_sites = VideoSurfEnhancer.getPref('enabled_sites'); var as = VideoSurfEnhancer.getActiveSite(); VideoSurfEnhancer.setPref("enabled_sites", VideoSurfEnhancer.toggleListPresence(enabled_sites, as['slug'])); VideoSurfEnhancer.setIconDisplay(); }, toggleSummariesEnabled: function() { var summaries_enabled = VideoSurfEnhancer.getPref('search_sites_summaries_enabled'); var as = VideoSurfEnhancer.getActiveSite(); VideoSurfEnhancer.setPref("search_sites_summaries_enabled", VideoSurfEnhancer.toggleListPresence(summaries_enabled, as['slug'])); VideoSurfEnhancer.setIconDisplay(); }, toggleRelatedEnabled: function() { var related_enabled = VideoSurfEnhancer.getPref('search_sites_related_enabled'); var as = VideoSurfEnhancer.getActiveSite(); VideoSurfEnhancer.setPref("search_sites_related_enabled", VideoSurfEnhancer.toggleListPresence(related_enabled, as['slug'])); VideoSurfEnhancer.setIconDisplay(); }, toggleRelatedVideoTabEnabled: function() { var related_tab_enabled = VideoSurfEnhancer.getPref('external_site_related_videos'); VideoSurfEnhancer.setPref("external_site_related_videos", !related_tab_enabled); VideoSurfEnhancer.setIconDisplay(); }, toggleListPresence: function(list, s) { //Adds or removes s from the comma separated list var newArr = []; var arr = list.split(","); var found = false; for(i = 0 ; i < arr.length ; i++) { if(arr[i] == s) { found = true; } else { if(arr[i].length > 0) { newArr[newArr.length] = arr[i]; } } } if(!found) { newArr[newArr.length] = s; } return newArr.join(","); }, checkListPresence: function(list, s) { var arr = list.split(","); var found = false; for(i = 0 ; i < arr.length ; i++) { if(arr[i] == s) { found = true; break; } } return found; }, updateContextMenuState: function() { //It seems setAttribute is necessary here... just doing ().checked = true does not work var summaries_option = document.getElementById("videosurf_enhanced-context-menu-addsummaries"); var related_option = document.getElementById("videosurf_enhanced-context-menu-addrelated"); var enabled_option = document.getElementById("videosurf_enhanced-context-menu-enabled"); var not_supported_option = document.getElementById("videosurf_enhanced-context-menu-not-supported"); var generic_video_option = document.getElementById("videosurf_enhanced-context-menu-generic-video"); summaries_option.setAttribute("checked", "true"); related_option.setAttribute("checked", "true"); related_option.className = ""; var as = VideoSurfEnhancer.getActiveSite(); if(as && as['slug'] != null) { enabled_option.setAttribute("label", "Enable for "+as['active_site'].split("||")[1]+""); enabled_option.setAttribute("checked", as['site_enabled'] ? "true" : "false"); summaries_option.setAttribute("checked", as['summaries_enabled'] ? "true" : "false"); related_option.setAttribute("checked", as['related_enabled'] ? "true" : "false"); summaries_option.setAttribute("disabled", as['site_enabled'] ? "false" : "true"); related_option.setAttribute("disabled", as['site_enabled'] ? "false" : "true"); not_supported_option.className = "hidden"; not_supported_option.setAttribute("disabled", "true"); document.getElementById("videosurf_enhanced-context-menu-separator-2").className = "visible"; enabled_option.className = "visible"; summaries_option.className = "visible"; related_option.className = "visible"; if(!VideoSurfEnhancer.checkListPresence(VideoSurfEnhancer.getPref("sites_summaries_supported"), as['slug'])) { //summaries_option.className = "hidden"; summaries_option.setAttribute("checked", "false"); summaries_option.setAttribute("disabled", "true"); } if(!VideoSurfEnhancer.checkListPresence(VideoSurfEnhancer.getPref("sites_related_supported"), as['slug'])) { //related_option.className = "hidden"; related_option.setAttribute("checked", "false"); related_option.setAttribute("disabled", "true"); } } else { if(!as.is_generic_video_page) { not_supported_option.className = "visible"; not_supported_option.setAttribute("disabled", "true"); } document.getElementById("videosurf_enhanced-context-menu-separator-2").className = "hidden"; enabled_option.className = "hidden"; summaries_option.className = "hidden"; related_option.className = "hidden"; } if(as.is_generic_video_page) { not_supported_option.className = "hidden"; generic_video_option.setAttribute("checked", VideoSurfEnhancer.getPref("external_site_related_videos")); generic_video_option.className = "visible"; } else { generic_video_option.className = "hidden"; } }, load: function() { if(gBrowser && !gBrowser.VideoSurfEnhanced) { gBrowser.addEventListener("DOMContentLoaded", VideoSurfEnhancer.go, true); gBrowser.tabContainer.addEventListener("TabSelect", VideoSurfEnhancer.setIconDisplay, false); var gExtensionManager = Components.classes["@mozilla.org/extensions/manager;1"].getService(Components.interfaces.nsIExtensionManager); var current = gExtensionManager.getItemForID("videosurf_enhanced@videosurf.com").version; VideoSurfEnhancer.log('Current Version: ' + VideoSurfEnhancer.getPref("first_run_version")); VideoSurfEnhancer.log('New Version: ' + current); if(VideoSurfEnhancer.getPref("first_run_version") != current) { VideoSurfEnhancer.log('Updating Preferences'); //Enabled any new sites that have been added VideoSurfEnhancer.updatePreferences(parseFloat(VideoSurfEnhancer.getPref("first_run_version"))); VideoSurfEnhancer.log('Setting Timeout'); //When FF remembers your previous tabs, this timeout is required to make this work. Otherwise the tab never opens for some odd reason. setTimeout(function() { gBrowser.selectedTab = gBrowser.addTab("http://www.videosurf.com/videos-at-a-glance-"+current); //post-installation splash page }, 1000); VideoSurfEnhancer.log('Updating Current Version'); //Update running version to the current one VideoSurfEnhancer.setPref("first_run_version", current); } //Load, convert, and cache regular expressions var regularExpressionJSON = JSON.parse(VideoSurfEnhancer.getUrlContents("chrome://videosurf_enhanced/content/siteRegularExpressions.js")); for(var siteID in regularExpressionJSON) { for(var regularExpressionIndex in regularExpressionJSON[siteID]['expressions']) { regularExpressionJSON[siteID]['expressions'][regularExpressionIndex]['regexp'] = new RegExp( regularExpressionJSON[siteID]['expressions'][regularExpressionIndex]['regexp'].substr(1, regularExpressionJSON[siteID]['expressions'][regularExpressionIndex]['regexp'].length -2) ); } } VS_VID_REGS = regularExpressionJSON; //Load, convert, and cache images var imageFiles = { 'arrow-down' : 'chrome://videosurf_enhanced/content/images/related-images/arrow-down.png', 'arrow-left' : 'chrome://videosurf_enhanced/content/images/related-images/arrow-left.png', 'arrow-right' : 'chrome://videosurf_enhanced/content/images/related-images/arrow-right.png', 'arrow-up' : 'chrome://videosurf_enhanced/content/images/related-images/arrow-up.png', 'container-background' : 'chrome://videosurf_enhanced/content/images/related-images/container-background.png', 'container-header' : 'chrome://videosurf_enhanced/content/images/related-images/container-header.png', 'tab-closed' : 'chrome://videosurf_enhanced/content/images/related-images/tab-closed.png', 'tab-loading-feedback' : 'chrome://videosurf_enhanced/content/images/related-images/tab-loading-feedback.gif', 'tab-loading' : 'chrome://videosurf_enhanced/content/images/related-images/tab-loading.png', 'tab-open' : 'chrome://videosurf_enhanced/content/images/related-images/tab-open.png', }; for(var imageID in imageFiles) { VS_LOCAL_IMAGES[imageID] = VideoSurfEnhancer.convertImgToDataUrl(imageFiles[imageID]); } gBrowser.VideoSurfEnhanced = true; //make sure we only do this once, unnecessary? } }, //load updatePreferences: function(previousVersion) { //Do not do anything if the extension have not been installed VideoSurfEnhancer.log('Previous Version: ' + previousVersion); if(!previousVersion) { return; } //Check to see if user have changes summary settings var isDefaultSummaries = VideoSurfEnhancer.getPrefManager().prefHasUserValue('search_sites_summaries_enabled'); VideoSurfEnhancer.log(isDefaultSummaries); //Check to see if user has changed related settings var isDefaultRelated = VideoSurfEnhancer.getPrefManager().prefHasUserValue('search_sites_related_enabled'); VideoSurfEnhancer.log(isDefaultRelated); //New sites added in their corasponding versions var preferenceJSON = [ { version : .66, sites : [ { id : 'riot', summary : true, related : true } ] }, { version : .67, sites : [ { id : 'digg', summary : true, related : false }, { id : 'reddit', summary : true, related : false } ] }, { version : .68, sites : [ ] } ]; for(newVersion in preferenceJSON) { var currentVersion = preferenceJSON[newVersion]; VideoSurfEnhancer.log(previousVersion); VideoSurfEnhancer.log(currentVersion.version); if(currentVersion.version > previousVersion) { for(var newSite in currentVersion.sites) { var currentSite = currentVersion.sites[newSite]; if(isDefaultSummaries && currentSite.summary) { VideoSurfEnhancer.setPref("search_sites_summaries_enabled", VideoSurfEnhancer.toggleListPresence(VideoSurfEnhancer.getPref('search_sites_summaries_enabled'), currentSite.id)); } if(isDefaultRelated && currentSite.related) { VideoSurfEnhancer.setPref("search_sites_related_enabled", VideoSurfEnhancer.toggleListPresence(VideoSurfEnhancer.getPref('search_sites_related_enabled'), currentSite.id)); } } } } }, //updatePreferences unload: function() { window.removeEventListener('load', VideoSurfEnhancer.load, false); window.removeEventListener('unload', VideoSurfEnhancer.unload, false); gBrowser.removeEventListener("DOMContentLoaded", VideoSurfEnhancer.go, false); gBrowser.tabContainer.removeEventListener("TabSelect", VideoSurfEnhancer.setIconDisplay, false); }, //unload log: function(value) { return; var ConsSrv = Components.classes['@mozilla.org/consoleservice;1'].getService(Components.interfaces.nsIConsoleService); ConsSrv.logStringMessage(value); } //log } //VideoSurfEnhancer window.addEventListener('load', VideoSurfEnhancer.load, false); window.addEventListener('unload', VideoSurfEnhancer.unload, false);