-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.