This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
options.coffee
69 lines (58 loc) · 2.57 KB
/
options.coffee
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
settings = chrome.extension.getBackgroundPage().syntaxtic.settings
console.log settings
style = document.createElement('link')
style.type = 'text/css'
style.id = 'theme-style'
style.rel = "stylesheet"
style.href = chrome.extension.getURL("styles/" + settings.theme)
document.head.appendChild(style)
style = document.createElement('link')
style.type = 'text/css'
style.id = 'theme-style'
style.rel = "stylesheet"
style.href = chrome.extension.getURL("styles/shCore.css")
document.head.appendChild(style)
script = document.createElement('script')
script.src = chrome.extension.getURL("scripts/shCore.js")
script.type = 'text/javascript'
document.head.appendChild(script)
script = document.createElement('script')
script.src = chrome.extension.getURL("scripts/shBrushCSharp.js")
script.type = 'text/javascript'
document.head.appendChild(script)
optionChanged = () ->
# update the settings object from the DOM
settings.theme = document.getElementById('themeSelect').value
settings.fontSize = document.getElementById('fontSizeSelect').value
settings.fontFamily = document.getElementById('fontFamilySelect').value
settings.lineHeight = document.getElementById('lineHeightSelect').value
settings.disableQuickCode = document.getElementById('quickCodeSelect').value
# apply changed theme
document.getElementById('theme-style').href = chrome.extension.getURL("styles/" + settings.theme)
# apply changed font
style = document.getElementById('fontOverride')
style.innerHTML = ".syntaxhighlighter, .syntaxhighlighter code, .syntaxhighlighter div {\n
font-size: #{ settings.fontSize } !important;\n
font-family: '#{ settings.fontFamily }', monospace !important;\n
line-height: #{ settings.lineHeight }em !important;\n
}\n"
style.innerHTML += ".syntaxhighlighter select {\n
background-color: white !important;\n
border: none;\n
margin: 0;\n
padding: 0;\n
}\n"
initOptionsPage = () ->
# update the DOM from the settings object
document.getElementById('themeSelect').value = settings.theme
document.getElementById('fontSizeSelect').value = settings.fontSize
document.getElementById('fontFamilySelect').value = settings.fontFamily
document.getElementById('lineHeightSelect').value = settings.lineHeight
document.getElementById('quickCodeSelect').value = settings.disableQuickCode
document.addEventListener 'DOMContentLoaded', () ->
# iterate over <select>s and add event listeners
[].forEach.call document.querySelectorAll('select'), (el) ->
el.addEventListener('change', optionChanged)
initOptionsPage()
# update the content of #fontOverride
optionChanged()