Skip to content

Commit

Permalink
100% Compatible with Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan DEKHTIAR committed Sep 11, 2017
1 parent ff2105b commit 6ea1d70
Show file tree
Hide file tree
Showing 33 changed files with 421 additions and 1,245 deletions.
72 changes: 67 additions & 5 deletions app/background.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,74 @@
var debug = true;
var local = false;
var api_endpoint = null;

if (debug){
if (local){
api_endpoint = "https://local.feedcrunch.io:5000/";
}
else{
api_endpoint = "https://feedcrunch-api-dev.eu-gb.mybluemix.net/";
}
}
else{
api_endpoint = "https://feedcrunch-api-prod.eu-gb.mybluemix.net/";
}

chrome.browserAction.onClicked.addListener(function() {

chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
console.log("ID="+ tabs[0].id);

chrome.tabs.sendMessage(tabs[0].id, {command: "create_window"}, function(response) {
console.log(response);
console.log(response.result);
});
chrome.cookies.remove({url: api_endpoint, name: "sessionid"});

chrome.tabs.sendMessage(
tabs[0].id,
{
command: "create_window",
id: tabs[0].id,
title: tabs[0].title,
url: tabs[0].url,
},
function(response) {
if (response["result"] != "success"){
console.log(response);
console.log(response.result);
}
}
);
});

});

chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.action == "get_endpoint"){
sendResponse({
result: "success",
endpoint: api_endpoint
});
}
else if (request.action == "open_signup_tab"){
chrome.tabs.executeScript(sender.tab.id,
{code: 'document.getElementById("feedcrunch-window").remove();'}
);
chrome.tabs.create({url: "https://www.feedcrunch.io/signup/"});
sendResponse({result: "success"});
}
else if (request.action == "get_pageinfo"){
sendResponse({
result: "success",
title: sender.tab.title,
url: sender.tab.url
});
}
else if(request.action == "shutdown-iframe"){
chrome.tabs.executeScript(sender.tab.id,
{code: 'document.getElementById("feedcrunch-window").remove();'}
);
sendResponse({result: "success"});
}
else{
sendResponse({result: "error: unknown action: " + request.action});
}
}
);
15 changes: 10 additions & 5 deletions app/content_scripts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){

if (request.command == "create_window"){

Expand All @@ -22,8 +22,6 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse)
target_webpage += "popup.html";
}

/* target_webpage = "templates/login.html"; */

iframe.src = chrome.runtime.getURL(target_webpage);
iframe.id = iframe_id;

Expand All @@ -34,10 +32,17 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse)

document.body.appendChild(iframe);
});
}

sendResponse({"result": "success"});
sendResponse({result: "success"});
}
else{
sendResponse({result: "error: iframe already exists"});
}

}
else{
sendResponse({result: "error: command unknown: " + request.command});
}


});
Binary file removed demo/1.0_0.crx
Binary file not shown.
71 changes: 27 additions & 44 deletions js/login.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
$( document ).ready(function() {

var endpoint = null;
var debug = false;
var local = true;

if (debug)
if (local)
endpoint = "https://local.feedcrunch.io:5000/";
else
endpoint = "https://feedcrunch-api-dev.eu-gb.mybluemix.net/";
else
endpoint = "https://feedcrunch-api-prod.eu-gb.mybluemix.net/";
chrome.runtime.sendMessage({action: "get_endpoint"}, function(response) {
if (response.result == "success"){
endpoint = response.endpoint;
}
else{
console.log("Response:" + response.result);
}
});

var curTab = null;

try {
chrome.tabs.getSelected(null, function(tab){
$('#close-btn').on('click', function(){
chrome.tabs.executeScript(tab.id,
{code: 'document.getElementById("feedcrunch-window").remove();'}
);
$('#close-btn').on('click', function(){
chrome.runtime.sendMessage({action: "shutdown-iframe"}, function(response) {
if (response.result != "success"){
console.log("Response:" + response.result);
}
});
});
chrome.cookies.remove({url: endpoint, name: "sessionid"});
}
catch(err) {}
catch(err) {
console.log("error: " + err);
}

$('#signup_link').on('click', function(){
chrome.tabs.create({url: $(this).attr('href')});
chrome.runtime.sendMessage({action: "open_signup_tab"}, function(response) {
if (response.result != "success"){
console.log("Response:" + response.result);
}
});
return false;
});

Expand Down Expand Up @@ -73,37 +78,15 @@ $( document ).ready(function() {

if(! $("#login_form").valid()) return false;

var formData = new FormData();
formData.append('username', $("#username").val());
formData.append('password', $("#password").val());

/*
data: {
'username': $("#username").val(),
'password': $("#password").val()
}
*/

$.ajax({
url: endpoint + "api/1.0/get_auth_token/",
type: 'POST',
// Fetch the stored token from localStorage and set in the header
data: formData,
data: {
'username': $("#username").val(),
'password': $("#password").val()
},
dataType: "json",
mimeType: "multipart/form-data",
contentType: false,
cache: false,
processData:false,
xhrFields: {
withCredentials: false
},
headers: {
'Cache-Control': 'no-cache'
},
beforeSend: function(xhr) {
/*xhr.setRequestHeader('X-CSRFToken', csrf_val);*/
/*xhr.setRequestHeader('X-CSRFToken', 'Fiy8DD6Epge9I7geiWOMTlXZdSsZMnBlq4XOH9JDmTfnilNQcsg2kTtnvnJ0c2w2');*/
},
success: function(response){
if (response.token) {
chrome.storage.local.set({
Expand Down Expand Up @@ -132,7 +115,7 @@ $( document ).ready(function() {
console.log("password is missing!");
}

if (! error_found)
if (!error_found)
console.log(xhr.responseText);
}
}
Expand Down
Loading

0 comments on commit 6ea1d70

Please sign in to comment.