Skip to content

Commit 9016945

Browse files
committed
Add Editor action handlers
1 parent 1a9a94c commit 9016945

File tree

3 files changed

+78
-13
lines changed

3 files changed

+78
-13
lines changed

src/index2.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
<!-- Dynamically displayed through JS -->
3333

3434
<!-- Editor Page -->
35-
<div id="editor_page_container">
36-
<div id="editor_page">
35+
<div id="editor_page">
36+
<div>
3737
<div id="editor_menu">
3838
<div id="editor_actions">
3939
<select value="css" id="editor_type">
40-
<option value="css">css</option>
41-
<option value="js">js</option>
40+
<option value="css">CSS</option>
41+
<option value="js">JS</option>
4242
</select>
4343
<div>
4444
<span id="editor_render" class="material-icons">...</span>
@@ -57,8 +57,8 @@
5757
</div>
5858

5959
<!-- Settings Page -->
60-
<section id="settings_page_container">
61-
<div id="settings_page">
60+
<section id="settings_page">
61+
<div>
6262
<h1>Settings</h1>
6363
</div>
6464
</section>

src/main.js

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
// Header Menu Icons/Buttons
1+
// Header IDS
22
const stateButton = document.getElementById('state_button')
33
const themeButton = document.getElementById('theme_button')
44
const settingsButton = document.getElementById('settings_button')
55

6-
// Editor Actions
6+
// Editor IDS
77
const editorType = document.getElementById('editor_type')
88
const editorCSS = document.getElementById('editor_css')
99
const editorJS = document.getElementById('editor_js')
10+
const editorTaburl = document.getElementById('editor_taburl')
11+
const editorRender = document.getElementById('editor_render')
12+
const editorLock = document.getElementById('editor_lock')
1013

11-
// Snipx Pages
12-
const editorPage = document.getElementById('editor_page_container')
13-
const settingsPage = document.getElementById('settings_page_container')
14+
// Page IDS
15+
const editorPage = document.getElementById('editor_page')
16+
const settingsPage = document.getElementById('settings_page')
1417

1518
// Create localStorage key/value if not there already
1619
let defaultStorage = {
@@ -43,6 +46,7 @@ chrome.tabs.query({
4346
let currentTabURL = newArray.join('')
4447
// Insert URL directly into localStorage
4548
localStorage.setItem('SnipxTabURL', currentTabURL)
49+
editorTaburl.innerText = currentTabURL
4650
})
4751

4852
// Set localStorage defaultStorage values
@@ -107,6 +111,14 @@ window.addEventListener('load', (e) => {
107111
})
108112
break
109113
}
114+
switch(localStorage.getItem('SnipxEditorRender')) {
115+
case 'true': editorRender.innerText = 'visibility'; break
116+
case 'false': editorRender.innerText = 'visibility_off'; break
117+
}
118+
switch(localStorage.getItem('SnipxEditorLock')) {
119+
case 'true': editorLock.innerText = 'lock'; break
120+
case 'false': editorLock.innerText = 'no_encryption'; break
121+
}
110122
// HEADER UPDATE
111123
// .................................
112124
// Load Event Listeners towards the end of the file
@@ -168,7 +180,44 @@ window.addEventListener('load', (e) => {
168180
// TYPE
169181
editorType.addEventListener('change', (e) => {
170182
localStorage.setItem('SnipxEditor', editorType.value)
171-
// Change editor type
183+
switch(editorType.value) {
184+
case 'css':
185+
editorJS.style.display = 'none'
186+
editorCSS.style.display = 'block'
187+
break
188+
case 'js':
189+
editorCSS.style.display = 'none'
190+
editorJS.style.display = 'block'
191+
break
192+
}
193+
}, false)
194+
editorRender.addEventListener('click', (e) => {
195+
switch(localStorage.getItem('SnipxEditorRender')) {
196+
case 'true':
197+
localStorage.setItem('SnipxEditorRender', 'false')
198+
// insert current editor code into TabURL
199+
window.location.reload()
200+
break
201+
case 'false':
202+
localStorage.setItem('SnipxEditorRender', 'true')
203+
// remove current editor code from TabURL
204+
window.location.reload()
205+
break
206+
}
207+
}, false)
208+
editorLock.addEventListener('click', (e) => {
209+
switch(localStorage.getItem('SnipxEditorLock')) {
210+
case 'true':
211+
localStorage.setItem('SnipxEditorLock', 'false')
212+
// unlock the current editor
213+
window.location.reload()
214+
break
215+
case 'false':
216+
localStorage.setItem('SnipxEditorLock', 'true')
217+
// lock the current editor
218+
window.location.reload()
219+
break
220+
}
172221
}, false)
173222
}, false)
174223

src/style.css

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
}
1414
.material-icons {
1515
color: white;
16+
cursor: pointer;
1617
}
1718
/* Custom properties */
1819
:root {
@@ -45,11 +46,13 @@ body {
4546
justify-content: space-between;
4647
}
4748
#header {
49+
height: 60px;
4850
background: black;
4951
}
5052
#header_title {
5153
font-size: 20px;
5254
color: blue;
55+
cursor: pointer;
5356
}
5457
/* Sections */
5558
section,
@@ -58,12 +61,25 @@ textarea {
5861
}
5962
#editor_menu {
6063
width: 100%;
64+
height: 30px;
6165
background: red;
6266
}
67+
#editor_type {
68+
font-size: 14px;
69+
cursor: pointer;
70+
}
6371
#editor_actions {
6472
outline: 1px solid lime;
6573
}
6674
#editor_events {
75+
/* padding: 4px; */
76+
/* outline: 1px solid lime; */
77+
}
78+
#editor_events a {
79+
font-size: 14px;
80+
cursor: pointer;
81+
text-decoration: underline;
82+
padding: 5px;
6783
outline: 1px solid lime;
6884
}
6985
.editor {
@@ -72,7 +88,7 @@ textarea {
7288
font-family: Consolas, 'Courier New', monospace;
7389
background: black;
7490
width: 480px;
75-
height: 490px;
91+
height: 400px;
7692
border: 0;
7793
resize: none;
7894
color: #cccccc;

0 commit comments

Comments
 (0)