Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to hide "shortcuts" #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ const setupSettingsDialog = () => {
const batteryInput = $('#settings-battery-input')
const connectionInput = $('#settings-connection-input')
const devicesInput = $('#settings-devices-input')
const shortcutInput = $('#settings-shortcut-input')
const cssTextarea = $('#settings-css-textarea')
const doneButton = $('#settings-done-button')

// keyboard shortcut overrides
const writingModeShortcutInput = $('#settings-writing-mode-shortcut-input')

store.get(['theme', 'mode', 'css', 'favicons', 'timeformat', 'battery', 'connection', 'devices'], (settings) => {
store.get(['theme', 'mode', 'css', 'favicons', 'timeformat', 'battery', 'connection', 'devices', 'shortcuts'], (settings) => {
let preset = {
mode: localStorage.getItem('mode') || 'system',
theme: localStorage.getItem('theme') || 'smooth-dark',
Expand All @@ -73,6 +74,7 @@ const setupSettingsDialog = () => {
battery: localStorage.getItem('battery') || 'show',
connection: localStorage.getItem('connection') || 'show',
devices: localStorage.getItem('devices') || 'show',
shortcuts: localStorage.getItem('shortcuts') || 'show',
writingModeShortcut: localStorage.getItem('writing-mode-shortcut') || (IS_MAC ? 'shift+command' : 'ctrl+shift'),
...settings
}
Expand Down Expand Up @@ -106,6 +108,11 @@ const setupSettingsDialog = () => {
if (preset.devices === 'show') {
$('#settings-devices-input').setAttribute('checked', 'checked')
}

$('#settings-shortcut-input').removeAttribute('checked')
if (preset.shortcuts === 'show') {
$('#settings-shortcut-input').setAttribute('checked', 'checked')
}

$('#settings-writing-mode-shortcut-input').value = preset.writingModeShortcut
$('#settings-css-textarea').value = preset.css
Expand Down Expand Up @@ -172,6 +179,14 @@ const setupSettingsDialog = () => {
})
})

shortcutInput.addEventListener('change', (ev) => {
const newValue = ev.target.checked ? 'show' : 'hide'
store.set({ shortcuts: newValue }, () => {
localStorage.setItem('shortcuts', newValue)
loadBookmarks()
})
})

doneButton.addEventListener('click', () => {
$('.overlay').classList.add('hidden')
$('#settings-dialog').classList.add('hidden')
Expand Down Expand Up @@ -438,6 +453,16 @@ const loadSyncedTabs = () => {
}

const loadBookmarks = () => {
// same as
// const showTabs = !localStorage.getItem('devices') || localStorage.getItem('devices') && localStorage.getItem('devices') === 'show'
// but removed an unwanted section
const showBookmarks = !localStorage.getItem('shortcuts') || localStorage.getItem('shortcuts') === 'show'

if (!showBookmarks) {
$('.bookmarks-box').innerHTML = ''
return
}

chrome.bookmarks.getSubTree('1', (tree) => {
const folder = tree[0].children.find(v => v.title.toLowerCase() === SHORTCUTS_FOLDER.toLowerCase())

Expand Down
4 changes: 4 additions & 0 deletions src/new-tab-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@
<input id="settings-battery-input" type="checkbox" />
<label class="inline" for="settings-battery-input">Show Battery</label>
</div>
<div class="input-container">
<input id="settings-shortcut-input" type="checkbox" />
<label class="inline" for="settings-shortcut-input">Show Shortcuts</label>
</div>
</div>
<div class="menu-divider" style="margin-bottom: 1rem;"></div>
<details>
Expand Down