Skip to content
This repository was archived by the owner on Feb 14, 2022. It is now read-only.

Commit cca4b56

Browse files
committed
Cleanup code
1 parent a954630 commit cca4b56

12 files changed

Lines changed: 125 additions & 126 deletions
File renamed without changes.

manifest.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"web_accessible_resources": [
2020
"css/*.css",
2121
"svg/*.svg",
22-
"3rdparty/tagify.2.28.4.min.js",
23-
"voting.js"
22+
"injected/tagify.2.28.4.min.js",
23+
"injected/voting.js"
2424
],
2525
"content_scripts": [{
2626
"matches": [
@@ -30,13 +30,13 @@
3030
"js": [
3131
"3rdparty/jquery.3.4.1.min.js",
3232
"3rdparty/bootstrap.3.2.0.min.js",
33-
"3rdparty/tagify.2.28.4.min.js",
34-
"content.js",
35-
"inject_stylesheet.js"
33+
"src/content/utils.js",
34+
"src/content/main.js",
35+
"src/content/inject_stylesheet.js"
3636
]
3737
}
3838
],
3939
"browser_action": {
40-
"default_popup": "options_login.html"
40+
"default_popup": "src/options/options_login.html"
4141
}
4242
}

content.js renamed to src/content/main.js

Lines changed: 2 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,5 @@
1-
function loadScript(src) {
2-
var s = document.createElement('script');
3-
s.src = chrome.runtime.getURL(src);
4-
s.onload = function() {
5-
this.remove();
6-
};
7-
8-
(document.head || document.documentElement).appendChild(s);
9-
}
10-
11-
loadScript('3rdparty/tagify.2.28.4.min.js')
12-
loadScript('voting.js')
13-
14-
const getPrefs = (key, defaultValue) => {
15-
return new Promise((resolve, reject) => {
16-
chrome.storage.local.get([key], (value) => {
17-
if (!value[key]) resolve(defaultValue)
18-
else resolve(value[key])
19-
})
20-
})
21-
}
22-
23-
function setPrefs(key, value) {
24-
var params = {}
25-
params[key] = value
26-
chrome.storage.local.set(params)
27-
}
28-
29-
function levelName(level) {
30-
const prefix = ['Bronze', 'Silver', 'Gold', 'Platinum', 'Diamond', 'Ruby']
31-
const roman = ['I', 'II', 'III', 'IV', 'V']
32-
33-
return prefix[Math.floor((level - 1) / 5)] + ' ' + roman[4 - (level - 1) % 5]
34-
}
35-
36-
function levelShortDisplayName(level) {
37-
const prefix = ['B', 'S', 'G', 'P', 'D', 'R']
38-
const roman = ['I', 'II', 'III', 'IV', 'V']
39-
40-
return '<b>' + prefix[Math.floor((level - 1) / 5)] + '</b> ' + roman[4 - (level - 1) % 5]
41-
}
42-
43-
function levelCssClass(level) {
44-
const prefix = ['bronze', 'silver', 'gold', 'platinum', 'diamond', 'ruby']
45-
46-
return prefix[Math.floor((level - 1) / 5)]
47-
}
48-
49-
function levelText(level) {
50-
if (level == 0) return "<span>Unranked</span>"
51-
return "<span class=\"text-" + levelCssClass(level) + "\">" + levelName(level) + "</span>"
52-
}
53-
54-
function kudekiLevelText(level) {
55-
const roman = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII']
56-
return "<span class=\"text-kudeki\">Ghudegy " + roman[level - 1] + "</span>"
57-
}
58-
59-
function levelLabelUnlisted() {
60-
return "<span class=\"level_hidden\">00"
61-
+ "</span><img class=\"level_badge small\" style=\"width: 1.1em;height: 1.4em;\" src=\"" + chrome.extension.getURL("svg/unlisted.svg") + "\">"
62-
}
63-
64-
function levelLabel(level) {
65-
if (level === null) return levelLabelUnlisted()
66-
if (level == -1) level = 0
67-
return "<span class=\"level_hidden\">" + ('0' + level).slice(-2)
68-
+ "</span><img class=\"level_badge small\" style=\"width: 1.1em;height: 1.4em;\" src=\"" + chrome.extension.getURL("svg/" + level + ".svg") + "\">"
69-
}
70-
71-
function kudekiLevelLabel(level) {
72-
return "<img class=\"level_badge small\" style=\"width: 1.1em;height: 1.4em;\" src=\"" + chrome.extension.getURL("svg/ka" + level + ".svg") + "\">"
73-
}
74-
75-
function matchCurrentURL(regex) {
76-
return regex.test(window.location.toString())
77-
}
78-
79-
function isBOJStack() {
80-
return matchCurrentURL(/^https?:\/\/stack\.acmicpc\.net\/.*?$/i)
81-
}
82-
83-
function isProblemPage() {
84-
return matchCurrentURL(/^https?:\/\/www\.acmicpc\.net\/problem\/[0-9]+\/?$/i)
85-
}
86-
87-
function isUserPage() {
88-
return matchCurrentURL(/^https?:\/\/www\.acmicpc\.net\/(user)\/[A-Za-z0-9_]+$/i)
89-
}
90-
91-
function isNotUserOrVsPage() {
92-
return !matchCurrentURL(/^https?:\/\/www\.acmicpc\.net\/(user|vs)\/.*$/i)
93-
}
94-
95-
function algorithmToTag(item, showTagsInEnglish) {
96-
if (showTagsInEnglish) {
97-
return {
98-
value: item.full_name_en,
99-
searchBy: item.full_name_ko + ',' + item.short_name_en + ',' + item.aliases,
100-
algorithm_id: item.algorithm_id
101-
}
102-
} else {
103-
return {
104-
value: item.full_name_ko,
105-
searchBy: item.full_name_en + ',' + item.short_name_en + ',' + item.aliases,
106-
algorithm_id: item.algorithm_id
107-
}
108-
}
109-
}
1+
loadScript('injected/tagify.2.28.4.min.js')
2+
loadScript('injected/voting.js')
1103

1114
async function initializeVoting(token, problemId, defaultLevel, myVote) {
1125
var params = {

src/content/utils.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
function loadScript(src) {
2+
var s = document.createElement('script');
3+
s.src = chrome.runtime.getURL(src);
4+
s.onload = function() {
5+
this.remove();
6+
};
7+
8+
(document.head || document.documentElement).appendChild(s);
9+
}
10+
11+
const getPrefs = (key, defaultValue) => {
12+
return new Promise((resolve, reject) => {
13+
chrome.storage.local.get([key], (value) => {
14+
if (!value[key]) resolve(defaultValue)
15+
else resolve(value[key])
16+
})
17+
})
18+
}
19+
20+
function setPrefs(key, value) {
21+
var params = {}
22+
params[key] = value
23+
chrome.storage.local.set(params)
24+
}
25+
26+
function levelName(level) {
27+
const prefix = ['Bronze', 'Silver', 'Gold', 'Platinum', 'Diamond', 'Ruby']
28+
const roman = ['I', 'II', 'III', 'IV', 'V']
29+
30+
return prefix[Math.floor((level - 1) / 5)] + ' ' + roman[4 - (level - 1) % 5]
31+
}
32+
33+
function levelShortDisplayName(level) {
34+
const prefix = ['B', 'S', 'G', 'P', 'D', 'R']
35+
const roman = ['I', 'II', 'III', 'IV', 'V']
36+
37+
return '<b>' + prefix[Math.floor((level - 1) / 5)] + '</b> ' + roman[4 - (level - 1) % 5]
38+
}
39+
40+
function levelCssClass(level) {
41+
const prefix = ['bronze', 'silver', 'gold', 'platinum', 'diamond', 'ruby']
42+
43+
return prefix[Math.floor((level - 1) / 5)]
44+
}
45+
46+
function levelText(level) {
47+
if (level == 0) return "<span>Unranked</span>"
48+
return "<span class=\"text-" + levelCssClass(level) + "\">" + levelName(level) + "</span>"
49+
}
50+
51+
function kudekiLevelText(level) {
52+
const roman = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII']
53+
return "<span class=\"text-kudeki\">Ghudegy " + roman[level - 1] + "</span>"
54+
}
55+
56+
function levelLabelUnlisted() {
57+
return "<span class=\"level_hidden\">00"
58+
+ "</span><img class=\"level_badge small\" style=\"width: 1.1em;height: 1.4em;\" src=\"" + chrome.extension.getURL("svg/unlisted.svg") + "\">"
59+
}
60+
61+
function levelLabel(level) {
62+
if (level === null) return levelLabelUnlisted()
63+
if (level == -1) level = 0
64+
return "<span class=\"level_hidden\">" + ('0' + level).slice(-2)
65+
+ "</span><img class=\"level_badge small\" style=\"width: 1.1em;height: 1.4em;\" src=\"" + chrome.extension.getURL("svg/" + level + ".svg") + "\">"
66+
}
67+
68+
function kudekiLevelLabel(level) {
69+
return "<img class=\"level_badge small\" style=\"width: 1.1em;height: 1.4em;\" src=\"" + chrome.extension.getURL("svg/ka" + level + ".svg") + "\">"
70+
}
71+
72+
function matchCurrentURL(regex) {
73+
return regex.test(window.location.toString())
74+
}
75+
76+
function isBOJStack() {
77+
return matchCurrentURL(/^https?:\/\/stack\.acmicpc\.net\/.*?$/i)
78+
}
79+
80+
function isProblemPage() {
81+
return matchCurrentURL(/^https?:\/\/www\.acmicpc\.net\/problem\/[0-9]+\/?$/i)
82+
}
83+
84+
function isUserPage() {
85+
return matchCurrentURL(/^https?:\/\/www\.acmicpc\.net\/(user)\/[A-Za-z0-9_]+$/i)
86+
}
87+
88+
function isNotUserOrVsPage() {
89+
return !matchCurrentURL(/^https?:\/\/www\.acmicpc\.net\/(user|vs)\/.*$/i)
90+
}
91+
92+
function algorithmToTag(item, showTagsInEnglish) {
93+
if (showTagsInEnglish) {
94+
return {
95+
value: item.full_name_en,
96+
searchBy: item.full_name_ko + ',' + item.short_name_en + ',' + item.aliases,
97+
algorithm_id: item.algorithm_id
98+
}
99+
} else {
100+
return {
101+
value: item.full_name_ko,
102+
searchBy: item.full_name_en + ',' + item.short_name_en + ',' + item.aliases,
103+
algorithm_id: item.algorithm_id
104+
}
105+
}
106+
}
File renamed without changes.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<meta http-equiv="X-UA-Compatible" content="ie=edge">
77
<link rel="stylesheet" type="text/css" href="https://solved.ac/css/fonts/inter/inter.css">
88
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Noto+Sans+KR:400,700">
9-
<link rel="stylesheet" href="options.css">
9+
<link rel="stylesheet" href="/css/options.css">
1010
<title>Options</title>
1111
</head>
1212
<body>
@@ -42,8 +42,8 @@ <h1 id="user_id">...</h1>
4242
</span>
4343
</div>
4444
</div>
45-
<script src="3rdparty/axios.0.19.0.min.js"></script>
46-
<script src="options_logged_info.js"></script>
47-
<script src="options_commons.js"></script>
45+
<script src="/3rdparty/axios.0.19.0.min.js"></script>
46+
<script src="/src/options/options_logged_info.js"></script>
47+
<script src="/src/options/options_commons.js"></script>
4848
</body>
4949
</html>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const logout = () => {
1111
const code = 'window.location.reload();'
1212
chrome.tabs.executeScript(id, { code })
1313
})
14-
window.location.href = '/options_login.html'
14+
window.location.href = '/src/options/options_login.html'
1515
})
1616
}
1717

0 commit comments

Comments
 (0)