parent
25fe0c5849
commit
8723154371
@ -1,44 +1,47 @@
|
||||
import ext from "./utils/ext";
|
||||
import storage from "./utils/storage";
|
||||
|
||||
ext.runtime.onMessage.addListener(
|
||||
function(request, sender, sendResponse) {
|
||||
if(request.action === "perform-save") {
|
||||
var data = request.data;
|
||||
var url;
|
||||
var token;
|
||||
storage.get(['url', 'token'], function(resp) {
|
||||
url = resp.url;
|
||||
token = resp.token;
|
||||
var params = {
|
||||
v: 1,
|
||||
u: encodeURIComponent(data.url),
|
||||
t: encodeURIComponent(data.title),
|
||||
d: encodeURIComponent(data.description),
|
||||
api_token: encodeURIComponent(token),
|
||||
i: encodeURIComponent(data.image),
|
||||
c: encodeURIComponent(data.comment),
|
||||
};
|
||||
var queryString = Object.keys(params).map((key) => {
|
||||
return key + '=' + params[key];
|
||||
}).join('&');
|
||||
fetch(url + "/api/links", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
body: new URLSearchParams(queryString)
|
||||
ext.runtime.onMessage.addListener(function(request, sender, sendResponse) {
|
||||
if (request.action === "perform-save") {
|
||||
var data = request.data;
|
||||
var url;
|
||||
var token;
|
||||
storage.get(["url", "token"], function(resp) {
|
||||
url = resp.url;
|
||||
token = resp.token;
|
||||
var params = {
|
||||
v: 1,
|
||||
u: encodeURIComponent(data.url),
|
||||
t: encodeURIComponent(data.title),
|
||||
d: encodeURIComponent(data.description),
|
||||
api_token: encodeURIComponent(token),
|
||||
i: encodeURIComponent(data.image),
|
||||
c: encodeURIComponent(data.comment)
|
||||
};
|
||||
var queryString = Object.keys(params)
|
||||
.map(key => {
|
||||
return key + "=" + params[key];
|
||||
})
|
||||
.then(function(response) {
|
||||
if (200 === response.status) {
|
||||
sendResponse({action: "saved"});
|
||||
} else {
|
||||
sendResponse({action: "error", status: response.status, error: response.statusText});
|
||||
}
|
||||
});
|
||||
.join("&");
|
||||
fetch(url + "/api/links", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Accept: "application/json"
|
||||
},
|
||||
body: new URLSearchParams(queryString)
|
||||
}).then(function(response) {
|
||||
if (200 === response.status) {
|
||||
sendResponse({ action: "saved" });
|
||||
} else {
|
||||
sendResponse({
|
||||
action: "error",
|
||||
status: response.status,
|
||||
error: response.statusText
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return true; // https://stackoverflow.com/a/20077854
|
||||
}
|
||||
return true; // https://stackoverflow.com/a/20077854
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -1,20 +1,22 @@
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
import ext from "./utils/ext";
|
||||
|
||||
var LIVERELOAD_HOST = 'localhost:';
|
||||
var LIVERELOAD_HOST = "localhost:";
|
||||
var LIVERELOAD_PORT = 35729;
|
||||
var connection = new WebSocket('ws://' + LIVERELOAD_HOST + LIVERELOAD_PORT + '/livereload');
|
||||
var connection = new WebSocket(
|
||||
"ws://" + LIVERELOAD_HOST + LIVERELOAD_PORT + "/livereload"
|
||||
);
|
||||
|
||||
connection.onerror = function (error) {
|
||||
console.log('reload connection got error:', error);
|
||||
connection.onerror = function(error) {
|
||||
console.log("reload connection got error:", error);
|
||||
};
|
||||
|
||||
connection.onmessage = function (e) {
|
||||
connection.onmessage = function(e) {
|
||||
if (e.data) {
|
||||
var data = JSON.parse(e.data);
|
||||
if (data && data.command === 'reload') {
|
||||
if (data && data.command === "reload") {
|
||||
ext.runtime.reload();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@ -1,68 +1,66 @@
|
||||
const apis = [
|
||||
'alarms',
|
||||
'bookmarks',
|
||||
'browserAction',
|
||||
'commands',
|
||||
'contextMenus',
|
||||
'cookies',
|
||||
'downloads',
|
||||
'events',
|
||||
'extension',
|
||||
'extensionTypes',
|
||||
'history',
|
||||
'i18n',
|
||||
'idle',
|
||||
'notifications',
|
||||
'pageAction',
|
||||
'runtime',
|
||||
'storage',
|
||||
'tabs',
|
||||
'webNavigation',
|
||||
'webRequest',
|
||||
'windows',
|
||||
]
|
||||
"alarms",
|
||||
"bookmarks",
|
||||
"browserAction",
|
||||
"commands",
|
||||
"contextMenus",
|
||||
"cookies",
|
||||
"downloads",
|
||||
"events",
|
||||
"extension",
|
||||
"extensionTypes",
|
||||
"history",
|
||||
"i18n",
|
||||
"idle",
|
||||
"notifications",
|
||||
"pageAction",
|
||||
"runtime",
|
||||
"storage",
|
||||
"tabs",
|
||||
"webNavigation",
|
||||
"webRequest",
|
||||
"windows"
|
||||
];
|
||||
|
||||
function Extension () {
|
||||
const _this = this
|
||||
function Extension() {
|
||||
const _this = this;
|
||||
|
||||
apis.forEach(function (api) {
|
||||
|
||||
_this[api] = null
|
||||
apis.forEach(function(api) {
|
||||
_this[api] = null;
|
||||
|
||||
try {
|
||||
if (chrome[api]) {
|
||||
_this[api] = chrome[api]
|
||||
_this[api] = chrome[api];
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
try {
|
||||
if (window[api]) {
|
||||
_this[api] = window[api]
|
||||
_this[api] = window[api];
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
try {
|
||||
if (browser[api]) {
|
||||
_this[api] = browser[api]
|
||||
_this[api] = browser[api];
|
||||
}
|
||||
} catch (e) {}
|
||||
try {
|
||||
_this.api = browser.extension[api]
|
||||
_this.api = browser.extension[api];
|
||||
} catch (e) {}
|
||||
})
|
||||
});
|
||||
|
||||
try {
|
||||
if (browser && browser.runtime) {
|
||||
this.runtime = browser.runtime
|
||||
this.runtime = browser.runtime;
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
try {
|
||||
if (browser && browser.browserAction) {
|
||||
this.browserAction = browser.browserAction
|
||||
this.browserAction = browser.browserAction;
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
}
|
||||
|
||||
module.exports = new Extension();
|
||||
module.exports = new Extension();
|
||||
|
@ -1,3 +1,3 @@
|
||||
import ext from "./ext";
|
||||
|
||||
module.exports = (ext.storage.sync ? ext.storage.sync : ext.storage.local);
|
||||
module.exports = ext.storage.sync ? ext.storage.sync : ext.storage.local;
|
||||
|
Loading…
Reference in new issue