Skip to content
Permalink
Browse files

firefox -> webextension

  • Loading branch information
Ndragomirov committed Feb 15, 2017
1 parent 76a47af commit 2978fb2d9a22c87f14c2a87344f903b093a439a8
0 common/css/bootstrap.min.css 100755 → 100644
Empty file.
@@ -5,7 +5,7 @@
<link rel="stylesheet" href="../dist/popup.comb.css">
<script type="text/javascript" src="../dist/popup.comb.js"></script>
</head>
<body class="direction-__MSG_@@bidi_dir__">
<body class="direction-__MSG_@@bidi_dir__" style="width: 440px; height: 590px; overflow: hidden;">

<div id="context-menu">
<div class="context-row">__MSG_m24__</div>
@@ -108,23 +108,23 @@ <h2 class="header">__MSG_m24__</h2>
<div class="share">
<div data-placement="top" title="__MSG_m29__" class="js-tab social tip"
data-href="http://twitter.com/intent/tweet?text=Twitch%20Now%20is%20an%20awesome%20Chrome%20extension%20that%20alerts%20you%20when%20followed%20channels%20are%20online%20https://chrome.google.com/webstore/detail/twitch-now/nlmbdmpjmlijibeockamioakdpmhjnpk"
>
>
<i class="icon-twitter-squared"></i>
</div>
<div data-placement="top" title="__MSG_m30__" class="js-tab social tip"
data-href="https://www.facebook.com/sharer/sharer.php?u=https://chrome.google.com/webstore/detail/twitch-now/nlmbdmpjmlijibeockamioakdpmhjnpk"
>
>
<i class="icon-facebook-squared"></i>
</div>
<div data-placement="top" title="__MSG_m31__" class="js-tab social tip"
data-href="https://plus.google.com/share?url=https://chrome.google.com/webstore/detail/twitch-now/nlmbdmpjmlijibeockamioakdpmhjnpk"
>
>
<i class="icon-gplus-squared"></i>
</div>

<div data-placement="top" title="__MSG_m32__" class="js-tab social tip"
data-href="http://vk.com/share.php?url=https://chrome.google.com/webstore/detail/twitch-now/nlmbdmpjmlijibeockamioakdpmhjnpk"
>
>
<i class="icon-vkontakte"></i>
</div>

0 common/icons/128_1.png 100755 → 100644
Empty file.
0 common/icons/16_1.png 100755 → 100644
Empty file.
0 common/icons/19_2.png 100755 → 100644
Empty file.
0 common/icons/19_2_grey.png 100755 → 100644
Empty file.
0 common/icons/32_1.png 100755 → 100644
Empty file.
0 common/icons/38_2.png 100755 → 100644
Empty file.
0 common/icons/38_2_grey.png 100755 → 100644
Empty file.
0 common/img/camera-dark.png 100755 → 100644
Empty file.
0 common/img/camera.png 100755 → 100644
Empty file.
0 common/img/heart.svg 100755 → 100644
Empty file.
0 common/img/heartbox.svg 100755 → 100644
Empty file.
0 common/img/info.svg 100755 → 100644
Empty file.
0 common/img/joystick.svg 100755 → 100644
Empty file.
0 common/img/play-dark.png 100755 → 100644
Empty file.
0 common/img/play.png 100755 → 100644
Empty file.
0 common/img/refresh.svg 100755 → 100644
Empty file.
0 common/img/search.svg 100755 → 100644
Empty file.
0 common/img/settings.svg 100755 → 100644
Empty file.
0 common/img/star.svg 100755 → 100644
Empty file.
@@ -33,10 +33,6 @@
return OSName;
};

bgApp.growlNotificationsSupported = function (){
return utils.notifications.growlNotificationsSupported();
};

bgApp.richNotificationsSupported = function (){
return utils.notifications.richNotificationsSupported();
};
@@ -71,20 +67,6 @@
return c.get("channel").display_name;
});

if ( bgApp.growlNotificationsSupported() ) {

var opts = {
title : "Twitch Now",
text : streamTitles.join("\n"),
iconURL: defaultIcon
}

if ( streamTitles.length == 1 ) {
opts.data = streamsToShow[0].getStreamURL();
}
utils.notifications.create(opts);
}

if ( bgApp.richNotificationsSupported() ) {

var notificationId = _.uniqueId("TwitchNow.Notification.");
@@ -525,7 +507,7 @@
});

var UpdatableCollection = Backbone.Collection.extend({
auto : false,
auto : false, // auto updates every `timeout` interval
pagination : false,
timeout : 60 * 1000,
pageQuery : {
@@ -920,7 +902,7 @@

getStreamURL: function (type){
type = type || settings.get("openStreamIn").get("value");
if(type == "html5"){
if ( type == "html5" ) {
return "http://player.twitch.tv/?channel=" + this.get("channel").name + "&html5";
}
var links = {
@@ -1028,6 +1010,47 @@
}
});

var Hosts = StreamCollection.extend({
pagination: false,
auto : true,
timeout : 5 * 60 * 1000,
model : Stream,
initialize: function (){
var self = this;

twitchApi.on("authorize", function (){
self.update();
})

twitchApi.on("revoke", function (){
self.reset();
});

StreamCollection.prototype.initialize.call(this);
},
parse : function (res, callback){
console.log(res.hosts);
if ( !res || !res.hosts ) {
return callback(new Error("api"));
}
var streams = res.hosts.map(function (host){
return Object.assign(
{},
host.target,
{
host: _.pick(host, 'display_name', 'id', 'name')
}
);
})

callback(null, streams);
},
send : function (query, callback){
console.log("hosts", arguments);
twitchApi.send("hosts", {}, callback);
}
})

var FollowingStreams = StreamCollection.extend({
pagination: false,
auto : true,
@@ -1255,6 +1278,7 @@
var gameLobby = root.gameLobby = new GameLobby;
var gameVideos = root.gameVideos = new GameLobbyVideos;
var gameStreams = root.gameStreams = new GameLobbyStreams;
var hosts = root.hosts = new Hosts;

topstreams.update();
games.update();
@@ -1,9 +1,8 @@
(function (){
var root = this;
var that = {};
var isFirefox = !!root.require;
var localStorage = isFirefox ? require("sdk/simple-storage").storage : root.localStorage;
var EventEmitter = isFirefox ? require("./eventemitter.js") : root.EventEmitter;
var isFirefox = !!root.browser;
var _browser = isFirefox ? root.browser : chrome;

function noop(){
}
@@ -20,38 +19,19 @@
}

var request = function (opts, callback){
if ( root.require ) {
opts.method = opts.method.toLowerCase();
var Request = require("sdk/request").Request;
Request({
url : opts.url,
content : opts.data,
onComplete: function (response){
if ( response.status == 200 ) {
callback(null, JSON.parse(response.text));
} else {
callback(response.status);
}
var $ = root.jQuery;
$.ajax({
url : opts.url,
type: opts.method,
data: opts.data
})
.always(function (data, textStatus, jqXHR){
if ( textStatus == "success" ) {
callback(null, data);
} else {
callback(data);
}
})[opts.method]()
}

if ( root.jQuery ) {
console.log("using jquery", opts);
var $ = root.jQuery;
$.ajax({
url : opts.url,
type: opts.method,
data: opts.data
})
.always(function (data, textStatus, jqXHR){
if ( textStatus == "success" ) {
callback(null, data);
} else {
callback(data);
}
});
}
});
}

var Adapter = function (id, opts, flow){
@@ -76,51 +56,27 @@
var injectScript = '(' + this.injectScript.toString() + ')()';
var injectTo;

if ( isFirefox ) {
var pageMode = require("sdk/page-mod");

injectTo = this.redirect + "*";

console.log("\n\n\nInjecting\n\n\n");
pageMode.PageMod({
include : ["https://" + injectTo, "http://" + injectTo],
contentScript : injectScript,
contentScriptWhen: "ready",
attachTo : "top",
onAttach : function (worker){
console.log("\n\n\nattached to: " + worker.tab.url);
worker.port.on("OAUTH2", function (msg){
console.log("\n\nAuth2 data :", msg)
self.finalize(msg.value.params);
worker.tab.close();
});
}
});
} else {
injectTo = this.redirect;
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo){
if ( changeInfo.url && changeInfo.url.indexOf(injectTo) != -1 ) {
console.log("\nExecuting scripts");
chrome.tabs.executeScript(tabId, {code: injectScript});
}
})

chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse){
if ( msg.type == "OAUTH2" ) {
self.finalize(msg.value.params);
setTimeout(function (){
chrome.tabs.remove(sender.tab.id);
}, 100)
}
});
}
injectTo = this.redirect;
_browser.tabs.onUpdated.addListener(function (tabId, changeInfo){
if ( changeInfo.url && changeInfo.url.indexOf(injectTo) != -1 ) {
console.log("\nExecuting scripts");
_browser.tabs.executeScript(tabId, {code: injectScript});
}
})

_browser.runtime.onMessage.addListener(function (msg, sender, sendResponse){
if ( msg.type == "OAUTH2" ) {
self.finalize(msg.value.params);
setTimeout(function (){
_browser.tabs.remove(sender.tab.id);
}, 100)
}
});
}

Adapter.prototype.injectScript = function (){

console.log("\n\nInjecting\n\n");
var self = window.self;
var isFirefox = self && self.port && self.port.emit;

var sendMessage = function (msg){

@@ -129,11 +85,7 @@
type : "OAUTH2"
};

if ( isFirefox ) {
self.port.emit("OAUTH2", data);
} else {
chrome.runtime.sendMessage(data);
}
chrome.runtime.sendMessage(data);
}

var send = function (){
@@ -151,7 +103,7 @@

Adapter.prototype.syncGet = function (){
var self = this;
chrome.storage.sync.get(this.lsPath, function (item){
_browser.storage.sync.get(this.lsPath, function (item){
console.log("SYNC_GET", item);
if ( item[self.lsPath] ) {
self.set(JSON.parse(item[self.lsPath]), true);
@@ -161,7 +113,7 @@

Adapter.prototype.sync = function (){
var self = this;
chrome.storage.onChanged.addListener(function (changes, namespace){
_browser.storage.onChanged.addListener(function (changes, namespace){
if ( namespace === "sync" ) {
console.log("SYNC_CHANGED", changes);
if ( self.lsPath in changes ) {
@@ -191,14 +143,12 @@

console.log("set sync data", syncData);

chrome.storage.sync.set(syncData, function (){
_browser.storage.sync.set(syncData, function (){
console.log("SYNC_SET_DONE", arguments);
});
}

if ( !isFirefox ) {
this.trigger("OAUTH2_TOKEN", {value: this.getAccessToken()});
}
this.trigger("OAUTH2_TOKEN", {value: this.getAccessToken()});
}

Adapter.prototype.updateLocalStorage = function (){
@@ -300,16 +250,7 @@
}

Adapter.prototype.openTab = function (url){
if ( isFirefox ) {
var tabs = require('sdk/tabs');

tabs.open({
url: url
});

} else {
chrome.tabs.create({url: url});
}
_browser.tabs.create({url: url});
}

Adapter.prototype.setAccessToken = function (token){

0 comments on commit 2978fb2

Please sign in to comment.