Skip to content

Commit

Permalink
新增 Places_ShowBookmarkPath.uc.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ywzhaiqi committed Oct 13, 2014
1 parent f04ba2a commit 2baa3e8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Places_ShowBookmarkPath/Places_ShowBookmarkPath.uc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// ==UserScript==
// @name Places_ShowBookmarkPath.uc.js
// @description 在 "我的足迹" 中右键显示书签路径
// @include chrome://browser/content/places/places.xul
// @version 2014/10/12
// ==/UserScript==

var UC_PlacesShowPath = {
bmsvc: Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"]
.getService(Components.interfaces.nsINavBookmarksService),

init: function() {
var menuitem = document.createElement('menuitem');
menuitem.setAttribute('label', '在文件夹中显示');
menuitem.setAttribute('title', '书签路径');
// menuitem.setAttribute('oncommand', 'UC_PlacesShowPath.getFolders();');

// 插入
var popup = document.getElementById('placesContext');
popup.appendChild(menuitem);

// 显示
var self = this;
popup.addEventListener('popupshowing', function() {
var folders = self.getFolders();
menuitem.setAttribute('label', folders || '');
menuitem.setAttribute('hidden', !folders);
});
},
getFolders: function() {
var node = PlacesUIUtils.getViewForNode(document.popupNode).selectedNode;
if (node && node.itemId >= 0) {
var parentId = node.itemId;
var parents = [];
while(true) {
parentId = this.bmsvc.getFolderIdForItem(parentId);
if (parentId == 0) break;

var parentTitle = this.bmsvc.getItemTitle(parentId);
if (!parentTitle) break;
parents.unshift(parentTitle); // 放到最前面
}

return parents.join('\\');
}
}
};

UC_PlacesShowPath.init();
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2baa3e8

Please sign in to comment.