aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRahiel Kasim <rahielkasim@gmail.com>2016-11-08 15:28:41 +0100
committerRahiel Kasim <rahielkasim@gmail.com>2016-11-08 15:28:41 +0100
commit1794284178e98e15b46e9ea8302f8001918b64ff (patch)
tree34d84f21cf7d349e24f33fdad6f6590b80370ca0
parent1dfa30b6ffc2b2c2355771e5c15c6a8d9975d2e6 (diff)
option to use multiple archiving services for manual archiving (#12)
-rw-r--r--chromium/archiveror.js40
-rw-r--r--chromium/manifest.json3
-rw-r--r--chromium/options.html8
-rw-r--r--chromium/options.js32
-rw-r--r--package.json15
-rw-r--r--webpack.config.js3
6 files changed, 55 insertions, 46 deletions
diff --git a/chromium/archiveror.js b/chromium/archiveror.js
index 0ffeec3..4fd384e 100644
--- a/chromium/archiveror.js
+++ b/chromium/archiveror.js
@@ -25,22 +25,24 @@ function postArchive(url, link) {
});
}
-// archive url online at service
-function archivePage(url, service) {
+// archive url online at services (a list of strings)
+function archivePage(url, services) {
if (is_local(url))
return; // don't archive internal pages, "file://", "chrome://", etc.
let tabId, link;
- chrome.storage.local.get({archiveService: "archive.is", email: ""}, function (items) {
- if (service === undefined)
- service = items.archiveService;
- link = get_archiving_url(url, service, items.email);
-
- chrome.tabs.create({url: link}, function (tab) {
- tabId = tab.id;
- // support updating clipboard with new link from archive.is "save the page again"
- chrome.tabs.onUpdated.addListener(url_to_clipboard);
- chrome.tabs.onRemoved.addListener(url_to_clipboard);
- });
+ chrome.storage.local.get({archiveServices: ["archive.is"], email: ""}, function (items) {
+ if (services === undefined)
+ services = items.archiveServices;
+ for (let service of services) {
+ link = get_archiving_url(url, service, items.email);
+
+ chrome.tabs.create({url: link}, function (tab) {
+ tabId = tab.id;
+ // support updating clipboard with new link from archive.is "save the page again"
+ chrome.tabs.onUpdated.addListener(url_to_clipboard);
+ chrome.tabs.onRemoved.addListener(url_to_clipboard);
+ });
+ }
});
let re = /.*(?:archive|webcitation)\.(?:is|org).*/;
@@ -268,7 +270,7 @@ chrome.contextMenus.onClicked.addListener(function (info, tab) {
if (info.menuItemId === "MHTML")
saveLocal(tab, false);
else
- archivePage(info.pageUrl, info.menuItemId);
+ archivePage(info.pageUrl, [info.menuItemId]);
});
function newBookmark(id, bookmark) {
@@ -418,3 +420,13 @@ function removeBookmark(id, removeInfo) {
}
}
chrome.bookmarks.onRemoved.addListener(removeBookmark);
+
+// TODO: preference migration, remove this somewhere 2017
+chrome.storage.local.get({archiveService: null}, function (items) {
+ let service = items.archiveService;
+ if (typeof service === "string") {
+ chrome.storage.local.set({archiveServices: [service]}, function () {
+ chrome.storage.local.remove("archiveService");
+ });
+ }
+});
diff --git a/chromium/manifest.json b/chromium/manifest.json
index 657780e..201d076 100644
--- a/chromium/manifest.json
+++ b/chromium/manifest.json
@@ -2,7 +2,7 @@
"name": "Archiveror",
"author": "Rahiel Kasim",
"description": "Archive webpages on archive.is, archive.org and more or on your own computer in MHTML format. Automatically archive your bookmarks.",
- "version": "0.5.3",
+ "version": "0.6.0",
"icons": {
"16": "icon-16.png",
@@ -14,7 +14,6 @@
"tabs",
"bookmarks",
"storage",
- "https://archive.is/",
"downloads",
"downloads.shelf",
"pageCapture",
diff --git a/chromium/options.html b/chromium/options.html
index dec5701..2dac9ed 100644
--- a/chromium/options.html
+++ b/chromium/options.html
@@ -9,19 +9,19 @@
</head>
<body>
<h3>Archiving Service</h3>
- <p>The online archiving service to use for manual archiving.</p>
+ <p>The online archiving service(s) to use for manual archiving.</p>
<label for="archive.is">
- <input type="radio" name="service" id="archive.is" value="archive.is">
+ <input type="checkbox" name="service" id="archive.is" value="archive.is">
<a href="https://archive.is/">archive.is</a>
</label>
<br>
<label for="archive.org">
- <input type="radio" name="service" id="archive.org" value="archive.org">
+ <input type="checkbox" name="service" id="archive.org" value="archive.org">
<a href="https://archive.org/web/">archive.org</a> (Wayback Machine)
</label>
<br>
<label for="webcitation.org">
- <input type="radio" name="service" id="webcitation.org" value="webcitation.org">
+ <input type="checkbox" name="service" id="webcitation.org" value="webcitation.org">
<a href="http://webcitation.org/">webcitation.org</a> (requires email, no HTTPS)
</label>
diff --git a/chromium/options.js b/chromium/options.js
index a4381c9..ddda383 100644
--- a/chromium/options.js
+++ b/chromium/options.js
@@ -1,21 +1,19 @@
function save_options() {
- function get_radio_option(name) {
- // get the selected radio option by name
- let radio = document.getElementsByName(name);
- let option = "None";
- for (let i = 0; i < radio.length; i++) {
- if (radio[i].checked === true) {
- option = radio[i].value;
- break;
+ function get_options(name) {
+ // get the selected options by name
+ let checkboxes = document.getElementsByName(name);
+ let options = [];
+ for (let c of checkboxes) {
+ if (c.checked === true) {
+ options.push(c.value);
}
}
- if (option === "None")
- message("Please select a mode."); // this should never happen
- return option;
+ return options;
}
- let mode = get_radio_option("mode");
- let service = get_radio_option("service");
+
+ let mode = get_options("mode")[0];
+ let services = get_options("service");
let dir = document.getElementById("dir").value;
// TODO: check dir for forbidden characters
@@ -23,7 +21,7 @@ function save_options() {
let bookmarks = document.getElementById("bookmarks").checked;
chrome.storage.local.set({
- archiveMode: mode, archiveDir: dir, archiveBookmarks: bookmarks, archiveService: service,
+ archiveMode: mode, archiveDir: dir, archiveBookmarks: bookmarks, archiveServices: services,
email: email
}, function () {
message("Options saved.");
@@ -32,7 +30,7 @@ function save_options() {
function restore_options() {
chrome.storage.local.get({ // below are the default values
- archiveMode: "online", archiveDir: "Archiveror", archiveBookmarks: true, archiveService: "archive.is",
+ archiveMode: "online", archiveDir: "Archiveror", archiveBookmarks: true, archiveServices: ["archive.is"],
email: ""
}, set_options);
@@ -43,7 +41,9 @@ function restore_options() {
document.getElementById("dir").value = items.archiveDir;
document.getElementById("email").value = items.email;
- document.getElementById(items.archiveService).checked = true;
+ for (let s of items.archiveServices) {
+ document.getElementById(s).checked = true;
+ }
if (items.archiveMode === "online")
document.getElementById("online").checked = true;
diff --git a/package.json b/package.json
index 342c201..84abf42 100644
--- a/package.json
+++ b/package.json
@@ -19,17 +19,16 @@
"url": "https://github.com/rahiel/archiveror/issues"
},
"devDependencies": {
- "babel-cli": "^6.10.1",
- "babel-loader": "^6.2.4",
- "babel-preset-es2015": "^6.9.0",
- "babel-preset-es2015-native-modules": "^6.6.0",
- "eslint": "^3.0.1",
- "jpm": "^1.0.7",
- "webpack": "^2.1.0-beta.15"
+ "babel-cli": "^6.18.0",
+ "babel-loader": "^6.2.7",
+ "babel-preset-es2015": "^6.18.0",
+ "eslint": "^3.9.1",
+ "jpm": "^1.2.2",
+ "webpack": "^2.1.0-beta.25"
},
"babel": {
"presets": [
- "es2015"
+ ["es2015", { "modules": false }]
]
}
}
diff --git a/webpack.config.js b/webpack.config.js
index faa60f3..62d8153 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -12,8 +12,7 @@ module.exports = {
{
loader: "babel-loader",
test: /\.js$/,
- exclude: /node_modules/,
- query: { presets: ["es2015-native-modules"] }
+ exclude: /node_modules/
},
{ test: /\.css$/, loader: "style!css" }
]