aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRahiel Kasim <rahielkasim@gmail.com>2016-06-27 20:54:30 +0200
committerRahiel Kasim <rahielkasim@gmail.com>2016-06-27 20:54:30 +0200
commitb62f5bcc9dd3aaf00d18c635ae4839294d5a9b08 (patch)
treeb8c2652f2c24721dffb1db8f68453e338b12a111
parent98210505d67aa5d408a0086b1b3262a012e2c5ae (diff)
exclude local pages from auto archiving, save as MHTML in context menu
-rw-r--r--chromium/archiveror.js16
-rw-r--r--chromium/manifest.json2
-rw-r--r--firefox/lib/main.js8
-rw-r--r--firefox/package.json2
-rw-r--r--utils.js10
5 files changed, 26 insertions, 12 deletions
diff --git a/chromium/archiveror.js b/chromium/archiveror.js
index d9882dd..0ffeec3 100644
--- a/chromium/archiveror.js
+++ b/chromium/archiveror.js
@@ -1,7 +1,9 @@
-import { get_archiving_url, services } from "./../utils.js";
+import { get_archiving_url, is_local, services } from "./../utils.js";
function archive_is(url) {
+ if (is_local(url))
+ return;
let request = new XMLHttpRequest();
request.open("POST", "https://archive.is/submit/", true);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
@@ -23,14 +25,15 @@ function postArchive(url, link) {
});
}
+// archive url online at service
function archivePage(url, service) {
+ 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);
- if (link === null)
- return; // don't archive internal pages, "file://", "chrome://", etc.
chrome.tabs.create({url: link}, function (tab) {
tabId = tab.id;
@@ -259,8 +262,13 @@ for (let service of services) {
parentId: menu
});
}
+chrome.contextMenus.create({type: "separator", id: "separator", parentId: menu});
+chrome.contextMenus.create({title: "Save MHTML as...", id: "MHTML", parentId: menu});
chrome.contextMenus.onClicked.addListener(function (info, tab) {
- archivePage(info.pageUrl, info.menuItemId);
+ if (info.menuItemId === "MHTML")
+ saveLocal(tab, false);
+ else
+ archivePage(info.pageUrl, info.menuItemId);
});
function newBookmark(id, bookmark) {
diff --git a/chromium/manifest.json b/chromium/manifest.json
index 20cd648..3e1d856 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.1",
+ "version": "0.5.2",
"icons": {
"16": "icon-16.png",
diff --git a/firefox/lib/main.js b/firefox/lib/main.js
index 3e2e9cf..a5e79cb 100644
--- a/firefox/lib/main.js
+++ b/firefox/lib/main.js
@@ -8,11 +8,13 @@ const ss = require("sdk/simple-storage");
const tabs = require('sdk/tabs');
const bookmarks = require("./bookmarks");
-const { get_archiving_url, services } = require("./../utils.js");
+const { get_archiving_url, is_local, services } = require("./../utils.js");
function archive(url) {
// silently submit url to archive.is
+ if (is_local(url))
+ return;
const r = Request({
url: "https://archive.is/submit/",
content: {"url": url, "anyway": 1},
@@ -60,12 +62,12 @@ let button = buttons.ActionButton({
});
function archivePage(service) {
+ if (is_local(tabs.activeTab.url))
+ return; // internal page, "file://" or "about:" etc.
if (service === undefined)
service = preferences.prefs.archiveService;
let email = preferences.prefs.email;
let url = get_archiving_url(tabs.activeTab.url, service, email);
- if (url === null)
- return; // internal page, "file://" or "about:" etc.
tabs.open({
url: url,
diff --git a/firefox/package.json b/firefox/package.json
index 0ed8eb2..1416102 100644
--- a/firefox/package.json
+++ b/firefox/package.json
@@ -8,7 +8,7 @@
"homepage": "https://github.com/rahiel/archiveror",
"author": "Rahiel Kasim",
"license": "GPL-3.0+ (https://github.com/rahiel/archiveror/blob/master/LICENSE.txt)",
- "version": "0.5.1",
+ "version": "0.5.2",
"preferences": [
{
"name": "archiveService",
diff --git a/utils.js b/utils.js
index 5c6100f..66cf9d4 100644
--- a/utils.js
+++ b/utils.js
@@ -4,11 +4,15 @@ export const services = ["archive.is", "archive.org", "webcitation.org"];
const exclude = ["file://", "about:", "chrome://"];
-export function get_archiving_url(page, service, email) {
+export function is_local(url) {
for (let i = 0; i < exclude.length; i++) {
- if (page.startsWith(exclude[i]))
- return null;
+ if (url.startsWith(exclude[i]))
+ return true;
}
+ return false;
+}
+
+export function get_archiving_url(page, service, email) {
let url = "https://archive.is/?run=1&url=" + page; // default
if (service === "archive.org")
url = "https://web.archive.org/save/" + page;