Skip to content

Commit

Permalink
"Open in new tab" removed for Safari
Browse files Browse the repository at this point in the history
  • Loading branch information
victrme committed Sep 30, 2024
1 parent b5ecb5c commit 7ded95a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
26 changes: 4 additions & 22 deletions src/scripts/features/links/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,7 @@ function createElem(link: Links.Elem, openInNewtab: boolean, style: Style) {
}

if (openInNewtab) {
if (BROWSER === 'safari') {
anchor.onclick = handleSafariNewtab
} else {
anchor.target = '_blank'
}
anchor.target = '_blank'
}

return li
Expand Down Expand Up @@ -612,18 +608,10 @@ function setOpenInNewTab(newtab: boolean, data: Sync.Storage): Sync.Storage {
const anchors = document.querySelectorAll<HTMLAnchorElement>('.link a')

for (const anchor of anchors) {
if (BROWSER === 'safari') {
if (newtab) {
anchor.addEventListener('click', handleSafariNewtab)
} else {
anchor.removeEventListener('click', handleSafariNewtab)
}
if (newtab) {
anchor.setAttribute('target', '_blank')
} else {
if (newtab) {
anchor.setAttribute('target', '_blank')
} else {
anchor.removeAttribute('target')
}
anchor.removeAttribute('target')
}
}

Expand Down Expand Up @@ -682,12 +670,6 @@ function setRows(row: string) {
eventDebounce({ linksrow: row })
}

function handleSafariNewtab(e: Event) {
const anchor = e.composedPath().filter((el) => (el as Element).tagName === 'A')[0]
window.open((anchor as HTMLAnchorElement)?.href)
e.preventDefault()
}

// Helpers

export function validateLink(title: string, url: string, parent?: string): Links.Elem {
Expand Down
10 changes: 6 additions & 4 deletions src/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,13 @@ <h2 class="trn">Quick Links</h2>
>
</p>

<hr />
<div class="not-safari">
<hr />

<div class="linknewtab wrapper">
<label for="i_linknewtab" class="trn">Open in new tab</label>
<input id="i_linknewtab" class="switch" type="checkbox" />
<div class="linknewtab wrapper">
<label for="i_linknewtab" class="trn">Open in new tab</label>
<input id="i_linknewtab" class="switch" type="checkbox" />
</div>
</div>

<hr />
Expand Down

0 comments on commit 7ded95a

Please sign in to comment.