aboutsummaryrefslogblamecommitdiffstats
path: root/lib/main.js
blob: 30c5b814253b2774140af622ef562da010783b00 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
                                                                                                                                                                                                                   
                   

                                                     








                                                                                                              
             



                                                  
                                     
                                                                         
 
                
 



                                                 
 
 




                                                     

 






                                                    


                               
                                   
    



                                                     
 
 



                                                  
                                      

                                                                                  

                                                                     



             
/*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");
var JSONURL = "http://matej.ceplovi.cz/progs/data/RH_Data-packages.json";

var config = {};

var matches = [
    "https://bugzilla.redhat.com/show_bug.cgi.*",
    "https://bugzilla.mozilla.org/show_bug.cgi.*"
];


function initialize(callback) {
        util.loadJSON(JSONURL, function(parsedData) {
        config = {};
        callback(config);
    }, this);
}

// 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;
    
    // 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) {
            var doc = window.document;
            if (isOurPage(window, matches)) {
                var curPage = new require("rhbzpage").RHBugzillaPage(doc, config);
            } else {
                console.log("Not our page: " + window.location.href);
            }
        });
    });
};