From dedc5cd4a751ec04604fffe297796b668ee7c4db Mon Sep 17 00:00:00 2001 From: David Logie Date: Mon, 14 Aug 2017 11:52:19 +0100 Subject: [PATCH] Rewrite as a Web Extension. --- LICENSE | 27 -------------- Makefile | 11 ------ README.markdown | 5 ++- background.js | 13 +++++++ manifest.json | 53 +++++++++++++++++++++++++++ src/chrome.manifest | 2 -- src/chrome/content/bookmark_keys.js | 54 ---------------------------- src/chrome/content/bookmark_keys.xul | 4 --- src/install.rdf | 19 ---------- 9 files changed, 68 insertions(+), 120 deletions(-) delete mode 100644 LICENSE delete mode 100644 Makefile create mode 100644 background.js create mode 100644 manifest.json delete mode 100755 src/chrome.manifest delete mode 100755 src/chrome/content/bookmark_keys.js delete mode 100755 src/chrome/content/bookmark_keys.xul delete mode 100755 src/install.rdf diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 2779d18..0000000 --- a/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2009, David Logie -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - 3. Neither the name of this project nor the names of its contributors may be - used to endorse or promote products derived from this software without - specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 3c36ac2..0000000 --- a/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -EXTENSION="`basename $(PWD)`" -VERSION=`grep "em:version" $(PWD)/src/install.rdf | sed -n -e 's/<.*>\(.*\)<\/.*>/\1/p' | sed 's/^[ \t]*//'` -FILENAME="$(EXTENSION)_$(VERSION).xpi" - -build: - @echo "Building $(FILENAME)..." - @cd "src" && zip -rq "$(FILENAME)" * - @mv "src/$(FILENAME)" . - @echo "Done!" - -.PHONY: build diff --git a/README.markdown b/README.markdown index 7b63ec6..e0b3524 100644 --- a/README.markdown +++ b/README.markdown @@ -1,4 +1,3 @@ -Bookmark Keys -------------- +# Bookmark Keys -Access your bookmarks bar using cmd/ctrl 1-9. +Access your bookmarks bar with ctrl/cmd 1-9. diff --git a/background.js b/background.js new file mode 100644 index 0000000..b9e9c03 --- /dev/null +++ b/background.js @@ -0,0 +1,13 @@ +browser.commands.onCommand.addListener((num) => { + var idx = Number(num) - 1; + browser.bookmarks.getChildren('toolbar_____').then((tree) => { + var url = tree[idx].url; + if (url.indexOf("javascript:") == 0) { + url = unescape(url.split("javascript:")[1]); + console.log(url); + browser.tabs.executeScript({"code": url}); + } else { + browser.tabs.update({"url": url}); + } + }); +}); diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..89094ab --- /dev/null +++ b/manifest.json @@ -0,0 +1,53 @@ +{ + "name": "Bookmark keys", + "description": "Access your bookmarks bar with ctrl/cmd + 1-9.", + "manifest_version": 2, + "version": "1.0.2", + "homepage_url": "https://github.com/djl/bookmark-keys", + "background": { + "scripts": ["background.js"] + }, + "permissions": [ + "*://*/*", + "bookmarks", + "tabs" + ], + "commands": { + "1": { + "suggested_key": { "default": "Ctrl+1" }, + "description": "Open the 1st bookmark" + }, + "2": { + "suggested_key": { "default": "Ctrl+2" }, + "description": "Open the 2nd bookmark" + }, + "3": { + "suggested_key": { "default": "Ctrl+3" }, + "description": "Open the 3rd bookmark" + }, + "4": { + "suggested_key": { "default": "Ctrl+4" }, + "description": "Open the 4th bookmark" + }, + "5": { + "suggested_key": { "default": "Ctrl+5" }, + "description": "Open the 5th bookmark" + }, + "6": { + "suggested_key": { "default": "Ctrl+6" }, + "description": "Open the 6th bookmark" + }, + "7": { + "suggested_key": { "default": "Ctrl+7" }, + "description": "Open the 7th bookmark" + }, + "8": { + "suggested_key": { "default": "Ctrl+8" }, + "description": "Open the 8th bookmark" + }, + "9": { + "suggested_key": { "default": "Ctrl+9" }, + "description": "Open the 9th bookmark" + } + } +} diff --git a/src/chrome.manifest b/src/chrome.manifest deleted file mode 100755 index 11a987f..0000000 --- a/src/chrome.manifest +++ /dev/null @@ -1,2 +0,0 @@ -content bookmark_keys chrome/content/ -overlay chrome://browser/content/browser.xul chrome://bookmark_keys/content/bookmark_keys.xul \ No newline at end of file diff --git a/src/chrome/content/bookmark_keys.js b/src/chrome/content/bookmark_keys.js deleted file mode 100755 index 58261fe..0000000 --- a/src/chrome/content/bookmark_keys.js +++ /dev/null @@ -1,54 +0,0 @@ -var bookmarkKeys = { - init: function() { - for (var i=0; i < 9; i++) { - var tab = i + 1; - var keyset = document.getElementById("mainKeyset"); - var key = document.createElement("key"); - key.setAttribute("id", "bookmarkKeys_" + tab); - key.setAttribute("key", tab); - key.setAttribute("oncommand", "bookmarkKeys.go(" + i + ");"); - key.setAttribute("modifiers", "accel"); - keyset.appendChild(key); - - // disable old keys - if (tab < 9) { - var old_key = document.getElementById("key_selectTab" + tab); - } else { - var old_key = document.getElementById("key_selectLastTab"); - } - old_key.removeAttribute('oncommand'); - } - }, - - getBookmark: function(index) { - var historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"] - .getService(Components.interfaces.nsINavHistoryService); - var options = historyService.getNewQueryOptions(); - var query = historyService.getNewQuery(); - - var bookmarksService = Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"] - .getService(Components.interfaces.nsINavBookmarksService); - - query.setFolders([bookmarksService.toolbarFolder], 1); - - var result = historyService.executeQuery(query, options); - var bookmarks_bar = result.root; - bookmarks_bar.containerOpen = true; - try { - node = bookmarks_bar.getChild(index); - } catch (err) { - node = false; - } - bookmarks_bar.containerOpen = false; - return node - }, - - go: function(i) { - var node = bookmarkKeys.getBookmark(i); - if (node) { - PlacesUIUtils._openNodeIn(node, "current", window); - } - } -} - -window.addEventListener("load", bookmarkKeys.init, false); diff --git a/src/chrome/content/bookmark_keys.xul b/src/chrome/content/bookmark_keys.xul deleted file mode 100755 index 9d5a612..0000000 --- a/src/chrome/content/bookmark_keys.xul +++ /dev/null @@ -1,4 +0,0 @@ - - -