mirror of
https://github.com/bytedream/stream-bypass.git
synced 2026-08-04 21:10:40 +02:00
use host id instead of host in settings
This commit is contained in:
@@ -34,7 +34,7 @@ export default defineBackground(() => {
|
|||||||
const host = await getHost(new URL(details.url).hostname);
|
const host = await getHost(new URL(details.url).hostname);
|
||||||
if (!host) return;
|
if (!host) return;
|
||||||
|
|
||||||
await HostSettings.addTemporaryHostDomain(host, new URL(details.redirectUrl).hostname);
|
await HostSettings.addTemporaryHostDomain(host.id, new URL(details.redirectUrl).hostname);
|
||||||
},
|
},
|
||||||
{ urls: ['<all_urls>'], types: ['main_frame', 'sub_frame'] }
|
{ urls: ['<all_urls>'], types: ['main_frame', 'sub_frame'] }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
<Toggle
|
<Toggle
|
||||||
bind:checked={
|
bind:checked={
|
||||||
() => !disabledHostIds.includes(host.id),
|
() => !disabledHostIds.includes(host.id),
|
||||||
(v) => (v ? HostSettings.removeDisabledHost(host) : HostSettings.addDisabledHost(host))
|
(v) => (v ? HostSettings.removeDisabledHost(host.id) : HostSettings.addDisabledHost(host.id))
|
||||||
}
|
}
|
||||||
size="sm"
|
size="sm"
|
||||||
></Toggle>
|
></Toggle>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export default {
|
|||||||
|
|
||||||
match: async function (match: RegExpMatchArray) {
|
match: async function (match: RegExpMatchArray) {
|
||||||
if (window.location.host.startsWith('filemoon')) {
|
if (window.location.host.startsWith('filemoon')) {
|
||||||
await HostSettings.addTemporaryHostDomain(this, new URL(match[0]).host);
|
await HostSettings.addTemporaryHostDomain(this.id, new URL(match[0]).host);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export default {
|
|||||||
|
|
||||||
match: async function (match: RegExpMatchArray) {
|
match: async function (match: RegExpMatchArray) {
|
||||||
if (this.domains.indexOf(window.location.hostname) !== -1) {
|
if (this.domains.indexOf(window.location.hostname) !== -1) {
|
||||||
await HostSettings.addTemporaryHostDomain(this, window.location.hostname);
|
await HostSettings.addTemporaryHostDomain(this.id, window.location.hostname);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|||||||
+1
-1
@@ -49,7 +49,7 @@ export default {
|
|||||||
|
|
||||||
match: async function (match: RegExpMatchArray) {
|
match: async function (match: RegExpMatchArray) {
|
||||||
if (window.location.host === 'voe.sx') {
|
if (window.location.host === 'voe.sx') {
|
||||||
await HostSettings.addTemporaryHostDomain(this, new URL(match[0]).host);
|
await HostSettings.addTemporaryHostDomain(this.id, new URL(match[0]).host);
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
let json = match[0];
|
let json = match[0];
|
||||||
|
|||||||
+7
-7
@@ -1,5 +1,5 @@
|
|||||||
import { storage } from '#imports';
|
import { storage } from '#imports';
|
||||||
import type { Host, HostId } from '@/lib/host';
|
import type { HostId } from '@/lib/host';
|
||||||
|
|
||||||
class Setting<T> {
|
class Setting<T> {
|
||||||
private item;
|
private item;
|
||||||
@@ -19,14 +19,14 @@ export class HostSettings {
|
|||||||
private static disabledHosts = new Setting<HostId[]>('local:disabledHosts', []);
|
private static disabledHosts = new Setting<HostId[]>('local:disabledHosts', []);
|
||||||
private static allHostsDisabled = new Setting<boolean>('local:allHostsDisabled', false);
|
private static allHostsDisabled = new Setting<boolean>('local:allHostsDisabled', false);
|
||||||
|
|
||||||
static addDisabledHost = (host: Host) =>
|
static addDisabledHost = (hostId: HostId) =>
|
||||||
this.disabledHosts.update((val) => {
|
this.disabledHosts.update((val) => {
|
||||||
if (!val.includes(host.id)) val.push(host.id);
|
if (!val.includes(hostId)) val.push(hostId);
|
||||||
return val;
|
return val;
|
||||||
});
|
});
|
||||||
static removeDisabledHost = (host: Host) =>
|
static removeDisabledHost = (hostId: HostId) =>
|
||||||
this.disabledHosts.update((val) => {
|
this.disabledHosts.update((val) => {
|
||||||
const index = val.indexOf(host.id);
|
const index = val.indexOf(hostId);
|
||||||
if (index !== -1) val.splice(index, 1);
|
if (index !== -1) val.splice(index, 1);
|
||||||
return val;
|
return val;
|
||||||
});
|
});
|
||||||
@@ -38,9 +38,9 @@ export class HostSettings {
|
|||||||
/* tmp */
|
/* tmp */
|
||||||
private static temporaryHostDomain = new Setting<Record<string, string>>('local:temporaryHostDomain', {});
|
private static temporaryHostDomain = new Setting<Record<string, string>>('local:temporaryHostDomain', {});
|
||||||
|
|
||||||
static addTemporaryHostDomain = (host: Host, domain: string) =>
|
static addTemporaryHostDomain = (hostId: HostId, domain: string) =>
|
||||||
this.temporaryHostDomain.update((val) => {
|
this.temporaryHostDomain.update((val) => {
|
||||||
val[domain] = host.id;
|
val[domain] = hostId;
|
||||||
return val;
|
return val;
|
||||||
});
|
});
|
||||||
static checkTemporaryHostDomain = (domain: string) => this.temporaryHostDomain.get().then((val) => val[domain]);
|
static checkTemporaryHostDomain = (domain: string) => this.temporaryHostDomain.get().then((val) => val[domain]);
|
||||||
|
|||||||
Reference in New Issue
Block a user