Skip to content

Commit

Permalink
Merge pull request #6 from ciex/master
Browse files Browse the repository at this point in the history
Firefox support
  • Loading branch information
henrycatalinismith authored Nov 17, 2017
2 parents 3b04420 + 6f47347 commit 0069778
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/wikimobilizer.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
var Wikimobilizer = {

listen: function(event) {
var filter = { urls : ["<all_urls>"] };
event.addListener(this.redirect.bind(this), filter, ["blocking"]);
},

redirect: function(details) {
return {
redirectUrl: this.transformUrl(details.url)
};
var redirectUrl = this.transformUrl(details.url);
if (redirectUrl !== details.url) {
return {
redirectUrl: redirectUrl
};
} else {
return {};
}
},

transformUrl: function(url) {
Expand All @@ -22,7 +26,9 @@ var Wikimobilizer = {

};

if (typeof chrome !== 'undefined' && typeof chrome.webRequest !== 'undefined') {
if (typeof browser !== "undefined" && typeof browser.webRequest !== 'undefined') {
Wikimobilizer.listen(browser.webRequest.onBeforeRequest);
} else if (typeof chrome !== "undefined" && typeof chrome.webRequest !== 'undefined') {
Wikimobilizer.listen(chrome.webRequest.onBeforeRequest);
} else if (typeof module !== 'undefined') {
module.exports = Wikimobilizer;;
Expand Down
7 changes: 7 additions & 0 deletions test/wikimobilizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,12 @@ describe('Wikimobilizer', function() {

});

describe("#redirect", function() {
it('does only issue a redirect if the requested URL requires one', function () {
Wikimobilizer.redirect({url: "https://de.m.wikipedia.org/wiki/Irland"}).
should.be.an.Object.and.be.empty;
});
});

});

0 comments on commit 0069778

Please sign in to comment.