diff --git a/JS/browserChromeBookmarkKeywords.uc.js b/JS/browserChromeBookmarkKeywords.uc.js index 6f5880c..728c87e 100644 --- a/JS/browserChromeBookmarkKeywords.uc.js +++ b/JS/browserChromeBookmarkKeywords.uc.js @@ -1,6 +1,6 @@ // ==UserScript== // @name Browser Chrome Bookmark Keywords -// @version 1.1.2 +// @version 1.1.3 // @author aminomancer // @homepage https://github.com/aminomancer/uc.css.js // @description Allow the creation of special keyword bookmarks with @@ -116,13 +116,15 @@ function init() { const lazy = {}; XPCOMUtils.defineLazyModuleGetters(lazy, { - UrlbarUtils: "resource:///modules/UrlbarUtils.jsm", - UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm", - UrlbarProvidersManager: "resource:///modules/UrlbarProvidersManager.jsm", - ExtensionSearchHandler: "resource://gre/modules/ExtensionSearchHandler.jsm", PartnerLinkAttribution: "resource:///modules/PartnerLinkAttribution.jsm", CONTEXTUAL_SERVICES_PING_TYPES: "resource:///modules/PartnerLinkAttribution.jsm", }); + ChromeUtils.defineESModuleGetters(lazy, { + UrlbarUtils: "resource:///modules/UrlbarUtils.sys.mjs", + UrlbarPrefs: "resource:///modules/UrlbarPrefs.sys.mjs", + UrlbarProvidersManager: "resource:///modules/UrlbarProvidersManager.sys.mjs", + ExtensionSearchHandler: "resource://gre/modules/ExtensionSearchHandler.sys.mjs", + }); const UrlbarProvidersManager = gURLBar.view.controller.manager; @@ -171,9 +173,13 @@ if (UrlbarProviderBookmarkKeywords.BCBK_modified) return; const { KeywordUtils } = ChromeUtils.import("resource://gre/modules/KeywordUtils.jsm"); - const { UrlbarProvider } = ChromeUtils.import("resource:///modules/UrlbarUtils.jsm"); - const { UrlbarTokenizer } = ChromeUtils.import("resource:///modules/UrlbarTokenizer.jsm"); - const { UrlbarResult } = ChromeUtils.import("resource:///modules/UrlbarResult.jsm"); + const { UrlbarProvider } = ChromeUtils.importESModule( + "resource:///modules/UrlbarUtils.sys.mjs" + ); + const { UrlbarTokenizer } = ChromeUtils.importESModule( + "resource:///modules/UrlbarTokenizer.sys.mjs" + ); + const { UrlbarResult } = ChromeUtils.importESModule("resource:///modules/UrlbarResult.sys.mjs"); UrlbarProvidersManager.unregisterProvider(UrlbarProviderBookmarkKeywords); class BrowserChromeBookmarkKeywords extends UrlbarProvider { diff --git a/JS/extensionStylesheetLoader.uc.js b/JS/extensionStylesheetLoader.uc.js index 1dac987..1045402 100644 --- a/JS/extensionStylesheetLoader.uc.js +++ b/JS/extensionStylesheetLoader.uc.js @@ -1,6 +1,6 @@ // ==UserScript== // @name Extension Stylesheet Loader -// @version 1.1.0 +// @version 1.1.1 // @author aminomancer // @homepage https://github.com/aminomancer // @description Allows users to share stylesheets for webextensions without @@ -53,7 +53,7 @@ class ExtensionStylesheetLoader { type: "manifest", }); this.childFile = await this.createTempFile( - `"use strict";const{WebExtensionPolicy}=Cu.getGlobalForObject(Cu);export class ExtensionStylesheetLoaderChild extends JSWindowActorChild{handleEvent(e){let policy=WebExtensionPolicy.getByHostname(this.document.location.hostname);if(policy&&policy.id)this.document.documentElement.setAttribute("uc-extension-id",policy.id)}}`, + `"use strict";const{WebExtensionPolicy}=Cu.getGlobalForObject(Services);export class ExtensionStylesheetLoaderChild extends JSWindowActorChild{handleEvent(e){let policy=WebExtensionPolicy.getByHostname(this.document.location.hostname);if(policy&&policy.id)this.document.documentElement.setAttribute("uc-extension-id",policy.id)}}`, { name: "ExtensionStylesheetLoaderChild", type: "sys.mjs" } ); diff --git a/JS/openLinkInUnloadedTab.uc.js b/JS/openLinkInUnloadedTab.uc.js index 4f70bf0..5d91ba7 100644 --- a/JS/openLinkInUnloadedTab.uc.js +++ b/JS/openLinkInUnloadedTab.uc.js @@ -66,11 +66,9 @@ const unloadedTabMenuL10n = { class UnloadedTabMenuBase { constructor() { - if (!window.E10SUtils) - XPCOMUtils.defineLazyModuleGetters(this, { - E10SUtils: `resource://gre/modules/E10SUtils.jsm`, - }); - else this.E10SUtils = window.E10SUtils; + XPCOMUtils.defineLazyModuleGetters(this, { + E10SUtils: `resource://gre/modules/E10SUtils.jsm`, + }); this.useLinkPref = `userChrome.openLinkInUnloadedTab.use_link_text_as_tab_title_when_unknown`; this.initPref(this.useLinkPref, true); diff --git a/JS/searchSelectionShortcut.uc.js b/JS/searchSelectionShortcut.uc.js index dd7f44d..36e6877 100644 --- a/JS/searchSelectionShortcut.uc.js +++ b/JS/searchSelectionShortcut.uc.js @@ -1,6 +1,6 @@ // ==UserScript== // @name Search Selection Keyboard Shortcut -// @version 1.7.0 +// @version 1.7.1 // @author aminomancer // @homepage https://github.com/aminomancer // @description Adds a new keyboard shortcut (Ctrl+Shift+F) that searches your default search @@ -143,7 +143,7 @@ class SearchSelectionShortcut { // it assumes you don't want to keep an empty tab around, so it'll open the // search/link in the current tab. this.parentFile = await this.createTempFile( - `"use strict";import{XPCOMUtils}from"resource://gre/modules/XPCOMUtils.sys.mjs";const lazy={};XPCOMUtils.defineLazyModuleGetters(lazy,{BrowserWindowTracker:"resource:///modules/BrowserWindowTracker.jsm",PrivateBrowsingUtils:"resource://gre/modules/PrivateBrowsingUtils.jsm",E10SUtils:"resource://gre/modules/E10SUtils.jsm"});XPCOMUtils.defineLazyPreferenceGetter(lazy,"CUSTOM_MATCHES","userChrome.searchSelectionShortcut.custom-matches","{}",null,(val=>JSON.parse(val)));const{WebExtensionPolicy}=Cu.getGlobalForObject(Cu);const schemes=/^http|https|ftp$/;const base=host=>{let domain;try{domain=Services.eTLD.getBaseDomainFromHost(host)}catch(e){}return domain};export class SearchSelectionShortcutParent extends JSWindowActorParent{get browser(){return this.browsingContext.top.embedderElement}getEngineTemplate(e){const engineURL=e._getURLOfType("text/html");return engineURL.params.length>0?e._searchForm:engineURL.template}async getMatchingEngine(match,url,host,check=true){if(!match)return null;let preferred;let uri=Services.io.newURI(url);if(check){if(url in lazy.CUSTOM_MATCHES)preferred=lazy.CUSTOM_MATCHES[url];if(!preferred&&host in lazy.CUSTOM_MATCHES)preferred=lazy.CUSTOM_MATCHES[host];if(!preferred&&!host){try{preferred=lazy.CUSTOM_MATCHES[uri.prePath+uri.filePath]}catch(e){}}if(preferred){const engine=Services.search.getEngineByName(preferred);if(engine&&!engine.hidden)return engine}}const visibleEngines=await Services.search.getVisibleEngines();let originalHost;if(preferred&&/.+\\..+/.test(preferred)){originalHost=host;host=preferred}let engines=visibleEngines.filter((engine=>engine.getResultDomain()==host));if(!engines.length){const baseHost=base(host);if(baseHost||!preferred)engines=visibleEngines.filter((engine=>base(engine.getResultDomain())==baseHost))}if(originalHost&&!engines.length){try{const fixup=Services.uriFixup.getFixupURIInfo(preferred,Ci.nsIURIFixup.FIXUP_FLAG_FIX_SCHEME_TYPOS);uri=fixup.fixedURI;engines=visibleEngines.filter((engine=>engine.getResultDomain()==uri.host))}catch(e){}if(!engines.length)return this.getMatchingEngine(match,url,originalHost,false)}if(engines.length>1){engines.sort(((a,b)=>{const uriA=Services.io.newURI(this.getEngineTemplate(a)),uriB=Services.io.newURI(this.getEngineTemplate(b)),cmnA=this.commonLength(uri,uriA),cmnB=this.commonLength(uri,uriB);return cmnB.host-cmnA.host||cmnB.path-cmnA.path||cmnB.query-cmnA.query}))}return engines[0]}commonLength(x,y){if(!(x?.spec&&y?.spec))return 0;let xh="",yh="";try{xh=x.host}catch(e){}try{yh=y.host}catch(e){}let xf=x.filePath,yf=y.filePath,xs=x.scheme,ys=y.scheme||"https",xq=x.query,yq=y.query,i=0,k=0,len=xh.length,sq="";if(xs!=ys&&!(schemes.test(xs)&&schemes.test(ys)))return 0;while(k{if(p.endsWith("{searchTerms}")){qp=p.replace(/{searchTerms}/,"");return}return true}));xa=xa.filter((p=>!(qp&&p.startsWith(qp))));sq=xa.filter((p=>ya.includes(p)))}return{host:xh.substring(len-k,len).length,path:xf.substring(0,i).length,query:sq.length}}stripURLPrefix(str){const match=/^[a-z]+:(?:\\/){0,2}/i.exec(str);if(!match)return["",str];let prefix=match[0];if(prefix.lengthJSON.parse(val)));const{WebExtensionPolicy}=Cu.getGlobalForObject(Services);const schemes=/^http|https|ftp$/;const base=host=>{let domain;try{domain=Services.eTLD.getBaseDomainFromHost(host)}catch(e){}return domain};export class SearchSelectionShortcutParent extends JSWindowActorParent{get browser(){return this.browsingContext.top.embedderElement}getEngineTemplate(e){const engineURL=e._getURLOfType("text/html");return engineURL.params.length>0?e._searchForm:engineURL.template}async getMatchingEngine(match,url,host,check=true){if(!match)return null;let preferred;let uri=Services.io.newURI(url);if(check){if(url in lazy.CUSTOM_MATCHES)preferred=lazy.CUSTOM_MATCHES[url];if(!preferred&&host in lazy.CUSTOM_MATCHES)preferred=lazy.CUSTOM_MATCHES[host];if(!preferred&&!host){try{preferred=lazy.CUSTOM_MATCHES[uri.prePath+uri.filePath]}catch(e){}}if(preferred){const engine=Services.search.getEngineByName(preferred);if(engine&&!engine.hidden)return engine}}const visibleEngines=await Services.search.getVisibleEngines();let originalHost;if(preferred&&/.+\\..+/.test(preferred)){originalHost=host;host=preferred}let engines=visibleEngines.filter((engine=>engine.getResultDomain()==host));if(!engines.length){const baseHost=base(host);if(baseHost||!preferred)engines=visibleEngines.filter((engine=>base(engine.getResultDomain())==baseHost))}if(originalHost&&!engines.length){try{const fixup=Services.uriFixup.getFixupURIInfo(preferred,Ci.nsIURIFixup.FIXUP_FLAG_FIX_SCHEME_TYPOS);uri=fixup.fixedURI;engines=visibleEngines.filter((engine=>engine.getResultDomain()==uri.host))}catch(e){}if(!engines.length)return this.getMatchingEngine(match,url,originalHost,false)}if(engines.length>1){engines.sort(((a,b)=>{const uriA=Services.io.newURI(this.getEngineTemplate(a)),uriB=Services.io.newURI(this.getEngineTemplate(b)),cmnA=this.commonLength(uri,uriA),cmnB=this.commonLength(uri,uriB);return cmnB.host-cmnA.host||cmnB.path-cmnA.path||cmnB.query-cmnA.query}))}return engines[0]}commonLength(x,y){if(!(x?.spec&&y?.spec))return 0;let xh="",yh="";try{xh=x.host}catch(e){}try{yh=y.host}catch(e){}let xf=x.filePath,yf=y.filePath,xs=x.scheme,ys=y.scheme||"https",xq=x.query,yq=y.query,i=0,k=0,len=xh.length,sq="";if(xs!=ys&&!(schemes.test(xs)&&schemes.test(ys)))return 0;while(k{if(p.endsWith("{searchTerms}")){qp=p.replace(/{searchTerms}/,"");return}return true}));xa=xa.filter((p=>!(qp&&p.startsWith(qp))));sq=xa.filter((p=>ya.includes(p)))}return{host:xh.substring(len-k,len).length,path:xf.substring(0,i).length,query:sq.length}}stripURLPrefix(str){const match=/^[a-z]+:(?:\\/){0,2}/i.exec(str);if(!match)return["",str];let prefix=match[0];if(prefix.length UrlbarUtils.getLogger({ prefix: "MuxerUnifiedComplete" }) ); diff --git a/resources/script-override/findInPage.js b/resources/script-override/findInPage.js index 4aea29a..a1d47f8 100644 --- a/resources/script-override/findInPage.js +++ b/resources/script-override/findInPage.js @@ -38,6 +38,8 @@ var gSearchResultsPane = { // A (node -> boolean) map of subitems to be made visible or hidden. subItems: new Map(), + searchResultsHighlighted: false, + init() { if (this.inited) { return; @@ -212,6 +214,8 @@ var gSearchResultsPane = { range.setStart(startNode, startValue); range.setEnd(endNode, endValue); this.getFindSelection(startNode.ownerGlobal).addRange(range); + + this.searchResultsHighlighted = true; } return !!indices.length; @@ -250,9 +254,12 @@ var gSearchResultsPane = { .QueryInterface(Ci.nsIInterfaceRequestor) .getInterface(Ci.nsISelectionDisplay) .QueryInterface(Ci.nsISelectionController); - let selection = controller.getSelection(Ci.nsISelectionController.SELECTION_FIND); + let selection = controller.getSelection( + Ci.nsISelectionController.SELECTION_FIND + ); selection.setColors("white", this.hex, "white", this.hex); + return selection; }, @@ -718,7 +725,10 @@ var gSearchResultsPane = { * a search to another preference category. */ removeAllSearchIndicators(window, showSubItems) { - this.getFindSelection(window).removeAllRanges(); + if (this.searchResultsHighlighted) { + this.getFindSelection(window).removeAllRanges(); + this.searchResultsHighlighted = false; + } this.removeAllSearchTooltips(); this.removeAllSearchMenuitemIndicators(); @@ -727,9 +737,8 @@ var gSearchResultsPane = { for (let subItem of this.subItems.keys()) { subItem.classList.remove("visually-hidden"); } + this.subItems.clear(); } - - this.subItems.clear(); }, /**