diff options
author | Matěj Cepl <mcepl@redhat.com> | 2010-06-09 21:53:42 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2010-06-09 21:53:42 +0200 |
commit | 9b41b8867d5eb3f78b6260e8ee719c81579102c9 (patch) | |
tree | f3b2ee664b4de1c563e5a03f1becc748bbad12a0 /lib/main.js | |
parent | e6c92c1ff7c2b465afd6076beabb692d9c3e4825 (diff) | |
download | bugzilla-triage-9b41b8867d5eb3f78b6260e8ee719c81579102c9.tar.gz |
* clean up to make jslint happy (abandoned let and replaced with var)
* cleaned up couple of crashes and missing stuff
Diffstat (limited to 'lib/main.js')
-rw-r--r-- | lib/main.js | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/lib/main.js b/lib/main.js index 1027d72..3364971 100644 --- a/lib/main.js +++ b/lib/main.js @@ -21,21 +21,18 @@ const JSONURL = "http://matej.ceplovi.cz/progs/data/RH_Data-packages.json"; var myStorage = require("simple-storage"); var config = {}; -config.matches = [ - "https://bugzilla.redhat.com/show_bug.cgi", - "https://bugzilla.mozilla.org/show_bug.cgi" -]; function initialize(callback) { util.loadJSON(JSONURL, function(parsedData) { config.gJSONData = parsedData; - // Get card translation table + var keys = "", key = ""; for (key in config.gJSONData) { keys += key + " "; } console.log("loaded JSON object keys: " + keys); + // Get card translation table if ("PCIIDsURL" in config.gJSONData.configData) { util.loadJSON(config.gJSONData.configData.PCIIDsURL, function(response) { config.PCI_ID_Array = response; @@ -50,37 +47,39 @@ function initialize(callback) { } -function isOurPage(window, bugzillaPageModLocation) { +// TODO: sometime in the future we should include +// also skip-process.js functionality and these URLs +// "https://bugzilla.redhat.com/process_bug.cgi", +// "https://bugzilla.redhat.com/post_bug.cgi", +// "https://bugzilla.mozilla.org/post_bug.cgi", +// "https://bugzilla.mozilla.org/process_bug.cgi" +function isOurPage(window, matchingURLs) { if ("window" in window) { window = window.window; } + var url = window.location.href; - if (window.location.protocol == "https:") { - // like ["name1": "url1", "name2":"url2"] - // FIXME the real name of bugzillaPageModLocation array - for (var loc in bugzillaPageModLocation) { - if (bugzillaPageModLocation[loc].test(window.location.href)) { - return true; - } - } - } - // we haven't found a conforming bugzilla - return false; + // like ["regexp-url1", "regexp-url2"] + return matchingURLs.some(function (element,i,a) { + return new RegExp(element).test(url); + }); } exports.main = function main(options, callbacks) { initialize(function (config) { browser.whenContentLoaded( function(window) { - if (isOurPage(window)) { + var doc = window.document; + if (isOurPage(window, config.gJSONData.configData.matches)) { + console.log("dump config:\n" + config); var curPage = {}; - var mycallback = function(doc) { - if (config.gJSONData.configData.objectStyle = "RH") { - curPage = new require("rhbzpage").RHBugzillaPage(doc, config); - } else if (config.gJSONData.configData.objectStyle = "MoFo") { - curPage = new require("mozillabzpage").MozillaBugzilla(doc, config); - } - }; + if (config.gJSONData.configData.objectStyle = "RH") { + curPage = new require("rhbzpage").RHBugzillaPage(doc, config); + } else if (config.gJSONData.configData.objectStyle = "MoFo") { + curPage = new require("mozillabzpage").MozillaBugzilla(doc, config); + } + } else { + console.log("Not our page: " + window.location.href); } }); }); |