Add remove and retag commands for keysnail bookmarks
This commit is contained in:
parent
0f5e07d009
commit
b980af6a77
1 changed files with 80 additions and 15 deletions
|
@ -1,4 +1,5 @@
|
|||
// ======================= KeySnail Init File ======================== //
|
||||
/* jshint moz: true */
|
||||
/*global key plugins hook command util gBrowser _content goDoCommand
|
||||
* KeySnail KeyEvent userscript ext openHelpLink
|
||||
* BrowserCloseTabOrWindow closeWindow undoCloseTab OpenBrowserWindow
|
||||
|
@ -545,18 +546,30 @@ key.setViewKey([':', 't'], function (ev, arg) {
|
|||
|
||||
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);
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
|
||||
bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder, uri,
|
||||
bmsvc.DEFAULT_INDEX, bookmark.title);
|
||||
taggingSvc.tagURI(uri, tags.split(',').map(String.trim));
|
||||
const bmService = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]
|
||||
.getService(Ci.nsINavBookmarksService);
|
||||
const ioService = Cc["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService);
|
||||
const tagService = Cc["@mozilla.org/browser/tagging-service;1"]
|
||||
.getService(Ci.nsITaggingService);
|
||||
|
||||
function _saveBookmark(tags, bookmark) {
|
||||
var uri = ioService.newURI(bookmark.url, null, null);
|
||||
|
||||
if (!bmService.isBookmarked(uri)) {
|
||||
bmService.insertBookmark(bmService.bookmarksMenuFolder, uri,
|
||||
bmService.DEFAULT_INDEX, bookmark.title);
|
||||
tagService.tagURI(uri, tags.split(',').map(String.trim));
|
||||
|
||||
display.prettyPrint("Successfully bookmarked \"" + bookmark.title + "\"",
|
||||
{timeout: 3000, fade: 250});
|
||||
} else {
|
||||
display.prettyPrint("Already bookmarked",
|
||||
{timeout: 3000, fade: 250});
|
||||
}
|
||||
}
|
||||
|
||||
function _readTags(url, bookmark) {
|
||||
|
@ -587,10 +600,50 @@ var oni =
|
|||
);
|
||||
}
|
||||
|
||||
var self = {
|
||||
addBookmark: function(arg) {
|
||||
function addBookmark() {
|
||||
_readTitle();
|
||||
}
|
||||
|
||||
function removeBookmark() {
|
||||
var uri = ioService.newURI(window.content.location.href, null, null);
|
||||
|
||||
if (bmService.isBookmarked(uri)) {
|
||||
bmService.getBookmarkIdsForURI(uri, {}).forEach(function(id) {
|
||||
bmService.removeItem(id);
|
||||
});
|
||||
|
||||
display.prettyPrint("Removed bookmark",
|
||||
{timeout: 3000, fade: 250});
|
||||
} else {
|
||||
display.prettyPrint("No bookmark found for this page",
|
||||
{timeout: 3000, fade: 250});
|
||||
}
|
||||
}
|
||||
|
||||
function tagBookmark() {
|
||||
var uri = ioService.newURI(window.content.location.href, null, null);
|
||||
|
||||
|
||||
if (bmService.isBookmarked(uri)) {
|
||||
var tags = tagService.getTagsForURI(uri, {});
|
||||
|
||||
prompt.read("tags:", function(newTags) {
|
||||
tagService.untagURI(uri, tags);
|
||||
tagService.tagURI(uri, newTags.split(',').map(String.trim));
|
||||
|
||||
display.prettyPrint("Retagged bookmark",
|
||||
{timeout: 3000, fade: 250});
|
||||
}, null, null, tags.join(', '));
|
||||
} else {
|
||||
display.prettyPrint("No bookmark found for this page",
|
||||
{timeout: 3000, fade: 250});
|
||||
}
|
||||
}
|
||||
|
||||
var self = {
|
||||
addBookmark: addBookmark,
|
||||
removeBookmark: removeBookmark,
|
||||
tagBookmark: tagBookmark
|
||||
};
|
||||
|
||||
return self;
|
||||
|
@ -598,7 +651,19 @@ var oni =
|
|||
|
||||
ext.add('oni-add-bookmark', function(ev, arg) { oni.addBookmark(arg); },
|
||||
M({en: "oni - Add bookmark"}));
|
||||
ext.add('oni-rm-bookmark', function(ev, arg) { oni.removeBookmark(arg); },
|
||||
M({en: "oni - Remove bookmark"}));
|
||||
ext.add('oni-tag-bookmark', function(ev, arg) { oni.tagBookmark(arg); },
|
||||
M({en: "oni - Tag bookmark"}));
|
||||
|
||||
key.setViewKey([':', 'a'], function(ev, arg) {
|
||||
ext.exec("oni-add-bookmark", arg, ev);
|
||||
}, "Bookmark this page");
|
||||
|
||||
key.setViewKey([':', 'K'], function(ev, arg) {
|
||||
ext.exec("oni-rm-bookmark", arg, ev);
|
||||
}, "Remove the bookmark for this page");
|
||||
|
||||
key.setViewKey([':', 'T'], function(ev, arg) {
|
||||
ext.exec("oni-tag-bookmark", arg, ev);
|
||||
}, "Change the tags for this page");
|
||||
|
|
Loading…
Reference in a new issue