parent
25fe0c5849
commit
8723154371
@ -47,8 +47,16 @@
|
||||
"gulp-sourcemaps": "^1.6.0",
|
||||
"gulp-uglify": "^1.5.4",
|
||||
"gulp-zip": "^2.0.3",
|
||||
"husky": "^2.2.0",
|
||||
"preprocessify": "^1.0.1",
|
||||
"prettier": "^1.17.0",
|
||||
"pretty-quick": "^1.10.0",
|
||||
"vinyl-buffer": "^1.0.0",
|
||||
"vinyl-source-stream": "^1.1.0"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "pretty-quick --staged"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
import ext from "./utils/ext";
|
||||
import storage from "./utils/storage";
|
||||
|
||||
ext.runtime.onMessage.addListener(
|
||||
function(request, sender, sendResponse) {
|
||||
if(request.action === "perform-save") {
|
||||
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) {
|
||||
storage.get(["url", "token"], function(resp) {
|
||||
url = resp.url;
|
||||
token = resp.token;
|
||||
var params = {
|
||||
@ -17,28 +16,32 @@ ext.runtime.onMessage.addListener(
|
||||
d: encodeURIComponent(data.description),
|
||||
api_token: encodeURIComponent(token),
|
||||
i: encodeURIComponent(data.image),
|
||||
c: encodeURIComponent(data.comment),
|
||||
c: encodeURIComponent(data.comment)
|
||||
};
|
||||
var queryString = Object.keys(params).map((key) => {
|
||||
return key + '=' + params[key];
|
||||
}).join('&');
|
||||
var queryString = Object.keys(params)
|
||||
.map(key => {
|
||||
return key + "=" + params[key];
|
||||
})
|
||||
.join("&");
|
||||
fetch(url + "/api/links", {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
Accept: "application/json"
|
||||
},
|
||||
body: new URLSearchParams(queryString)
|
||||
})
|
||||
.then(function(response) {
|
||||
}).then(function(response) {
|
||||
if (200 === response.status) {
|
||||
sendResponse({action: "saved"});
|
||||
sendResponse({ action: "saved" });
|
||||
} else {
|
||||
sendResponse({action: "error", status: response.status, error: response.statusText});
|
||||
sendResponse({
|
||||
action: "error",
|
||||
status: response.status,
|
||||
error: response.statusText
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return true; // https://stackoverflow.com/a/20077854
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -16,22 +16,28 @@ var extractTags = () => {
|
||||
};
|
||||
|
||||
var ogTitle = document.querySelector("meta[property='og:title']");
|
||||
if(ogTitle) {
|
||||
if (ogTitle) {
|
||||
data.title = ogTitle.getAttribute("content");
|
||||
} else {
|
||||
data.title = document.title;
|
||||
}
|
||||
|
||||
var descriptionTag = document.querySelector("meta[property='og:description']") || document.querySelector("meta[name='description']");
|
||||
if(descriptionTag) {
|
||||
data.description = descriptionTag.getAttribute("content")
|
||||
var descriptionTag =
|
||||
document.querySelector("meta[property='og:description']") ||
|
||||
document.querySelector("meta[name='description']");
|
||||
if (descriptionTag) {
|
||||
data.description = descriptionTag.getAttribute("content");
|
||||
}
|
||||
|
||||
var imgTag = document.querySelector("meta[property='og:image']") || document.querySelector("meta[property='twitter-image']");
|
||||
if(imgTag) {
|
||||
data.image = imgTag.getAttribute("content")
|
||||
var imgTag =
|
||||
document.querySelector("meta[property='og:image']") ||
|
||||
document.querySelector("meta[property='twitter-image']");
|
||||
if (imgTag) {
|
||||
data.image = imgTag.getAttribute("content");
|
||||
} else {
|
||||
imgTag = document.querySelector("link[rel=icon]") || document.querySelector("link[rel=apple-touch-icon]");
|
||||
imgTag =
|
||||
document.querySelector("link[rel=icon]") ||
|
||||
document.querySelector("link[rel=apple-touch-icon]");
|
||||
if (imgTag) {
|
||||
data.image = imgTag.getAttribute("href");
|
||||
}
|
||||
@ -41,8 +47,8 @@ var extractTags = () => {
|
||||
};
|
||||
|
||||
function onRequest(request, sender, sendResponse) {
|
||||
if (request.action === 'process-page') {
|
||||
sendResponse(extractTags())
|
||||
if (request.action === "process-page") {
|
||||
sendResponse(extractTags());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,19 +1,21 @@
|
||||
'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();
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,11 @@ var urlInput = document.querySelector("[name=url]");
|
||||
var tokenInput = document.querySelector("[name=token]");
|
||||
var message = document.getElementById("msg");
|
||||
|
||||
storage.get('url', function(resp) {
|
||||
storage.get("url", function(resp) {
|
||||
urlInput.value = resp.url || "https://app.readlater.shikiryu.com";
|
||||
});
|
||||
|
||||
storage.get('token', function(resp) {
|
||||
storage.get("token", function(resp) {
|
||||
tokenInput.value = resp.token;
|
||||
});
|
||||
|
||||
|
@ -10,51 +10,62 @@ var page_data = {
|
||||
};
|
||||
|
||||
var popup = document.getElementById("app");
|
||||
storage.get('color', function(resp) {
|
||||
storage.get("color", function(resp) {
|
||||
var color = resp.color;
|
||||
if(color) {
|
||||
popup.style.backgroundColor = color
|
||||
if (color) {
|
||||
popup.style.backgroundColor = color;
|
||||
}
|
||||
});
|
||||
|
||||
var renderMessage = (message) => {
|
||||
var renderMessage = message => {
|
||||
var displayContainer = document.getElementById("display-container");
|
||||
displayContainer.textContent = message;
|
||||
};
|
||||
|
||||
var renderBookmark = (data) => {
|
||||
var renderBookmark = data => {
|
||||
if (data) {
|
||||
page_data = data;
|
||||
document.querySelector("[data-template=title]").textContent = page_data.title;
|
||||
document.querySelector("[data-template=description]").textContent = page_data.description;
|
||||
document.querySelector("[data-template=title]").textContent =
|
||||
page_data.title;
|
||||
document.querySelector("[data-template=description]").textContent =
|
||||
page_data.description;
|
||||
if ("" !== img) {
|
||||
var img = document.createElement("image");
|
||||
img.src = page_data.image;
|
||||
document.querySelector("[data-template=image]").appendChild(img);
|
||||
}
|
||||
document.querySelector("[data-template=url]").textContent = page_data.url;
|
||||
document.querySelector("[data-template=url]").setAttribute("href", page_data.url);
|
||||
document
|
||||
.querySelector("[data-template=url]")
|
||||
.setAttribute("href", page_data.url);
|
||||
} else {
|
||||
renderMessage(ext.i18n.getMessage("cantExtractTitle"));
|
||||
}
|
||||
};
|
||||
|
||||
ext.tabs.query({active: true, currentWindow: true}, function(tabs) {
|
||||
ext.tabs.query({ active: true, currentWindow: true }, function(tabs) {
|
||||
var activeTab = tabs[0];
|
||||
chrome.tabs.sendMessage(activeTab.id, { action: 'process-page' }, renderBookmark);
|
||||
chrome.tabs.sendMessage(
|
||||
activeTab.id,
|
||||
{ action: "process-page" },
|
||||
renderBookmark
|
||||
);
|
||||
});
|
||||
|
||||
popup.addEventListener("click", function(e) {
|
||||
if(e.target && e.target.matches("#save-btn")) {
|
||||
if (e.target && e.target.matches("#save-btn")) {
|
||||
e.preventDefault();
|
||||
page_data.comment = document.getElementById("comment").value;
|
||||
ext.runtime.sendMessage({action: "perform-save", data: page_data}, function (response) {
|
||||
ext.runtime.sendMessage(
|
||||
{ action: "perform-save", data: page_data },
|
||||
function(response) {
|
||||
if (response && response.action === "saved") {
|
||||
renderMessage(ext.i18n.getMessage("savedSuccessfully"));
|
||||
} else {
|
||||
renderMessage(response.error + " ("+response.status+")");
|
||||
renderMessage(response.error + " (" + response.status + ")");
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@ -66,5 +77,5 @@ var dataMessages = document.querySelectorAll("[data-message]");
|
||||
var optionsLink = document.querySelector(".js-options");
|
||||
optionsLink.addEventListener("click", function(e) {
|
||||
e.preventDefault();
|
||||
ext.tabs.create({'url': ext.extension.getURL('options.html')});
|
||||
ext.tabs.create({ url: ext.extension.getURL("options.html") });
|
||||
});
|
||||
|
@ -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();
|
@ -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
Block a user