parent
							
								
									440a9f4763
								
							
						
					
					
						commit
						18265b94c6
					
				|  | @ -1,5 +1,5 @@ | |||
| /* global API msg */// msg.js
 | ||||
| /* global CHROME URLS stringAsRegExp tryRegExp */// toolbox.js
 | ||||
| /* global CHROME URLS stringAsRegExp tryRegExp tryURL */// toolbox.js
 | ||||
| /* global bgReady compareRevision */// common.js
 | ||||
| /* global calcStyleDigest styleCodeEmpty styleSectionGlobal */// sections-util.js
 | ||||
| /* global db */ | ||||
|  | @ -607,14 +607,14 @@ const styleMan = (() => { | |||
|       }, | ||||
|       get urlWithoutParams() { | ||||
|         if (!urlWithoutParams) { | ||||
|           const u = createURL(url); | ||||
|           const u = tryURL(url); | ||||
|           urlWithoutParams = u.origin + u.pathname; | ||||
|         } | ||||
|         return urlWithoutParams; | ||||
|       }, | ||||
|       get domain() { | ||||
|         if (!domain) { | ||||
|           const u = createURL(url); | ||||
|           const u = tryURL(url); | ||||
|           domain = u.hostname; | ||||
|         } | ||||
|         return domain; | ||||
|  | @ -634,27 +634,6 @@ const styleMan = (() => { | |||
|     } | ||||
|   } | ||||
| 
 | ||||
|   function createURL(url) { | ||||
|     try { | ||||
|       return new URL(url); | ||||
|     } catch (err) { | ||||
|       return { | ||||
|         hash: '', | ||||
|         host: '', | ||||
|         hostname: '', | ||||
|         href: '', | ||||
|         origin: '', | ||||
|         password: '', | ||||
|         pathname: '', | ||||
|         port: '', | ||||
|         protocol: '', | ||||
|         search: '', | ||||
|         searchParams: new URLSearchParams(), | ||||
|         username: '', | ||||
|       }; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   function uuidv4() { | ||||
|     const seeds = crypto.getRandomValues(new Uint16Array(8)); | ||||
|     // 00001111-2222-M333-N444-555566667777
 | ||||
|  |  | |||
|  | @ -11,8 +11,8 @@ | |||
|   debounce | ||||
|   getOwnTab | ||||
|   sessionStore | ||||
|   tryCatch | ||||
|   tryJSONparse | ||||
|   tryURL | ||||
| */// toolbox.js
 | ||||
| 'use strict'; | ||||
| 
 | ||||
|  | @ -74,7 +74,7 @@ const baseInit = (() => { | |||
|     const id = Number(params.get('id')); | ||||
|     const style = id && await API.styles.get(id) || { | ||||
|       name: params.get('domain') || | ||||
|         tryCatch(() => new URL(params.get('url-prefix')).hostname) || | ||||
|         tryURL(params.get('url-prefix')).hostname || | ||||
|         '', | ||||
|       enabled: true, | ||||
|       sections: [ | ||||
|  |  | |||
|  | @ -18,6 +18,7 @@ | |||
|   stringAsRegExp | ||||
|   tryCatch | ||||
|   tryRegExp | ||||
|   tryURL | ||||
|   waitForTabUrl | ||||
| */ | ||||
| 
 | ||||
|  | @ -150,13 +151,13 @@ function urlToMatchPattern(url, ignoreSearch) { | |||
| } | ||||
| 
 | ||||
| async function findExistingTab({url, currentWindow, ignoreHash = true, ignoreSearch = false}) { | ||||
|   url = new URL(url); | ||||
|   url = tryURL(url); | ||||
|   const tabs = await browser.tabs.query({ | ||||
|     url: urlToMatchPattern(url, ignoreSearch), | ||||
|     currentWindow, | ||||
|   }); | ||||
|   return tabs.find(tab => { | ||||
|     const tabUrl = new URL(tab.pendingUrl || tab.url); | ||||
|     const tabUrl = tryURL(tab.pendingUrl || tab.url); | ||||
|     return tabUrl.protocol === url.protocol && | ||||
|       tabUrl.username === url.username && | ||||
|       tabUrl.password === url.password && | ||||
|  | @ -282,6 +283,29 @@ function tryJSONparse(jsonString) { | |||
|   } catch (e) {} | ||||
| } | ||||
| 
 | ||||
| function tryURL( | ||||
|   url, | ||||
|   fallback = { | ||||
|     hash: '', | ||||
|     host: '', | ||||
|     hostname: '', | ||||
|     href: '', | ||||
|     origin: '', | ||||
|     password: '', | ||||
|     pathname: '', | ||||
|     port: '', | ||||
|     protocol: '', | ||||
|     search: '', | ||||
|     searchParams: new URLSearchParams(), | ||||
|     username: '', | ||||
|   }) { | ||||
|   try { | ||||
|     return new URL(url); | ||||
|   } catch (e) { | ||||
|     return fallback; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| function debounce(fn, delay, ...args) { | ||||
|   clearTimeout(debounce.timers.get(fn)); | ||||
|   debounce.timers.set(fn, setTimeout(debounce.run, delay, fn, ...args)); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user