Skip to content

Commit

Permalink
rename variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Casheeew committed Dec 20, 2023
1 parent 96321b1 commit 4085f3b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
30 changes: 15 additions & 15 deletions ext/js/background/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export class Backend {
text = text.substring(0, maximumSearchLength);
}
try {
const {tab, created} = await this._getOrCreateSearchPopup();
const {tab, created} = await this._getOrCreateSearchPopupWrapper();
const {id} = tab;
if (typeof id !== 'number') {
throw new Error('Tab does not have an id');
Expand Down Expand Up @@ -799,7 +799,7 @@ export class Backend {

/** @type {import('api').Handler<import('api').GetOrCreateSearchPopupDetails, import('api').GetOrCreateSearchPopupResult>} */
async _onApiGetOrCreateSearchPopup({focus = false, text}) {
const {tab, created} = await this._getOrCreateSearchPopup();
const {tab, created} = await this._getOrCreateSearchPopupWrapper();
if (focus === true || (focus === 'ifCreated' && created)) {
await this._focusTab(tab);
}
Expand Down Expand Up @@ -960,18 +960,18 @@ export class Backend {
const queryParams = {};
if (query.length > 0) { queryParams.query = query; }
const queryString = new URLSearchParams(queryParams).toString();
let url = baseUrl;
let queryUrl = baseUrl;
if (queryString.length > 0) {
url += `?${queryString}`;
queryUrl += `?${queryString}`;
}

/** @type {import('backend').FindTabsPredicate} */
const predicate = ({url: url2}) => {
if (url2 === null || !url2.startsWith(baseUrl)) { return false; }
const parsedUrl = new URL(url2);
const baseUrl2 = `${parsedUrl.origin}${parsedUrl.pathname}`;
const mode2 = parsedUrl.searchParams.get('mode');
return baseUrl2 === baseUrl && (mode2 === mode || (!mode2 && mode === 'existingOrNewTab'));
const predicate = ({url}) => {
if (url === null || !url.startsWith(baseUrl)) { return false; }
const parsedUrl = new URL(url);
const parsedBaseUrl = `${parsedUrl.origin}${parsedUrl.pathname}`;
const parsedMode = parsedUrl.searchParams.get('mode');
return parsedBaseUrl === baseUrl && (parsedMode === mode || (!parsedMode && mode === 'existingOrNewTab'));
};

const openInTab = async () => {
Expand All @@ -997,10 +997,10 @@ export class Backend {
} catch (e) {
// NOP
}
await this._createTab(url);
await this._createTab(queryUrl);
return;
case 'newTab':
await this._createTab(url);
await this._createTab(queryUrl);
return;
}
}
Expand Down Expand Up @@ -1072,9 +1072,9 @@ export class Backend {
/**
* @returns {Promise<{tab: chrome.tabs.Tab, created: boolean}>}
*/
_getOrCreateSearchPopup() {
_getOrCreateSearchPopupWrapper() {
if (this._searchPopupTabCreatePromise === null) {
const promise = this._getOrCreateSearchPopup2();
const promise = this._getOrCreateSearchPopup();
this._searchPopupTabCreatePromise = promise;
promise.then(() => { this._searchPopupTabCreatePromise = null; });
}
Expand All @@ -1084,7 +1084,7 @@ export class Backend {
/**
* @returns {Promise<{tab: chrome.tabs.Tab, created: boolean}>}
*/
async _getOrCreateSearchPopup2() {
async _getOrCreateSearchPopup() {
// Use existing tab
const baseUrl = chrome.runtime.getURL('/search.html');
/**
Expand Down
6 changes: 3 additions & 3 deletions ext/js/display/display-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -882,13 +882,13 @@ export class DisplayGenerator {
_appendFurigana(container, term, reading, addText) {
container.lang = 'ja';
const segments = this._japaneseUtil.distributeFurigana(term, reading);
for (const {text, reading: reading2} of segments) {
if (reading2) {
for (const {text, reading: furigana} of segments) {
if (furigana) {
const ruby = document.createElement('ruby');
const rt = document.createElement('rt');
addText(ruby, text);
ruby.appendChild(rt);
rt.appendChild(document.createTextNode(reading2));
rt.appendChild(document.createTextNode(furigana));
container.appendChild(ruby);
} else {
addText(container, text);
Expand Down
1 change: 1 addition & 0 deletions ext/js/display/query-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ export class QueryParser extends EventDispatcher {
}

/**
* Convert _reading_ to hiragana, katakana, or romaji, or _term_ if it is entirely kana and _reading_ is an empty string, based on _readingMode.
* @param {string} term
* @param {string} reading
* @returns {string}
Expand Down
8 changes: 4 additions & 4 deletions ext/js/templates/sandbox/anki-template-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ export class AnkiTemplateRenderer {
/** @type {import('template-renderer').HelperFunction<string>} */
_furigana(args, context, options) {
const {expression, reading} = this._getFuriganaExpressionAndReading(args, context, options);
const segs = this._japaneseUtil.distributeFurigana(expression, reading);
const segments = this._japaneseUtil.distributeFurigana(expression, reading);

let result = '';
for (const {text, reading: reading2} of segs) {
for (const {text, reading: reading2} of segments) {
const safeText = this._escape(text);
const safeReading = this._escape(reading2);
if (safeReading.length > 0) {
Expand All @@ -190,10 +190,10 @@ export class AnkiTemplateRenderer {
/** @type {import('template-renderer').HelperFunction<string>} */
_furiganaPlain(args, context, options) {
const {expression, reading} = this._getFuriganaExpressionAndReading(args, context, options);
const segs = this._japaneseUtil.distributeFurigana(expression, reading);
const segments = this._japaneseUtil.distributeFurigana(expression, reading);

let result = '';
for (const {text, reading: reading2} of segs) {
for (const {text, reading: reading2} of segments) {
if (reading2.length > 0) {
if (result.length > 0) { result += ' '; }
result += `${text}[${reading2}]`;
Expand Down

0 comments on commit 4085f3b

Please sign in to comment.