From a7c8f22d92005da2332b88bf5a9721fa791c7902 Mon Sep 17 00:00:00 2001 From: "YUKI \"Piro\" Hiroshi" Date: Wed, 5 May 2021 18:32:50 +0900 Subject: [PATCH] Fix indent --- webextensions/background/uriMatcher.js | 146 ++++++++++++------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/webextensions/background/uriMatcher.js b/webextensions/background/uriMatcher.js index efe6736..f5e65eb 100644 --- a/webextensions/background/uriMatcher.js +++ b/webextensions/background/uriMatcher.js @@ -9,28 +9,28 @@ var URIMatcher = { matchSingle: async function(params) { log('matchSingle: ', params); try{ - await this.initialized; - this._updateURIRegExp(); - const match = this.matchMaybeURIs(params.text); - if (match.length == 0) - return null; - - for (let maybeURI of match) { - maybeURI = this.sanitizeURIString(maybeURI); - const uriRange = await this.findTextRange({ - text: maybeURI, - range: params.cursor, - tabId: params.tabId - }); - if (!uriRange) - continue; - return { - text: maybeURI, - range: uriRange, - uri: this.fixupURI(maybeURI, params.baseURI) - }; - } - log(' => no match'); + await this.initialized; + this._updateURIRegExp(); + const match = this.matchMaybeURIs(params.text); + if (match.length == 0) + return null; + + for (let maybeURI of match) { + maybeURI = this.sanitizeURIString(maybeURI); + const uriRange = await this.findTextRange({ + text: maybeURI, + range: params.cursor, + tabId: params.tabId + }); + if (!uriRange) + continue; + return { + text: maybeURI, + range: uriRange, + uri: this.fixupURI(maybeURI, params.baseURI) + }; + } + log(' => no match'); } catch(error){ console.error(error); @@ -41,64 +41,64 @@ var URIMatcher = { matchAll: async function(params) { log('matchAll: ', params); try{ - await this.initialized; - params.onProgress && params.onProgress(0); - this._updateURIRegExp(); - const results = []; - const startAt = Date.now(); - - let maxCount = 0; - const uniqueURIs = {}; - for (const range of params.ranges) { - const match = this.matchMaybeURIs(range.text); - if (match.length == 0) { - range.maybeURIs = []; - continue; - } - - const maybeURIs = Array.from(match).map(maybeURI => this.sanitizeURIString(maybeURI)); - range.maybeURIs = []; - for (const maybeURI of maybeURIs) { - const uri = this.fixupURI(maybeURI, params.baseURI); - if (uri in uniqueURIs) + await this.initialized; + params.onProgress && params.onProgress(0); + this._updateURIRegExp(); + const results = []; + const startAt = Date.now(); + + let maxCount = 0; + const uniqueURIs = {}; + for (const range of params.ranges) { + const match = this.matchMaybeURIs(range.text); + if (match.length == 0) { + range.maybeURIs = []; continue; - uniqueURIs[uri] = true; - range.maybeURIs.push({ - original: maybeURI, - uri: uri - }); + } + + const maybeURIs = Array.from(match).map(maybeURI => this.sanitizeURIString(maybeURI)); + range.maybeURIs = []; + for (const maybeURI of maybeURIs) { + const uri = this.fixupURI(maybeURI, params.baseURI); + if (uri in uniqueURIs) + continue; + uniqueURIs[uri] = true; + range.maybeURIs.push({ + original: maybeURI, + uri: uri + }); + } + maxCount += range.maybeURIs.length; } - maxCount += range.maybeURIs.length; - } - let count = 0; - for (const range of params.ranges) { - for (const maybeURI of range.maybeURIs) { - const uriRange = await this.findTextRange({ - text: maybeURI.original, - range: range, - tabId: params.tabId - }); - if (uriRange) { - results.push({ + let count = 0; + for (const range of params.ranges) { + for (const maybeURI of range.maybeURIs) { + const uriRange = await this.findTextRange({ text: maybeURI.original, - range: uriRange, - uri: maybeURI.uri + range: range, + tabId: params.tabId }); + if (uriRange) { + results.push({ + text: maybeURI.original, + range: uriRange, + uri: maybeURI.uri + }); + } + count++; + if (Date.now() - startAt > 250) + params.onProgress && params.onProgress(count / maxCount); + if (count % 100 == 0) + await wait(0); } - count++; - if (Date.now() - startAt > 250) - params.onProgress && params.onProgress(count / maxCount); - if (count % 100 == 0) - await wait(0); } - } - params.onProgress && params.onProgress(1); - results.sort((aA, aB) => - aA.range.startTextNodePos - aB.range.startTextNodePos || - aA.range.startNodePos - aB.range.startNodePos || - aA.range.startOffset - aB.range.startOffset); - log(' => ', results); + params.onProgress && params.onProgress(1); + results.sort((aA, aB) => + aA.range.startTextNodePos - aB.range.startTextNodePos || + aA.range.startNodePos - aB.range.startNodePos || + aA.range.startOffset - aB.range.startOffset); + log(' => ', results); } catch(error){ console.error(error);