-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (38 loc) · 1.56 KB
/
index.js
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
/* vim: set expandtab ts=4 sw=4: */
var debug = false;
var {Cc, Ci} = require("chrome");
var nonMobilePattern = new RegExp("^http://w*\.?theregister");
var httpRequestObserver =
{
observe: function(subject, topic, data)
{
var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
url = subject.URI.spec;
var res = nonMobilePattern.test(url);
if (res) {
if (debug)
console.log("non-mobile detected...redirecting to mobile");
var ioService = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
var newUri = url.replace(/http:\/\/w*.?theregister.co.uk/,
"http://m.theregister.co.uk");
httpChannel.redirectTo(ioService.newURI(newUri, null, null));
}
}
};
var observerService = Cc["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService);
exports.main = function(options, callbacks) {
if (debug)
console.log("Starting up register mobilizer due to " +
options.loadReason);
observerService.addObserver(httpRequestObserver, "http-on-modify-request",
false);
// observerService.addObserver(httpRequestObserver, "http-on-opening-request", false);
}
exports.onUnload = function(reason) {
if (debug)
console.log("Unloading register mobilizer due to " + reason);
observerService.removeObserver(httpRequestObserver,
"http-on-modify-request");
}