aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRahiel Kasim <rahielkasim@gmail.com>2016-06-25 13:49:04 +0200
committerRahiel Kasim <rahielkasim@gmail.com>2016-06-25 13:49:04 +0200
commitb635995ab07cfb5bdf4d1ac82a48325941a35023 (patch)
tree079f3b2ea0a657b7322d99778c3d286baa65f9ba
parent22d90d253e20043913645389daab407b439a2c98 (diff)
archive pages from the context menu
-rw-r--r--chromium/archiveror.js25
-rw-r--r--chromium/manifest.json13
-rw-r--r--firefox/lib/main.js29
-rw-r--r--firefox/package.json2
-rw-r--r--package.json8
-rw-r--r--utils.js8
6 files changed, 68 insertions, 17 deletions
diff --git a/chromium/archiveror.js b/chromium/archiveror.js
index a9e4321..83fe128 100644
--- a/chromium/archiveror.js
+++ b/chromium/archiveror.js
@@ -1,4 +1,5 @@
-import { get_archiving_url } from "./../utils.js";
+import { get_archiving_url, services } from "./../utils.js";
+
function archive_is(url) {
let request = new XMLHttpRequest();
@@ -22,10 +23,12 @@ function postArchive(url, link) {
});
}
-function archivePage(url) {
+function archivePage(url, service) {
let tabId, link;
chrome.storage.local.get({archiveService: "archive.is", email: ""}, function (items) {
- link = get_archiving_url(url, items.archiveService, items.email);
+ if (service === undefined)
+ service = items.archiveService;
+ link = get_archiving_url(url, service, items.email);
chrome.tabs.create({url: link}, function (tab) {
tabId = tab.id;
@@ -242,6 +245,22 @@ chrome.commands.onCommand.addListener(function (command) {
}
});
+// context menu
+let menu = chrome.contextMenus.create({
+ title: "Archive",
+ id: "context-menu"
+});
+for (let service of services) {
+ chrome.contextMenus.create({
+ title: service,
+ id: service,
+ parentId: menu
+ });
+}
+chrome.contextMenus.onClicked.addListener(function (info, tab) {
+ archivePage(info.pageUrl, info.menuItemId);
+});
+
function newBookmark(id, bookmark) {
chrome.storage.local.get({archiveBookmarks: true}, function (items) {
if (bookmark.hasOwnProperty("url") && items.archiveBookmarks === true) {
diff --git a/chromium/manifest.json b/chromium/manifest.json
index 27c29ea..a38e7ca 100644
--- a/chromium/manifest.json
+++ b/chromium/manifest.json
@@ -2,11 +2,13 @@
"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.4.1",
+ "version": "0.5.0",
- "icons": { "16": "icon-16.png",
- "48": "icon-48.png",
- "128": "icon-128.png" },
+ "icons": {
+ "16": "icon-16.png",
+ "48": "icon-48.png",
+ "128": "icon-128.png"
+ },
"permissions": [
"tabs",
@@ -17,7 +19,8 @@
"downloads.shelf",
"pageCapture",
"<all_urls>",
- "clipboardWrite"
+ "clipboardWrite",
+ "contextMenus"
],
"background": {
diff --git a/firefox/lib/main.js b/firefox/lib/main.js
index 96d1c7c..e35a0f3 100644
--- a/firefox/lib/main.js
+++ b/firefox/lib/main.js
@@ -1,5 +1,6 @@
const buttons = require('sdk/ui/button/action');
const clipboard = require("sdk/clipboard");
+const cm = require("sdk/context-menu");
const Hotkey = require("sdk/hotkeys").Hotkey;
const preferences = require("sdk/simple-prefs");
const Request = require("sdk/request").Request;
@@ -7,7 +8,8 @@ const ss = require("sdk/simple-storage");
const tabs = require('sdk/tabs');
const bookmarks = require("./bookmarks");
-const { get_archiving_url } = require("./../utils.js");
+const { get_archiving_url, services } = require("./../utils.js");
+
function archive(url) {
// silently submit url to archive.is
@@ -57,8 +59,9 @@ let button = buttons.ActionButton({
}
});
-function archivePage() {
- let service = preferences.prefs.archiveService;
+function archivePage(service) {
+ if (service === undefined)
+ service = preferences.prefs.archiveService;
let email = preferences.prefs.email;
tabs.open({
@@ -107,6 +110,26 @@ function autoArchive(url) {
}
}
+// right-click context menu
+let menuItems = [];
+for (let i = 0; i < services.length; i++) {
+ menuItems.push(cm.Item({
+ label: services[i],
+ data: services[i]
+ }));
+}
+let archiveContextMenu = cm.Menu({
+ label: "Archive",
+ context: cm.PageContext(),
+ contentScript: `self.on("click", function (node, data) {
+ self.postMessage(data);
+ })`,
+ onMessage: function (service) {
+ archivePage(service);
+ },
+ items: menuItems
+});
+
exports.main = function () {
// archive newly made bookmarks
bookmarks.on("added", autoArchive);
diff --git a/firefox/package.json b/firefox/package.json
index 6ce1a3e..b568f4d 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.4.1",
+ "version": "0.5.0",
"preferences": [
{
"name": "archiveService",
diff --git a/package.json b/package.json
index 401a4e2..1bddb99 100644
--- a/package.json
+++ b/package.json
@@ -19,13 +19,13 @@
"url": "https://github.com/rahiel/archiveror/issues"
},
"devDependencies": {
- "babel-cli": "^6.7.5",
+ "babel-cli": "^6.10.1",
"babel-loader": "^6.2.4",
- "babel-preset-es2015": "^6.6.0",
+ "babel-preset-es2015": "^6.9.0",
"babel-preset-es2015-native-modules": "^6.6.0",
- "eslint": "^2.8.0",
+ "eslint": "^2.13.1",
"jpm": "^1.0.7",
- "webpack": "^2.1.0-beta.5"
+ "webpack": "^2.1.0-beta.14"
},
"babel": {
"presets": [
diff --git a/utils.js b/utils.js
index 19d1c93..0669bc9 100644
--- a/utils.js
+++ b/utils.js
@@ -1,5 +1,7 @@
// code shared between the extensions
+export const services = ["archive.is", "archive.org", "webcitation.org"];
+
export function get_archiving_url(page, service, email) {
let url = "https://archive.is/?run=1&url=" + page; // default
if (service === "archive.org")
@@ -11,4 +13,8 @@ export function get_archiving_url(page, service, email) {
return url;
}
-exports.get_archiving_url = get_archiving_url;
+// exports for firefox
+exports = {
+ get_archiving_url: get_archiving_url,
+ services: services
+};