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

Commit f7ed68e

Browse files
committed
Added option to display tags in English
1 parent 887b854 commit f7ed68e

3 files changed

Lines changed: 111 additions & 79 deletions

File tree

content.js

Lines changed: 95 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,19 @@ function setPrefs(key, value) {
6262
chrome.storage.local.set(params)
6363
}
6464

65-
function algorithmToTag(item) {
66-
return {
67-
value: item.full_name_ko,
68-
searchBy: item.full_name_en + ',' + item.short_name_en + ',' + item.aliases,
69-
algorithm_id: item.algorithm_id
65+
function algorithmToTag(item, showTagsInEnglish) {
66+
if (showTagsInEnglish) {
67+
return {
68+
value: item.full_name_en,
69+
searchBy: item.full_name_ko + ',' + item.short_name_en + ',' + item.aliases,
70+
algorithm_id: item.algorithm_id
71+
}
72+
} else {
73+
return {
74+
value: item.full_name_ko,
75+
searchBy: item.full_name_en + ',' + item.short_name_en + ',' + item.aliases,
76+
algorithm_id: item.algorithm_id
77+
}
7078
}
7179
}
7280

@@ -88,75 +96,77 @@ function initializeVoting(token, problemId, defaultLevel, myVote) {
8896
if (!document.querySelector(".label-success") && user.user_id !== "solvedac") return
8997

9098
getJson("https://api.solved.ac/algorithms.php", (algorithms) => {
91-
const bottom = document.querySelector(".col-md-12:nth-child(4)")
92-
var visibleState = "poll_shown"
93-
if (myVote) visibleState = "poll_hidden"
94-
bottom.outerHTML += "<div class=\"col-md-12\"><section id=\"problem_difficulty\" class=\"" + visibleState + "\"><div class=\"headline\" onclick=\"togglePoll()\"><h2>난이도 투표 <small>펼치기/접기</small></h2></div></section></div>"
95-
96-
const difficultySectionConainer = document.getElementById("problem_difficulty")
97-
const difficultySection = document.createElement("div")
98-
difficultySection.className = "poll"
99-
difficultySectionConainer.appendChild(difficultySection)
100-
101-
const commentCaption = document.createElement("span")
102-
commentCaption.className = "vote_caption"
103-
commentCaption.innerText = "난이도 의견"
104-
difficultySection.appendChild(commentCaption)
105-
106-
const difficultySelector = document.createElement("select")
107-
difficultySelector.name = "difficulty_selector"
108-
difficultySelector.className = "difficulty_selector"
109-
110-
for (var i = 1; i <= 30; i++) {
111-
const difficultyItem = document.createElement("option")
112-
difficultyItem.value = i;
113-
difficultyItem.innerText = levelName(i);
114-
difficultyItem.className = levelCssClass(i);
115-
difficultySelector.appendChild(difficultyItem)
116-
}
99+
getPrefs('show_tags_in_english', (showTagsInEnglish) => {
100+
const bottom = document.querySelector(".col-md-12:nth-child(4)")
101+
var visibleState = "poll_shown"
102+
if (myVote) visibleState = "poll_hidden"
103+
bottom.outerHTML += "<div class=\"col-md-12\"><section id=\"problem_difficulty\" class=\"" + visibleState + "\"><div class=\"headline\" onclick=\"togglePoll()\"><h2>난이도 투표 <small>펼치기/접기</small></h2></div></section></div>"
104+
105+
const difficultySectionConainer = document.getElementById("problem_difficulty")
106+
const difficultySection = document.createElement("div")
107+
difficultySection.className = "poll"
108+
difficultySectionConainer.appendChild(difficultySection)
109+
110+
const commentCaption = document.createElement("span")
111+
commentCaption.className = "vote_caption"
112+
commentCaption.innerText = "난이도 의견"
113+
difficultySection.appendChild(commentCaption)
114+
115+
const difficultySelector = document.createElement("select")
116+
difficultySelector.name = "difficulty_selector"
117+
difficultySelector.className = "difficulty_selector"
118+
119+
for (var i = 1; i <= 30; i++) {
120+
const difficultyItem = document.createElement("option")
121+
difficultyItem.value = i;
122+
difficultyItem.innerText = levelName(i);
123+
difficultyItem.className = levelCssClass(i);
124+
difficultySelector.appendChild(difficultyItem)
125+
}
117126

118-
difficultySelector.selectedIndex = (defaultLevel - 1);
119-
difficultySection.appendChild(difficultySelector);
120-
difficultySection.appendChild(document.createElement("br"))
127+
difficultySelector.selectedIndex = (defaultLevel - 1);
128+
difficultySection.appendChild(difficultySelector);
129+
difficultySection.appendChild(document.createElement("br"))
121130

122-
const commentSection = document.createElement("textarea")
123-
commentSection.id = "problem_comment"
124-
if (myVote) commentSection.value = myVote.comment
125-
difficultySection.appendChild(commentSection)
126-
difficultySection.appendChild(document.createElement("br"))
131+
const commentSection = document.createElement("textarea")
132+
commentSection.id = "problem_comment"
133+
if (myVote) commentSection.value = myVote.comment
134+
difficultySection.appendChild(commentSection)
135+
difficultySection.appendChild(document.createElement("br"))
127136

128-
const whitelist = algorithms.map(algorithmToTag)
129-
var selectedAlgorithms = []
130-
if (myVote) selectedAlgorithms = myVote.algorithms.map(algorithmToTag)
137+
const whitelist = algorithms.map(algorithmToTag, showTagsInEnglish)
138+
var selectedAlgorithms = []
139+
if (myVote) selectedAlgorithms = myVote.algorithms.map(algorithmToTag, showTagsInEnglish)
131140

132-
const algorithmCaption = document.createElement("span")
133-
algorithmCaption.className = "vote_caption"
134-
algorithmCaption.innerText = "알고리즘 분류 의견"
135-
difficultySection.appendChild(algorithmCaption)
136-
137-
const algorithmSection = document.createElement("input")
138-
algorithmSection.id = "algorithm_input"
139-
algorithmSection.name = "basic"
140-
difficultySection.appendChild(algorithmSection)
141-
142-
const whitelistScript = document.createElement("script")
143-
whitelistScript.innerHTML = "var whitelist = JSON.parse(" + JSON.stringify(JSON.stringify(whitelist)) + ");"
144-
difficultySection.appendChild(whitelistScript)
145-
146-
const algorithmInputScript = document.createElement("script")
147-
algorithmInputScript.innerHTML = "var algorithmSuggestionInput=new Tagify(document.querySelector('#algorithm_input'),"
148-
+ "{enforceWhitelist: true, whitelist: whitelist, dropdown: {enabled: 1, classname: 'algorithm_dropdown'}, delimiters: '[|]'});"
149-
+ "algorithmSuggestionInput.addTags(JSON.parse(" + JSON.stringify(JSON.stringify(selectedAlgorithms)) + "))"
150-
difficultySection.appendChild(algorithmInputScript)
151-
152-
const sendButton = document.createElement("button")
153-
sendButton.className = "btn btn-primary"
154-
sendButton.id = "poll_submit"
155-
sendButton.type = "submit"
156-
sendButton.innerText = "이렇게 제출하기"
157-
sendButton.style.marginTop = "16px"
158-
sendButton.setAttribute("onclick", "sendVote('" + token + "'," + problemId + ")")
159-
difficultySection.appendChild(sendButton)
141+
const algorithmCaption = document.createElement("span")
142+
algorithmCaption.className = "vote_caption"
143+
algorithmCaption.innerText = "알고리즘 분류 의견"
144+
difficultySection.appendChild(algorithmCaption)
145+
146+
const algorithmSection = document.createElement("input")
147+
algorithmSection.id = "algorithm_input"
148+
algorithmSection.name = "basic"
149+
difficultySection.appendChild(algorithmSection)
150+
151+
const whitelistScript = document.createElement("script")
152+
whitelistScript.innerHTML = "var whitelist = JSON.parse(" + JSON.stringify(JSON.stringify(whitelist)) + ");"
153+
difficultySection.appendChild(whitelistScript)
154+
155+
const algorithmInputScript = document.createElement("script")
156+
algorithmInputScript.innerHTML = "var algorithmSuggestionInput=new Tagify(document.querySelector('#algorithm_input'),"
157+
+ "{enforceWhitelist: true, whitelist: whitelist, dropdown: {enabled: 1, classname: 'algorithm_dropdown'}, delimiters: '[|]'});"
158+
+ "algorithmSuggestionInput.addTags(JSON.parse(" + JSON.stringify(JSON.stringify(selectedAlgorithms)) + "))"
159+
difficultySection.appendChild(algorithmInputScript)
160+
161+
const sendButton = document.createElement("button")
162+
sendButton.className = "btn btn-primary"
163+
sendButton.id = "poll_submit"
164+
sendButton.type = "submit"
165+
sendButton.innerText = "이렇게 제출하기"
166+
sendButton.style.marginTop = "16px"
167+
sendButton.setAttribute("onclick", "sendVote('" + token + "'," + problemId + ")")
168+
difficultySection.appendChild(sendButton)
169+
})
160170
})
161171
}
162172
xhr.send(JSON.stringify(params))
@@ -274,7 +284,7 @@ function addLevelIndicators() {
274284

275285
var standard = (difficultyVotes.length > 0 && difficultyVotes[0].user_id == "solvedac")
276286

277-
getPrefs('hide_other_votes', (value) => {
287+
getPrefs('hide_other_votes', (hideOtherVotes) => {
278288
if (!document.querySelector(".label-success") && user.user_id !== "solvedac") return
279289
if (levelData.level != 0 && !standard) {
280290
for (var i = 0; i < difficultyVotes.length; i++) {
@@ -284,7 +294,7 @@ function addLevelIndicators() {
284294
myVote = vote
285295
}
286296

287-
if (value === undefined || JSON.parse(value) === false) {
297+
if (hideOtherVotes === undefined || JSON.parse(hideOtherVotes) === false) {
288298
var difficultyVote = document.createElement("div")
289299
difficultyVote.className = "difficulty_vote"
290300
difficultyVote.innerHTML = "<a href=\"/user/" + vote.user_id + "\">"
@@ -302,13 +312,19 @@ function addLevelIndicators() {
302312
voteComment.innerText = "난이도 의견을 입력하지 않았습니다"
303313
}
304314
if (vote.algorithms) {
305-
for (var j = 0; j < vote.algorithms.length; j++) {
306-
var algo = vote.algorithms[j]
307-
var algorithmTag = document.createElement("div")
308-
algorithmTag.innerText = algo.full_name_ko
309-
algorithmTag.className = "algorithm_tag"
310-
voteComment.appendChild(algorithmTag)
311-
}
315+
getPrefs('show_tags_in_english', (showTagsInEnglish) => {
316+
for (var j = 0; j < vote.algorithms.length; j++) {
317+
var algo = vote.algorithms[j]
318+
var algorithmTag = document.createElement("div")
319+
if (JSON.parse(showTagsInEnglish) === true) {
320+
algorithmTag.innerText = algo.full_name_en
321+
} else {
322+
algorithmTag.innerText = algo.full_name_ko
323+
}
324+
algorithmTag.className = "algorithm_tag"
325+
voteComment.appendChild(algorithmTag)
326+
}
327+
})
312328
}
313329
difficultyVote.appendChild(voteComment)
314330

options_logged_info.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ <h1 id="user_id">...</h1>
3333
<span class="toggle_knob"></span>
3434
</span>
3535
</div>
36+
<div class="option_item" data-key="show_tags_in_english">
37+
<span class="option_caption">
38+
문제 태그 영어로 보기
39+
</span>
40+
<span class="option_switch">
41+
<span class="toggle_knob"></span>
42+
</span>
43+
</div>
3644
</div>
3745
<script src="3rdparty/axios.0.19.0.min.js"></script>
3846
<script src="options_logged_info.js"></script>

options_login.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ <h3 class="input_caption">비밀번호</h3>
3838
<span class="toggle_knob"></span>
3939
</span>
4040
</div>
41+
<div class="option_item" data-key="show_tags_in_english">
42+
<span class="option_caption">
43+
문제 태그 영어로 보기
44+
</span>
45+
<span class="option_switch">
46+
<span class="toggle_knob"></span>
47+
</span>
48+
</div>
4149
</div>
4250
<script src="3rdparty/axios.0.19.0.min.js"></script>
4351
<script src="options_login.js"></script>

0 commit comments

Comments
 (0)