// Открыть или переключиться на окно "Библиотеки" на кнопке и закрывать "Библиотеки" по двойному-клику --> (obs => { this._handleClick = () => { const libraryWin = Services.wm.getMostRecentWindow('Places:Organizer'); if (libraryWin) Services.focus.focusedWindow = libraryWin; else PlacesCommandHook.showPlacesOrganizer(); }; Services.obs.addObserver(obs, 'domwindowopened'); addDestructor(() => Services.obs.removeObserver(obs, 'domwindowopened')); })( { libraryURL: 'chrome://browser/content/places/places.xul' , isLibraryhWin(win) { return win.location && win.location.href == this.libraryURL } , observe(win) { win.addEventListener('load', this) } , handleEvent(e) { const win = e ? e.target.defaultView : content.document.defaultView; win.removeEventListener('load', this) if (!this.isLibraryhWin(win)) return; let targetIsURI; const check = e => { targetIsURI = false; const trNode = e.originalTarget; if (trNode.localName != 'treechildren') return; const tree = trNode.parentNode, tbo = tree.treeBoxObject, cell = tbo.getCellAt(e.clientX, e.clientY); if (cell.row == -1) return; const node = tree.view.nodeForTreeIndex(cell.row); targetIsURI = node.type == 0 }, close = () => { targetIsURI && win.close() }, unload = () => { win.removeEventListener('mousedown', check); win.removeEventListener('dblclick', close, true); win.removeEventListener('unload', unload) }; win.addEventListener('mousedown', check); win.addEventListener('dblclick', close, true); win.addEventListener('unload', unload); } } ); // <-- Открыть или переключиться на окно "Библиотеки" на кнопке и закрывать "Библиотеки" по двойному-клику |