aboutsummaryrefslogtreecommitdiffstats
path: root/lib/main.js
blob: ac2fd04f86c2c9f40099390d82770da165e07fde (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*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");

// FIXME this apparently is not good, properties of the object
// itself must be set, not variable referring to it 
var myStorage = require("simple-storage").storage;
// FIXME we should follow private browsing state
/*
simpleStorage.storage.history = [];
var privateBrowsing = require("private-browsing");
if (!privateBrowsing.active) {
  var url = getSelectedTabURL();
  simpleStorage.storage.history.push(url);
}

*/

var TriagedDistro = 13;
var NumberOfFrames = 7;
var XMLRPCurl = "https://bugzilla.redhat.com/xmlrpc.cgi";
var bugURL = "https://bugzilla.redhat.com/show_bug.cgi?id=";

// ==============================================================
// https://wiki.mozilla.org/Labs/Jetpack/JEP/24
var manifest = {
    settings : [
            {
                name : "BZpassword",
                type : "password",
                label : "Bugzilla password"
            },
            {
                name : "JSONURL",
                type : "text",
                label : "Configuration file URL",
                "default" : "http://mcepl.fedorapeople.org/scripts/BugZappers_data.json"
            },
            {
                name : "enabledPacks",
                type : "text",
                label : "comment packs which should be enabled",
                "default" : ""
            }
    ]
};
jetpack.future.import("storage.settings");


// TODO we should have an array SpecialFlags instead of multiple Boolean
// variables
var logSubmits = false;
var chipIDsGroupings = [];
var AddrArray = [];
var topRow = {};
var bottomRow = {};

// /////////////////////////////////////////////////////////////////////////////

function doReplace(window) {
    for (var node in require("text-node").iterator(window.document.body)) {
        var origText = node.textContent;
        var newText = origText.replace("friend", "acquaintance", "g");
        newText = newText.replace("Friend", "Acquaintance", "g");
        if (newText != origText) {
            node.textContent = newText;
        }
    }
}

////////////////////////////////////////////////////////////////////////////////
let config = {};
config.matches = [
    "https://bugzilla.redhat.com/show_bug.cgi",
    "https://bugzilla.mozilla.org/show_bug.cgi"
];
util.loadJSON(jetpack.storage.settings.JSONURL, function(parsedData) {
    config.gJSONData = parsedData;

    // Get card translation table
    let keys = "";
    for (let key in config.gJSONData) {
        keys += key + " ";
    }
    console.log("keys = " + keys);
    
    if ("PCIIDsURL" in config.gJSONData.configData) {
        util.loadJSON(config.gJSONData.configData.PCIIDsURL, function(response) {
            config.PCI_ID_Array = response;
        });
    }

    if (!myStorage.logs) {
        console.log("No store for logs defined!");
        myStorage.logs = {};
    }

    config.logger = new logger.Logger(myStorage.logs,
        config.gJSONData.constantData.bugzillalabelAbbreviations);
    
    let callback = function(doc) {
        if (config.gJSONData.configData.objectStyle = "RH") {
            let curPage = new RHBugzillaPage(doc);
        } else if (config.gJSONData.configData.objectStyle = "MoFo") {
            let curPage = new MozillaBugzilla(doc);
        }
    };

    jetpack.pageMods.add(callback, config);
}, this);

////////////////////////////////////////////////////////////////

// FIXME What are the real values of options and callbacks parameters?
exports.main = function main(options, callbacks) {
    require("tab-browser").whenContentLoaded(
        function(window) {
            if (window.location.protocol == "http:" &&
            // options.matches
            window.location.host.match(/facebook.com$/))
                require("persistent-page-mod").register(window, doReplace);
        }
    );
};s