Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit c8046a2

Browse files
committed
chore: remove unnecessary code
1 parent c8f1ab7 commit c8046a2

File tree

11 files changed

+709
-775
lines changed

11 files changed

+709
-775
lines changed

src/api/index.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
1-
import './chrome';
2-
import {FilterConfig as Theme, DynamicThemeFix} from '../definitions';
3-
import ThemeEngines from '../generators/theme-engines';
4-
import {createOrUpdateDynamicTheme, removeDynamicTheme} from '../inject/dynamic-theme';
1+
import "./chrome";
2+
import { FilterConfig as Theme, DynamicThemeFix } from "../definitions";
3+
import ThemeEngines from "../generators/theme-engines";
4+
import {
5+
createOrUpdateDynamicTheme,
6+
removeDynamicTheme
7+
} from "../inject/dynamic-theme";
58

69
const defaultTheme: Theme = {
7-
mode: 1,
8-
brightness: 100,
9-
contrast: 100,
10-
grayscale: 0,
11-
sepia: 0,
12-
useFont: false,
13-
fontFamily: '',
14-
textStroke: 0,
15-
engine: ThemeEngines.dynamicTheme,
16-
stylesheet: '',
10+
mode: 1,
11+
brightness: 100,
12+
contrast: 100,
13+
grayscale: 0,
14+
sepia: 0,
15+
engine: ThemeEngines.dynamicTheme,
16+
stylesheet: ""
1717
};
1818

19-
export function enable(themeOptions: Partial<Theme>, fixes: DynamicThemeFix = null, isIFrame = false) {
20-
const theme = {...defaultTheme, ...themeOptions};
19+
export function enable(
20+
themeOptions: Partial<Theme>,
21+
fixes: DynamicThemeFix = null,
22+
isIFrame = false
23+
) {
24+
const theme = { ...defaultTheme, ...themeOptions };
2125

22-
if (theme.engine !== ThemeEngines.dynamicTheme) {
23-
throw new Error('Theme engine is not supported');
24-
}
26+
if (theme.engine !== ThemeEngines.dynamicTheme) {
27+
throw new Error("Theme engine is not supported");
28+
}
2529

26-
createOrUpdateDynamicTheme(theme, fixes, isIFrame);
30+
createOrUpdateDynamicTheme(theme, fixes, isIFrame);
2731
}
2832

2933
export function disable() {
30-
removeDynamicTheme();
34+
removeDynamicTheme();
3135
}

src/background/extension.ts

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ import Messenger from "./messenger";
33
import TabManager from "./tab-manager";
44
import UserStorage from "./user-storage";
55
import {
6-
getFontList,
76
getCommands,
87
setShortcut,
98
canInjectScript
109
} from "./utils/extension-api";
11-
import { isInTimeInterval, getDuration } from "../utils/time";
1210
import { isURLInList, getURLHost, isURLEnabled } from "../utils/url";
1311
import ThemeEngines from "../generators/theme-engines";
1412
import createCSSFilterStylesheet from "../generators/css-filter";
@@ -27,13 +25,10 @@ import {
2725
TabInfo
2826
} from "../definitions";
2927

30-
const AUTO_TIME_CHECK_INTERVAL = getDuration({ seconds: 10 });
31-
3228
export class Extension {
3329
ready: boolean;
3430

3531
config: ConfigManager;
36-
fonts: string[];
3732
messenger: Messenger;
3833
tabs: TabManager;
3934
user: UserStorage;
@@ -52,24 +47,14 @@ export class Extension {
5247
}
5348

5449
isEnabled() {
55-
if (this.user.settings.automation === "time") {
56-
const now = new Date();
57-
return isInTimeInterval(
58-
now,
59-
this.user.settings.time.activation,
60-
this.user.settings.time.deactivation
61-
);
62-
}
6350
return this.user.settings.enabled;
6451
}
6552

6653
private awaiting: (() => void)[];
6754

6855
async start() {
6956
await this.config.load({ local: true });
70-
this.fonts = await getFontList();
7157

72-
await this.user.loadSettings();
7358
this.changeSettings(this.user.settings);
7459
console.log("loaded", this.user.settings);
7560

@@ -81,7 +66,6 @@ export class Extension {
8166
this.awaiting.forEach(ready => ready());
8267
this.awaiting = null;
8368

84-
this.startAutoTimeCheck();
8569
this.user.cleanup();
8670
}
8771

@@ -121,8 +105,7 @@ export class Extension {
121105
if (command === "toggle") {
122106
console.log("Toggle command entered");
123107
this.changeSettings({
124-
enabled: !this.isEnabled(),
125-
automation: ""
108+
enabled: !this.isEnabled()
126109
});
127110
}
128111
if (command === "addSite") {
@@ -157,7 +140,6 @@ export class Extension {
157140
isEnabled: this.isEnabled(),
158141
isReady: this.ready,
159142
settings: this.user.settings,
160-
fonts: this.fonts,
161143
shortcuts: await this.getShortcuts()
162144
};
163145
}
@@ -174,25 +156,7 @@ export class Extension {
174156
}
175157
}
176158

177-
private wasEnabledOnLastCheck: boolean;
178-
179-
private startAutoTimeCheck() {
180-
setInterval(() => {
181-
if (!this.ready || this.user.settings.automation !== "time") {
182-
return;
183-
}
184-
const isEnabled = this.isEnabled();
185-
if (this.wasEnabledOnLastCheck !== isEnabled) {
186-
this.wasEnabledOnLastCheck = isEnabled;
187-
this.tabs.sendMessage(this.getTabMessage);
188-
this.reportChanges();
189-
}
190-
}, AUTO_TIME_CHECK_INTERVAL);
191-
}
192-
193159
changeSettings($settings: Partial<UserSettings>) {
194-
const prev = { ...this.user.settings };
195-
196160
this.user.set($settings);
197161
this.onSettingsChanged();
198162
}
@@ -239,7 +203,6 @@ export class Extension {
239203
return;
240204
}
241205

242-
this.wasEnabledOnLastCheck = this.isEnabled();
243206
this.tabs.sendMessage(this.getTabMessage);
244207
this.saveUserSettings();
245208
this.reportChanges();
@@ -342,7 +305,6 @@ export class Extension {
342305
// User settings
343306

344307
private async saveUserSettings() {
345-
await this.user.saveSettings();
346308
console.log("saved", this.user.settings);
347309
}
348310
}

src/background/messenger.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ export default class Messenger {
3333
chrome.runtime.onMessage.addListener(msg => {
3434
if (msg.name === "toggle") {
3535
this.adapter.changeSettings({
36-
enabled: msg.toggle,
37-
automation: ""
36+
enabled: msg.toggle
3837
});
3938
}
4039
});

0 commit comments

Comments
 (0)