aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRahiel Kasim <rahielkasim@gmail.com>2017-06-11 12:54:18 +0200
committerRahiel Kasim <rahielkasim@gmail.com>2017-06-11 12:54:18 +0200
commit976bd0471db63ea770c9a292240a257181c520b6 (patch)
tree0fee8ab2bf1fdbf62b6c043165e45b79d25fe97e
parentcd9b5129ec243c7e30d37e2e49586aff2a8f6a02 (diff)
review bookmark removal code
chrome.bookmarks.onRemoved was improved in Chrome 48
-rw-r--r--package.json2
-rw-r--r--src/archiveror.js81
-rw-r--r--src/manifest.json3
3 files changed, 28 insertions, 58 deletions
diff --git a/package.json b/package.json
index 760c7fc..a83e47d 100644
--- a/package.json
+++ b/package.json
@@ -17,7 +17,7 @@
"url": "https://github.com/rahiel/archiveror/issues"
},
"devDependencies": {
- "babel-core": "^6.24.1",
+ "babel-core": "^6.25.0",
"babel-loader": "^7.0.0",
"babel-preset-es2015": "^6.24.1",
"eslint": "^3.19.0",
diff --git a/src/archiveror.js b/src/archiveror.js
index 73b99a3..ae4de1a 100644
--- a/src/archiveror.js
+++ b/src/archiveror.js
@@ -253,21 +253,23 @@ 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.removeAll(function () {
+ let menu = chrome.contextMenus.create({
+ title: "Archive",
+ id: "context-menu"
});
-}
-if (hasPageCapture) {
- chrome.contextMenus.create({type: "separator", id: "separator", parentId: menu});
- chrome.contextMenus.create({title: "Save MHTML as...", id: "MHTML", parentId: menu});
-}
+ for (let service of services) {
+ chrome.contextMenus.create({
+ title: service,
+ id: service,
+ parentId: menu
+ });
+ }
+ if (hasPageCapture) {
+ 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) {
if (info.menuItemId === "MHTML")
saveLocal(tab, false);
@@ -279,7 +281,6 @@ function newBookmark(id, bookmark) {
chrome.storage.local.get({archiveBookmarks: true}, function (items) {
if (bookmark.hasOwnProperty("url") && items.archiveBookmarks === true) {
archive(bookmark.url, true, undefined, bookmark);
- getBookmarkTree();
}
});
}
@@ -342,7 +343,6 @@ function moveLocal(id, moveInfo) {
chrome.downloads.removeFile(downloadId, function () {
downloadBlock.push(null);
saveDownload(newId, bookmark.url);
- getBookmarkTree();
});
});
});
@@ -360,58 +360,27 @@ function moveLocal(id, moveInfo) {
chrome.bookmarks.onMoved.addListener(moveLocal);
chrome.bookmarks.onChanged.addListener(moveLocal);
-// Block updating bookmarkTree when there's something in bookmarkBlock
-let bookmarkBlock = [];
-let bookmarkTree;
-
-function getBookmarkTree() {
- if (bookmarkBlock.length > 0) {
- window.setTimeout(getBookmarkTree, 200);
- return;
- }
- chrome.bookmarks.getTree(function (bookmarks) {
- bookmarkTree = bookmarks[0];
- });
-}
-getBookmarkTree();
-
-function findBookmark(tree, id, callback) {
- // find bookmark in bookmarkTree
- // TODO: make synchronous
- for (let i = 0; i < tree.children.length; i++) {
- if (tree.children[i].id === id) {
- callback(tree.children[i]);
- } else if (tree.children[i].hasOwnProperty("children")) {
- findBookmark(tree.children[i], id, callback);
- }
- }
-}
-
function removeBookmark(id, removeInfo) {
- bookmarkBlock.push(null);
- findBookmark(bookmarkTree, id, deleteBookmarkNode);
+ let node = removeInfo.node;
- function deleteBookmarkNode(bookmarkNode) {
- if (bookmarkNode.hasOwnProperty("children")) { // directory
- for (let i = 0; i < bookmarkNode.children.length; i++) {
- removeBookmark(bookmarkNode.children[i].id);
- }
- bookmarkBlock.pop();
- } else {
- deleteBookmark(bookmarkNode);
+ if (node.hasOwnProperty("children")) { // directory
+ for (let child of node.children) {
+ removeBookmark(child.id, {node: child});
}
+ } else {
+ deleteBookmark(node);
}
function deleteBookmark(bookmark) {
- bookmarkBlock.pop();
- getBookmarkTree();
let url = bookmark.url;
let key = "_" + url;
chrome.storage.local.get(key, function (items) {
// What if deleting the file fails?
- chrome.downloads.removeFile(items[key].id);
chrome.storage.local.remove(key);
+ if (items.hasOwnProperty(key) && hasPageCapture) {
+ chrome.downloads.removeFile(items[key].id);
+ }
});
chrome.storage.local.remove(url);
diff --git a/src/manifest.json b/src/manifest.json
index d9d361d..0e78623 100644
--- a/src/manifest.json
+++ b/src/manifest.json
@@ -2,13 +2,14 @@
"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.6.1",
+ "version": "0.6.2",
"applications": {
"gecko": {
"id": "archiveror@love.addons.mozilla.org",
"strict_min_version": "52.0"
}
},
+ "minimum_chrome_version": "48",
"icons": {
"16": "icon-16.png",
"48": "icon-48.png",