|
@@ -18,8 +18,10 @@ function getCurrentTabUrl(callback) {
|
|
|
function tryToDetectSettings() {
|
|
function tryToDetectSettings() {
|
|
|
chrome.tabs.query(queryInfo, function(tabs) {
|
|
chrome.tabs.query(queryInfo, function(tabs) {
|
|
|
chrome.tabs.executeScript(tabs[0].id, { file: 'detectapp.js' }, function (results) {
|
|
chrome.tabs.executeScript(tabs[0].id, { file: 'detectapp.js' }, function (results) {
|
|
|
- if (results[0] && results[0].addPostUrl) {
|
|
|
|
|
- localStorage.settingsUrl = results[0].addPostUrl;
|
|
|
|
|
|
|
+ if (results[0] && results[0].origin && results[0].token) {
|
|
|
|
|
+ localStorage.origin = results[0].origin;
|
|
|
|
|
+ localStorage.token = results[0].token;
|
|
|
|
|
+ localStorage.title = results[0].title;
|
|
|
show('home');
|
|
show('home');
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -29,7 +31,7 @@ function tryToDetectSettings() {
|
|
|
tryToDetectSettings();
|
|
tryToDetectSettings();
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
- if (!localStorage.settingsUrl) {
|
|
|
|
|
|
|
+ if (!localStorage.token) {
|
|
|
show('setup');
|
|
show('setup');
|
|
|
} else {
|
|
} else {
|
|
|
show('main');
|
|
show('main');
|
|
@@ -61,7 +63,9 @@ function show(view) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function disconnectApp() {
|
|
function disconnectApp() {
|
|
|
- delete localStorage.settingsUrl;
|
|
|
|
|
|
|
+ delete localStorage.origin;
|
|
|
|
|
+ delete localStorage.token;
|
|
|
|
|
+ delete localStorage.title;
|
|
|
show('disconnected');
|
|
show('disconnected');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -69,8 +73,10 @@ function add() {
|
|
|
show('busy');
|
|
show('busy');
|
|
|
|
|
|
|
|
var http = new XMLHttpRequest();
|
|
var http = new XMLHttpRequest();
|
|
|
|
|
+ var url = localStorage.origin + '/api/things?token=' + localStorage.token;
|
|
|
var body = JSON.stringify({ content: document.getElementById('content').value });
|
|
var body = JSON.stringify({ content: document.getElementById('content').value });
|
|
|
- http.open('POST', localStorage.settingsUrl, true);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ http.open('POST', url, true);
|
|
|
|
|
|
|
|
http.setRequestHeader('Content-type', 'application/json');
|
|
http.setRequestHeader('Content-type', 'application/json');
|
|
|
http.setRequestHeader('Content-length', body.length);
|
|
http.setRequestHeader('Content-length', body.length);
|
|
@@ -79,7 +85,7 @@ function add() {
|
|
|
http.onreadystatechange = function() {//Call a function when the state changes.
|
|
http.onreadystatechange = function() {//Call a function when the state changes.
|
|
|
if(http.readyState === 4) {
|
|
if(http.readyState === 4) {
|
|
|
if (http.status === 401) {
|
|
if (http.status === 401) {
|
|
|
- delete localStorage.settingsUrl;
|
|
|
|
|
|
|
+ delete localStorage.token;
|
|
|
show('setup');
|
|
show('setup');
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|