Skip to content

Commit

Permalink
background color picker update
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberSphinxxx committed Sep 15, 2024
1 parent f6db487 commit c7b7693
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
7 changes: 7 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ <h1>
</div>
</div>

<div class="theme-picker">
<label for="bgColorPicker">Choose Background Color:</label>
<input type="color" id="bgColorPicker" name="bgColorPicker">
<button id="resetColorBtn">Reset Background</button>
</div>


<script src="script.js"></script>

</body>
Expand Down
24 changes: 24 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,5 +296,29 @@ document.addEventListener('fullscreenchange', () => {
}
});

const bgColorPicker = document.getElementById('bgColorPicker');
const resetColorBtn = document.getElementById('resetColorBtn');

window.addEventListener('DOMContentLoaded', () => {
const savedColor = localStorage.getItem('backgroundColor');
if (savedColor) {
document.body.style.backgroundColor = savedColor;
bgColorPicker.value = savedColor;
}
});

bgColorPicker.addEventListener('input', (event) => {
const color = event.target.value;
document.body.style.backgroundColor = color;
localStorage.setItem('backgroundColor', color);
});

// Reset button functionality
resetColorBtn.addEventListener('click', () => {
document.body.style.backgroundColor = '';
localStorage.removeItem('backgroundColor');
});


editor.setValue(tabs[0].content, -1);
runCode();
27 changes: 26 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,29 @@ body.dark-mode {

.focus-mode #preview {
height: 100vh;
}
}

.theme-picker {
margin: 20px;
display: flex;
align-items: center;
gap: 10px;
}

#bgColorPicker {
padding: 0.5px;
}

#resetColorBtn {
padding: 5px 10px;
background-color: #89b4fa;
color: #1e1e2e;
border: none;
border-radius: 5px;
cursor: pointer;
font-weight: bold;
}

#resetColorBtn:hover {
background-color: #b4befe;
}

0 comments on commit c7b7693

Please sign in to comment.