代码拉取完成,页面将自动刷新
// ==UserScript==
// @name acBookMarkTreeFolder_Fx37
// @namespace http://www.sephiroth-j.de/mozilla/
// @description Autoclose BookMark Folders
// @include chrome://browser/content/bookmarks/bookmarksPanel.xul
// @include chrome://browser/content/places/bookmarksSidebar.xul
// @compatibility Firefox 66+
// @author original Ronny Perinke
// @version original Autoclose Bookmark History Folders 0.5.5
// @modiffied Alice0775
// @version 2019/01/18 fix for 66(Bug 1482389 - Convert TreeBoxObject to XULTreeElement)
// @version 2019/01/18 fix dark theme
// @version 2018/08/10 fix target scroll listener
// @version 2018/08/13 61+
// @version 2012/12/07 //aEvent.preventDefault();
// @Note http://space.geocities.yahoo.co.jp/gl/alice0775
// @Note I got permission to open this script to the public from Mr.Sephiroth on July 28,2007.
// ==/UserScript==
// @version 2008/11/28 Firefox3.1b3pre tboの初期化に時間が掛かるようでsetTimeoutするようにした
// @version 2007/12/09 21:00
/* ***** BEGIN LICENSE BLOCK *****
* Author: Ronny Perinke http://www.sephiroth-j.de
*
* License: This extension is subject to MPL 1.1/GPL 2.0/LGPL 2.1
* You may obtain a copy of the License at http://www.mozilla.org/MPL/ and http://www.gnu.org/copyleft/gpl.html
* other rules:
* 1) If you use any of this code please include references or credit in your code to myself, and include my homepage URL
* 2) You MUST contact me, the author before you use this code (I like to know that it's been usefull).
* 3) I would greatly appreciate a link back to me or credit somewhere on your site (makes me feel good, not required).
* 4) If improvments are made to the code, please inform me so that I can use it (if applicable, not required).
* 5) Translators: please contact me and send me a copy of the language files and/or the new xpi with the new language.
* I'd like to include them in the official xpi on my server. You will list you in the contributors list.
*
* ***** END LICENSE BLOCK ***** */
var acBookMarkTreeFolder = {
_Prefs: {
ScrollToRow : true, //次回サイドバーオープン時に現在のスクロール状態を出来るだけ再現
SelectLast : true //次回サイドバーオープン時に現在開いているフォルダを開いてフォーカスする
},
kPrefROWPOSITION: "ac-BookMarkTreeFolder.lastBookmarkFolder",
kPrefFOLDER: "ac-BookMarkTreeFolder.lastSelectedBookmarkID",
get _BTree() {
return document.getElementById("bookmarks-view");
},
init: function(){
if (!this._BTree)
return;
document.addEventListener('unload', this, false);
this._BTree.addEventListener('click', this, false);
//this._BTree.addEventListener('dragover',function(event){acBookMarkTreeFolder.onClick(event);},false);
(document.getElementById("bookmarks-view-children") ||
document.getElementById("bookmarks-view").childNodes[1])
.addEventListener("scroll", this, false);
this.loadPrefs();
this.addToolbar();
if (this._BTree.result && this._Prefs.SelectLast) {
var itemId = this.getPref(this.kPrefFOLDER, "int", -1);
if (itemId != -1) {
this._BTree.selectItems([itemId], false);
}
try {
var pos = this.getPref(this.kPrefROWPOSITION,"int",0);
if (this._BTree && this._BTree.view.rowCount >= pos && this._Prefs.ScrollToRow){
this._BTree.scrollToRow(pos);
}
} catch(e) {}
}
},
uninit: function(){
this._BTree.removeEventListener('click', this, false);
//this._BTree.removeEventListener('dragover',function(event){acBookMarkTreeFolder.onClick(event);},false);
document.getElementById("bookmarks-view-children").removeEventListener("scroll", this, false);
},
loadPrefs: function(){
this._Prefs.SelectLast = this.getPref("ac-BookMarkTreeFolder.ReselectLastFolder","bool",this._Prefs.SelectLast);
this._Prefs.ScrollToRow = this.getPref("ac-BookMarkTreeFolder.ScrollToLastFolder","bool",this._Prefs.ScrollToRow);
},
handleEvent: function(aEvent){
switch(aEvent.type) {
case 'scroll':
this.onScroll();
break;
case 'click':
this.onClick(aEvent);
break;
case 'unload':
this.uninit();
break;
}
},
_stimer: false,
onScroll: function(){
if (this._stimer)
return;
this._stimer = true;
setTimeout(function(){this._stimer = false;}.bind(this), 50, this);
var getRow = this._BTree.getFirstVisibleRow();
this.setPref(this.kPrefROWPOSITION, 'int', getRow);
},
addToolbar: function(){
const kXULNS =
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var toolbar = document.getElementById("acBookMarkTreeFolder-toolbar");
if (toolbar){
return;
}
var toolbox = document.createElementNS(kXULNS, "toolbox");
toolbox.setAttribute("style", "-moz-appearance: none;");
toolbar = document.createElementNS(kXULNS, "toolbar");
toolbar.setAttribute("id", "acBookMarkTreeFolder-toolbar");
var closeAllButton = document.createElementNS(kXULNS, "toolbarbutton");
closeAllButton.setAttribute("label", "\u6298\u7573");//折畳
closeAllButton.setAttribute("oncommand", "acBookMarkTreeFolder.closeAll();");
var openAllButton = document.createElementNS(kXULNS, "toolbarbutton");
openAllButton.setAttribute("label", "\u5c55\u958b");//展開
openAllButton.setAttribute("oncommand", "acBookMarkTreeFolder.openAll();");
toolbar.appendChild(closeAllButton);
toolbar.appendChild(openAllButton);
toolbox.appendChild(toolbar);
this._BTree.parentNode.insertBefore(toolbox, this._BTree);
return;
},
onClick: function(aEvent){
var parents = new Array();
var aView = this._BTree.view;
if (aEvent.button != 0 && aEvent.type !="dragover"){
if (this._BTree.selectedNode && 'itemId' in this._BTree.selectedNode)
this.setPref(this.kPrefFOLDER, "int", this._BTree.selectedNode.itemId);
else
this.setPref(this.kPrefFOLDER, "int", -1);
return;
}
let cell = this._BTree.getCellAt(aEvent.clientX, aEvent.clientY);
if (cell.row == -1)
return;
//alert(this._BTree.selectedNode.itemId);
if (this._BTree.selectedNode && 'itemId' in this._BTree.selectedNode)
this.setPref(this.kPrefFOLDER, "int", this._BTree.selectedNode.itemId);
else
this.setPref(this.kPrefFOLDER, "int", -1);
if(!aView.isContainer(cell.row))
return;
if (this._BTree.currentIndex != cell.row){
return;
}
aView.selection.select(this._BTree.currentIndex);
for (var i = this._BTree.currentIndex; i != -1; i = aView.getParentIndex(i)){
parents.push(i);
}
parents.reverse();
for (var i = aView.rowCount - 1; i >= 0; i--){
if (i == parents[parents.length - 1]){
parents.pop();
}else{
if (aView.isContainer(i) && aView.isContainerOpen(i)){
aView.toggleOpenState(i);
}
}
}
this._BTree.ensureRowIsVisible(this._BTree.currentIndex);
//aEvent.preventDefault();
},
closeAll: function(){
var aView = this._BTree.view;
if (aView){
for (var i = aView.rowCount-1; i>=0; i--){
if (aView.isContainer(i) && aView.isContainerOpen(i)) aView.toggleOpenState(i);
}
}
},
openAll: function(){
var aView = this._BTree.view;
if (aView){
var oldrows = -1;
var rows = aView.rowCount;
do{
for (var i = rows-1; i>=0; i--){
if (aView.isContainer(i) && !aView.isContainerOpen(i)) aView.toggleOpenState(i);
}
oldrows = rows;
rows = aView.rowCount;
}
while(rows != oldrows);
}
},
clearPref: function(aPrefString){
var xpPref = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefBranch);
xpPref.clearUserPref(aPrefString);
},
getPref: function(aPrefString, aPrefType, aDefault){
var xpPref = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefBranch);
try{
switch (aPrefType){
case 'complex':
return xpPref.getComplexValue(aPrefString, Components.interfaces.nsIFile); break;
case 'str':
return xpPref.getCharPref(aPrefString).toString(); break;
case 'int':
return xpPref.getIntPref(aPrefString); break;
case 'bool':
default:
return xpPref.getBoolPref(aPrefString); break;
}
}catch(e){
}
return aDefault;
},
setPref: function(aPrefString, aPrefType, aValue){
var xpPref = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefBranch);
try{
switch (aPrefType){
case 'complex':
return xpPref.setComplexValue(aPrefString, Components.interfaces.nsIFile, aValue); break;
case 'str':
return xpPref.setCharPref(aPrefString, aValue); break;
case 'int':
aValue = parseInt(aValue);
return xpPref.setIntPref(aPrefString, aValue); break;
case 'bool':
default:
return xpPref.setBoolPref(aPrefString, aValue); break;
}
}catch(e){
}
return null;
}
}
acBookMarkTreeFolder.init();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。