From 0f5e07d0096eac1643f949bb4f5ab06187e1bf42 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Wed, 18 Nov 2015 00:23:21 +0100 Subject: [PATCH] Add bookmark command to Keysnail --- keysnail/.keysnail.js | 63 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/keysnail/.keysnail.js b/keysnail/.keysnail.js index 9799e2e..a42e3d6 100644 --- a/keysnail/.keysnail.js +++ b/keysnail/.keysnail.js @@ -3,7 +3,8 @@ * KeySnail KeyEvent userscript ext openHelpLink * BrowserCloseTabOrWindow closeWindow undoCloseTab OpenBrowserWindow * getBrowser goQuitApplication saveDocument toJavaScriptConsole - * display shell BrowserReload BrowserBack BrowserForward content*/ + * display shell BrowserReload BrowserBack BrowserForward content M + * Components*/ // You can preserve your code in this area when generating the init // file using GUI. Put all your code except special key, set*key, // hook, blacklist. @@ -541,3 +542,63 @@ key.setViewKey([':', 'k'], function (ev, arg) { key.setViewKey([':', 't'], function (ev, arg) { ext.exec("bmany-list-bookmarks-with-tag", arg, ev); }, "bmany - List bookmarks with tag"); + +var oni = + (function() { + function _saveBookmark(tags, bookmark) { + var bmsvc = Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"] + .getService(Components.interfaces.nsINavBookmarksService); + var ios = Components.classes["@mozilla.org/network/io-service;1"] + .getService(Components.interfaces.nsIIOService); + var taggingSvc = Components.classes["@mozilla.org/browser/tagging-service;1"] + .getService(Components.interfaces.nsITaggingService); + var uri = ios.newURI(bookmark.url, null, null); + + bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder, uri, + bmsvc.DEFAULT_INDEX, bookmark.title); + taggingSvc.tagURI(uri, tags.split(',').map(String.trim)); + } + + function _readTags(url, bookmark) { + bookmark.url = url; + + prompt.read( + "tags (comma-separated):", + _saveBookmark, + bookmark, null + ); + } + + function _readURL(title) { + prompt.read( + "url:", + _readTags, + {title: title}, null, + window.content.location.href + ); + } + + function _readTitle() { + prompt.read( + "title:", + _readURL, + null, null, + window.content.document.title + ); + } + + var self = { + addBookmark: function(arg) { + _readTitle(); + } + }; + + return self; + })(); + +ext.add('oni-add-bookmark', function(ev, arg) { oni.addBookmark(arg); }, + M({en: "oni - Add bookmark"})); + +key.setViewKey([':', 'a'], function (ev, arg) { + ext.exec("oni-add-bookmark", arg, ev); +}, "Bookmark this page");