Created
December 7, 2008 15:10
-
-
Save Constellation/33165 to your computer and use it in GitHub Desktop.
userChrome.js: filter on adding bookmark
This file contains hidden or 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
// ==UserScript== | |
// @name place filters | |
// @include main | |
// @include chrome://browser/content/browser.xul | |
// ==/UserScript== | |
(function(){ | |
// folderのcurrentはBookmarkMenuFolder | |
var PSB_filters = [ | |
// { | |
// reg: /^http:\/\/[^\.]+\.tumblr\.com\//, | |
// folder: "Tumblr", | |
// } | |
]; | |
PlacesStarButton.onClick = PSB_onClick = function(aEvent){ | |
var aParent = PSB_filter(getBrowser().selectedBrowser.currentURI); | |
if (aEvent.button == 0) PlacesCommandHook.bookmarkCurrentPage(this._starred, aParent); | |
} | |
function PSB_filter(uri){ | |
var info = null; | |
var spec = uri.spec; | |
if(PSB_filters.some(function(data){ | |
return data.reg.test(spec)? true && (info = data) : false; | |
})){ | |
return info? getFolderByPath(info.folder) : null; | |
} | |
} | |
// expample : start/google | |
var bookmarks = PlacesUtils.bookmarks; | |
function getFolderByPath(path){ | |
var current = bookmarks.bookmarksMenuFolder; | |
path.split('/').forEach(function(name){ | |
var temp = bookmarks.getChildFolder(current, name); | |
if(!temp) current = bookmarks.createFolder(current, name, 0); | |
else current = temp; | |
}); | |
return current; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment