momo2000
Advanced Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору ((bar, button = false, insertAtTop = true, ctrlFcloseFinbar = false) => ({ init(parent) { var has = bar = parent.querySelector("#appcontent > findbar"); has || this.initFinbar(parent); var lo = bar.linkedObject; lo.listenCtrlF = ctrlFcloseFinbar ? listen => listen ? addEventListener("keydown", lo, true) : removeEventListener("keydown", lo, true) : () => {}; has && !bar.hidden && lo.listenCtrlF(true); if (button) self._handleClick = () => bar.hidden ? bar.startFind(bar.FIND_NORMAL) : bar.collapsed || bar.close(); addDestructor(lo.destroy, lo); }, destroy(reason) { if (reason[5] != "e") return; bar.close(); bar._browser = {}; bar.remove(); this.setProgressListener(false); for(var key of ["gFindBar", "gFindBarInitialized"]) Object.defineProperty(window, key, this[key]); gBrowser[this.gBrKey] = this[this.gBrKey]; Services.ppmm.removeDelayedProcessScript(this.url); Services.ppmm.loadProcessScript("data:," + encodeURIComponent(` Services.appinfo.processType != Services.appinfo.PROCESS_TYPE_DEFAULT && Services.appinfo.processType != Services.appinfo.PROCESS_TYPE_CONTENT || (nsvo => { var proto = nsvo.Finder.prototype; if ("_requestMatchesCount" in proto) { proto.requestMatchesCount = proto._requestMatchesCount; delete proto._requestMatchesCount; } })(Cu.import("resource://gre/modules/Finder.jsm", {}));` ) , false); }, initFinbar(parent) { for(var tab of gBrowser.tabs) { if (!tab._findBar) continue; tab._findBar.browser = null; tab._findBar._browser = {}; tab._findBar.remove(); delete tab._findBar; } bar = document.createElement("findbar"); var p = new Proxy({}, {get: () => () => {}}); bar._browser = {finder: p, messageManager: p}; parent.insertBefore(bar, insertAtTop ? parent.firstChild : null); bar.linkedObject = this; ["gFindBar", "gFindBarInitialized"].forEach((key, ind) => { this[key] = Object.getOwnPropertyDescriptor(window, key); delete window[key]; window[key] = ind ? true : bar; }); var key = "getCachedFindBar" in gBrowser ? "getCachedFindBar" : "getFindBar"; this[this.gBrKey = key] = gBrowser[key]; gBrowser[key] = () => bar; [ "close", "startFind", "onMatchesCountResult", "_updateMatchesCount", "_onBrowserKeypress", "receiveMessage" ].forEach((key, ind) => { var func = bar[key].bind(bar); bar[key] = ind ? (...args) => this[key](...args) || func(...args) : (...args) => func(...args) || this[key](...args); }); this.url = "data:," + encodeURIComponent(` Services.appinfo.processType != Services.appinfo.PROCESS_TYPE_DEFAULT && Services.appinfo.processType != Services.appinfo.PROCESS_TYPE_CONTENT || (nsvo => { var proto = nsvo.Finder.prototype; if ("_requestMatchesCount" in proto) return; proto._requestMatchesCount = proto.requestMatchesCount; proto.requestMatchesCount = ${ this.newRequestMatchesCount } })(Cu.import("resource://gre/modules/Finder.jsm", {}));` ); delete this.newRequestMatchesCount; Services.ppmm.loadProcessScript(this.url, true); }, newRequestMatchesCount: async function requestMatchesCount(aWord, aLinksOnly) { if (typeof aLinksOnly != "boolean") { var {linksOnly, data} = aLinksOnly; aLinksOnly = linksOnly; this.entireWord = data.entireWord; this.caseSensitive = data.caseSensitive; this.onModalHighlightChange(data.useModalHighlight); this.onHighlightAllChange(data.highlightAll); data.highlightAll && await this.highlighter.highlight(true, aWord, linksOnly); this._iterator && this._iterator.reset(); var obj; Object.defineProperty(this, "_currentMatchesCountResult", { configurable: true, enumerable: true, get: (val = obj) => { if (val) { if (!val.total) val.total = new Number(0); val.currentFound = val._currentFound; } return obj = val; }, set: val => { if (val) return obj = val; delete this._currentMatchesCountResult; return obj = this._currentMatchesCountResult = val; } }); var lfr = this._lastFindResult; lfr !== null && lfr != Ci.nsITypeAheadFind.FIND_NOTFOUND || Object.defineProperty(this, "_lastFindResult", { configurable: true, enumerable: true, get: () => null, set: val => { if (val == Ci.nsITypeAheadFind.FIND_WRAPPED) val = Ci.nsITypeAheadFind.FIND_FOUND; delete this._lastFindResult; return this._lastFindResult = val; } }); } this._requestMatchesCount(aWord, aLinksOnly); }, close() { bar.collaped = false; this.setProgressListener(false); this.setBrowser(null, null); }, startFind() { if (this.maybeCollapse(gBrowser.selectedBrowser)) return true; if (bar.hidden) this.setBrowser(300), this.setProgressListener(true); else if (!ctrlFcloseFinbar) setTimeout(() => this.updateMatchesCount(), 100); }, onMatchesCountResult(res) { if (!("currentFound" in res) || res.total == -1 || res.currentFound) return; bar._foundMatches.value = `${+res.total || "Нет"} совпадени${ bar.pluralForm.get(res.total, "е;я;й") }.`; bar._foundMatches.hidden = false; return true; }, _updateMatchesCount() { return true; }, _onBrowserKeypress(e) { if (!bar.hidden) return; if (!e.charCode) return true; this.setBrowser(300); this.setProgressListener(true); }, receiveMessage(msg) { msg.target = bar._browser; }, progressListenerAdded: false, setProgressListener(add) { if (add) { if (this.progressListenerAdded) return; this.progressListenerAdded = true; gBrowser.addProgressListener(this); this.listenCtrlF(true); } else { if (!this.progressListenerAdded) return; this.progressListenerAdded = false; gBrowser.removeProgressListener(this); this.listenCtrlF(false); } }, handleEvent(e) { if ( e.ctrlKey && e.code == "KeyF" && !e.shiftKey && !e.altKey && !bar.collapsed ) e.preventDefault(), e.stopPropagation(), bar.close(); }, updateMatchesCount() { var str = bar._findField.value; if (!str) return; var data = { entireWord: bar._entireWord, caseSensitive: bar._typeAheadCaseSensitive, highlightAll: bar._highlightAll, useModalHighlight: bar._useModalHighlight }; bar.browser.finder.requestMatchesCount( bar._findField.value, {linksOnly: bar._findMode == bar.FIND_LINKS, data} ); }, maybeCollapse(br) { return br.isSyntheticDocument || br.documentContentType == "application/vnd.mozilla.xul+xml"; }, setBrowser(updateDelay, br = gBrowser.selectedBrowser) { if (bar._browser != br) { var b = bar._browser; if (b) { b.messageManager.removeMessageListener("Findbar:Mouseup", bar); b.finder.removeResultListener(bar); bar._highlightAll && b.finder.highlight(false); } if (br) { br.messageManager.addMessageListener("Findbar:Mouseup", bar); bar._updateBrowserWithState(); } bar._browser = br; } if (!br) return; bar._updateStatusUI(); bar._foundMatches.value = ""; br.finder.addResultListener(bar); if ( !(bar.collapsed = this.maybeCollapse(br)) && br.currentURI.spec != "about:blank" && updateDelay !== null ) updateDelay ? setTimeout(this.updateMatchesCount, updateDelay) : this.updateMatchesCount(); }, onStateChange(wpr, req, state) { state & Ci.nsIWebProgressListener.STATE_STOP && this.setBrowser(); }, onLocationChange(wpr, req) { req || Components.stack.formattedStack.includes("SessionStore.jsm") || this.setBrowser(); } }).init(document.getElementById("appcontent")))(); | Всего записей: 1732 | Зарегистр. 14-04-2007 | Отправлено: 09:13 23-01-2020 | Исправлено: momo2000, 09:22 23-01-2020 |
|