forked from kw-service/klas-helper-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
118 lines (106 loc) ยท 4.28 KB
/
content.js
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
110
111
112
113
114
115
116
117
var internalPathFunctions = undefined;
if (typeof browser === 'undefined') {
var browser = chrome;
}
// JavaScript ํ์ผ ์บ์ ๋ฌธ์ ํด๊ฒฐ
function jsCache(filePath) {
const nowDate = new Date();
const cacheValue = nowDate.getYear() + nowDate.getMonth() + nowDate.getDay() + nowDate.getHours() + nowDate.getMinutes();
return filePath + '?v=' + cacheValue;
}
(async () => {
const src = browser.runtime.getURL('core/internal.js');
const content = await import(src);
internalPathFunctions = content.internalPathFunctions;
// ํฌ๋กฌ sync ์คํ ๋ฆฌ์ง ์ด์ฉํด ์ฒดํฌ ์ฌ๋ถ ํ์ธ
try {
browser.storage.sync.get('currentState', function (items) {
// chrome namespace not supported
if (items === undefined) {
main();
}
else if (items.currentState === undefined) {
browser.storage.sync.set({ 'currentState': 'ON' });
main();
}
else if (items.currentState === 'ON') {
main();
}
});
}
catch (e) {
main();
}
})();
async function main() {
'use strict';
const waitTimer = setInterval(() => {
if (document.querySelector('.navtxt span:nth-child(1)')) {
if (document.querySelector('.navtxt span:nth-child(2)')) {
document.querySelector('.navtxt span:nth-child(2)').remove();
document.querySelector('.navtxt span:nth-child(1)').innerHTML = (`
<a href="https://github.com/klas-helper/klas-helper-extension/wiki/%EA%B8%B0%EC%A1%B4-KLAS-Helper-Tempermonkey-%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8-%EC%82%AD%EC%A0%9C-%EB%B0%A9%EB%B2%95"
target="_blank" rel="noopener" style="color: red; text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff;">
๊ธฐ์กด ์คํฌ๋ฆฝํธ๋ฅผ ์ญ์ ํด ์ฃผ์ธ์! (ํด๋ฆญ)
</a>
`);
}
else {
document.querySelector('.navtxt span:nth-child(1)').innerHTML = (`
<a href="https://github.com/klas-helper/klas-helper" target="_blank" rel="noopener">KLAS Helper</a>
<a href="https://github.com/klas-helper/klas-helper-extension" target="_blank" rel="noopener">ํ์ฅ ํ๋ก๊ทธ๋จ</a>
์ฌ์ฉ ์ค
`);
}
clearInterval(waitTimer);
}
}, 500);
// ๋ฉ์ธ ํ์ผ ์ฝ์
// ์
๋ฐ์ดํธ ์ ์ฆ๊ฐ์ ์ผ๋ก ์
๋ฐ์ดํธ๋ฅผ ๋ฐ์ํ๊ธฐ ์ํด ์ด๋ฌํ ๋ฐฉ์์ ์ฌ์ฉํจ
const scriptElements = [];
// let jsfile = 'https://nbsp1221.github.io/klas-helper/dist/main-ext.js';
let jsfile = browser.runtime.getURL('core/main-ext.js');
let ChartJs = browser.runtime.getURL('assets/Chart.min.js');
let jQueryModalJs = browser.runtime.getURL('assets/jquery.modal.min.js');
let jQueryModalCss = browser.runtime.getURL('assets/jquery.modal.min.css');
let jsScriptElements = document.createElement('script');
let chartJsScriptElements = document.createElement('script');
let jQueryModalJsScriptElements = document.createElement('script');
let jQueryModalCssScriptElements = document.createElement('link');
jsScriptElements.src = jsCache(jsfile);
chartJsScriptElements.src = jsCache(ChartJs);
jQueryModalJsScriptElements.src = jsCache(jQueryModalJs);
jQueryModalCssScriptElements.href = jsCache(jQueryModalCss);
jQueryModalCssScriptElements.rel = 'stylesheet';
jQueryModalCssScriptElements.type = 'text/css';
scriptElements.push(jsScriptElements);
scriptElements.push(chartJsScriptElements);
scriptElements.push(jQueryModalJsScriptElements);
scriptElements.push(jQueryModalCssScriptElements);
// document.head.appendChild(scriptElement);
let useTempermonkey = false;
for (let i = 0; i < document.head.children.length; i++) {
if (document.head.children[i].src !== undefined) {
if (document.head.children[i].src.includes('https://klas-helper.github.io/klas-helper/dist/main.js')) {
console.log('Detect tempermonkey script!');
useTempermonkey = true;
break;
}
}
}
if (!useTempermonkey) {
for (const element in scriptElements) {
document.head.appendChild(scriptElements[element]);
}
// document.head.appendChild(scriptElement);
for (const path in internalPathFunctions) {
if (path === location.pathname) {
internalPathFunctions[path]();
}
}
}
// ์ผ์ ์๊ฐ์ด ์ง๋ ๊ฒฝ์ฐ ํ์ด๋จธ ํด์
setTimeout(() => {
clearInterval(waitTimer);
}, 1500);
}