~djl/bookmark-keys

dedc5cd4a751ec04604fffe297796b668ee7c4db — David Logie 6 years ago 7ccacfb
Rewrite as a Web Extension.
9 files changed, 68 insertions(+), 120 deletions(-)

D LICENSE
D Makefile
M README.markdown
A background.js
A manifest.json
D src/chrome.manifest
D src/chrome/content/bookmark_keys.js
D src/chrome/content/bookmark_keys.xul
D src/install.rdf
D LICENSE => LICENSE +0 -27
@@ 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

D Makefile => Makefile +0 -11
@@ 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

M README.markdown => README.markdown +2 -3
@@ 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.

A background.js => background.js +13 -0
@@ 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});
        }
    });
});

A manifest.json => manifest.json +53 -0
@@ 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"
        }
    }
}

D src/chrome.manifest => src/chrome.manifest +0 -2
@@ 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

D src/chrome/content/bookmark_keys.js => src/chrome/content/bookmark_keys.js +0 -54
@@ 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);

D src/chrome/content/bookmark_keys.xul => src/chrome/content/bookmark_keys.xul +0 -4
@@ 1,4 0,0 @@
<?xml version="1.0"?>
<overlay id="command_keys" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
	<script type="application/x-javascript" src="chrome://bookmark_keys/content/bookmark_keys.js" />
</overlay>

D src/install.rdf => src/install.rdf +0 -19
@@ 1,19 0,0 @@
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
    <Description about="urn:mozilla:install-manifest">
        <em:id>bookmark-keys@djl.firefox</em:id>
        <em:version>1.0.1</em:version>
        <em:type>2</em:type>
        <em:targetApplication>
            <Description>
                <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
                <em:minVersion>3.0</em:minVersion>
                <em:maxVersion>*</em:maxVersion>
            </Description>
        </em:targetApplication>
        <em:name>Bookmark Keys</em:name>
        <em:description>Access your bookmarks bar using cmd/ctrl 1-9.</em:description>
        <em:creator>djl</em:creator>
        <em:multiprocessCompatible>true</em:multiprocessCompatible>
    </Description>
</RDF>