-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
109 lines (90 loc) · 2.75 KB
/
Copy pathmain.ts
File metadata and controls
109 lines (90 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import "./trusted-types-polyfill";
import "./animation.scss";
import "./tailwind.css";
import { App, createApp } from "vue";
import subtitleComponents from "./subtitle/components/components";
import generalComponents from "./common/components/components";
import { netflix } from "./subtitle/web_netflix/initializer";
import { youtube } from "./subtitle/web_youtube/initializer";
import { AppInitializer } from "./common/types/general.type";
import { cleanText } from "./common/helper/text";
import { analytic } from "./plugins/mixpanel";
import { VERSION } from "./common/static/global";
import { log } from "./common/helper/log";
import { addPlugins } from "./plugins/install";
import {
registerGlobalEvents,
unregisterGlobalEvents,
} from "./subtitle/helpers/global-events";
import { loginWithLastSession } from "./plugins/modular-rest";
import { useSettingsStore } from "./common/store/settings";
log("Using version", VERSION);
let vueApp!: App;
let appInitializer!: AppInitializer;
let initialized = false;
// Select an app initializer from existing modules
//
[youtube, netflix].forEach((item) => {
if (location.hostname.includes(item.website.host)) {
appInitializer = item;
}
});
// Create an interval to initializing the app
// In each interval cycle Initializer seeks for a subtitle container,
// Then the app being initiated if container exists
//
function start() {
setInterval(() => {
//
// Mount vue app of location match
//
if (
!initialized &&
location.pathname.includes(appInitializer.website.path)
) {
initialized = true;
// Create a vue app
const app = createApp(appInitializer.component as any);
// Add plugins
vueApp = addPlugins(app);
// Initialize settings
const settingsStore = useSettingsStore();
settingsStore.initialize();
// Login with last session
loginWithLastSession();
// Register components
//
const components = {
...subtitleComponents,
...generalComponents,
};
Object.keys(components).forEach((name) => {
let component = (components as any)[name];
vueApp.component(name, component);
vueApp.config.globalProperties.$filters = {
cleanText: cleanText,
};
});
//
// END Register components
appInitializer
.start(vueApp)
.then((_) => {
registerGlobalEvents();
})
.catch((_) => analytic.track("extension_init-failed"));
}
//
// Unmount vue app if location doesn't match anymore
//
else if (
initialized &&
!location.pathname.includes(appInitializer.website.path)
) {
initialized = false;
unregisterGlobalEvents();
vueApp.unmount();
}
}, 100);
}
start();