aboutsummaryrefslogtreecommitdiffstats
path: root/lib/main.js
blob: 1027d72100dad89cbf2436b3a002b43c1908e9f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*jslint onevar: false, browser: true, evil: true, laxbreak: true, undef: true, nomen: true, eqeqeq: true, bitwise: true, maxerr: 1000, immed: false, white: false, plusplus: false, regexp: false, undef: false */
/*global jetpack */
// Released under the MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php
//
// Links to read through
// http://ehsanakhgari.org/blog/2010-01-07/bugzilla-tweaks-enhanced
// http://hg.mozilla.org/users/ehsan.akhgari_gmail.com/extensions/file/tip/bugzillatweaks
// http://hg.mozilla.org/users/ehsan.akhgari_gmail.com/extensions/file/ecfa0f028b81/bugzillatweaks/lib/main.js
// http://hg.mozilla.org/users/avarma_mozilla.com/atul-packages/file/42ac1e99a107/packages\
//     /facebook-acquaintances/lib/main.js#l11
// http://ehsanakhgari.org/blog/2010-05-31/my-experience-jetpack-sdk#comment-1253
// 
"use strict";
var util = require("util");
var logger = require("logger");
var file = require("file");
var myStorage = require("simple-storage").storage;
var browser = require("tab-browser");
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);

    if ("PCIIDsURL" in config.gJSONData.configData) {
        util.loadJSON(config.gJSONData.configData.PCIIDsURL, function(response) {
            config.PCI_ID_Array = response;
        });
    }

    config.logger = new logger.Logger(myStorage.logs,
        config.gJSONData.constantData.bugzillalabelAbbreviations);
        
    callback(config);
}, this);

}

function isOurPage(window, bugzillaPageModLocation) {
    if ("window" in window) {
        window = window.window;
    }
    
    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;
}

exports.main = function main(options, callbacks) {
    initialize(function (config) {
        browser.whenContentLoaded(
        function(window) {
            if (isOurPage(window)) {
                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);
                    }
                };
            }
        });
    });
};