Skip to content

Commit

Permalink
reuse getHost + code cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
tophf committed Dec 17, 2024
1 parent 4e0c42d commit 9e30433
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/background/sw/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bgPreInit.push(

/**
* This ensures that SW starts even before our page makes a clientData request inside.
* The actual listener may be invoked after `onfetch`, but is may depend on implementation.
* The actual listener is usually invoked after `onfetch`, but there's no guarantee.
*/
chrome.webRequest.onBeforeRequest.addListener(req => {
clientUrls[req.url] = true;
Expand Down
4 changes: 2 additions & 2 deletions src/background/token-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {DNR_ID_IDENTITY, updateDynamicRules} from '/js/dnr';
import {chromeLocal} from '/js/storage-util';
import {FIREFOX} from '/js/ua';
import * as URLS from '/js/urls';
import {clamp} from '/js/util';
import {clamp, getHost} from '/js/util';
import {browserWindows} from '/js/util-webext';
import launchWebAuthFlow from 'webext-launch-web-auth-flow';
import {isVivaldi} from './common';
Expand Down Expand Up @@ -227,7 +227,7 @@ async function authUserMV3(url, interactive, redirectUri) {
type: 'redirect',
redirect: {
transform: {
host: apiUrl.split('/')[2],
host: getHost(apiUrl),
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/background/usercss-install-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {kContentType, kMainFrame} from '/js/consts';
import {DNR_ID_INSTALLER, updateDynamicRules} from '/js/dnr';
import * as prefs from '/js/prefs';
import * as URLS from '/js/urls';
import {RX_META} from '/js/util';
import {getHost, RX_META} from '/js/util';
import {FIREFOX} from '/js/ua';
import {bgBusy, safeTimeout} from './common';
import download from './download';
Expand Down Expand Up @@ -44,7 +44,7 @@ function toggle(key, val) {
: /^.*\.user\.css$/).source,
requestDomains: val
? undefined
: [...new Set(urls.map(u => u.split('/')[2]))],
: [...new Set(urls.map(getHost))],
resourceTypes: [kMainFrame],
responseHeaders: [{
header: kContentType,
Expand Down
4 changes: 2 additions & 2 deletions src/js/themer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {MF_ICON_EXT, MF_ICON_PATH} from './util-webext';
import '/css/global.css';
import '/css/global-dark.css';

export const isDarkChanged = new Set();
export const onDarkChanged = new Set();
export const MEDIA_ON = 'screen';
export const MEDIA_OFF = 'not all';
const MEDIA_NAME = 'dark';
Expand Down Expand Up @@ -51,5 +51,5 @@ function updateDOM() {
m.mediaText = `${isDark ? MEDIA_ON : MEDIA_OFF},${MEDIA_NAME}`;
}
});
for (const fn of isDarkChanged) fn(isDark);
for (const fn of onDarkChanged) fn(isDark);
}
4 changes: 2 additions & 2 deletions src/popup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {getEventKeyName, setupLivePrefs} from '/js/dom-util';
import {t, template} from '/js/localization';
import {API, onExtension} from '/js/msg';
import * as prefs from '/js/prefs';
import {isDark, isDarkChanged} from '/js/themer';
import {isDark, onDarkChanged} from '/js/themer';
import {CHROME, FIREFOX, MOBILE, OPERA} from '/js/ua';
import {ownRoot} from '/js/urls';
import {capitalize, clamp, clipString, isEmptyObj, sleep, stringAsRegExpStr} from '/js/util';
Expand Down Expand Up @@ -38,7 +38,7 @@ export const $entry = styleOrId => $(`#${ENTRY_ID_PREFIX_RAW}${styleOrId.id || s
onExtension(onRuntimeMessage);

updateStateIcon(isDark);
isDarkChanged.add(val => updateStateIcon(val, null));
onDarkChanged.add(val => updateStateIcon(val, null));

prefs.subscribe('popup.stylesFirst', (key, stylesFirst) => {
$.rootCL.toggle('styles-first', stylesFirst);
Expand Down

0 comments on commit 9e30433

Please sign in to comment.