Skip to content

Commit

Permalink
Tweak navigation and UI so new duplicate option matches current window
Browse files Browse the repository at this point in the history
  • Loading branch information
Skeletonxf committed Nov 10, 2024
1 parent f65f62c commit ff59310
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
32 changes: 19 additions & 13 deletions src/duplicate-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,35 +136,41 @@ export default class DuplicateTab {
async #respondToPage(data, sender) {
try {
const { url, incognito, id } = await settings.session.getKeyValue(oldTabData)
if (data.selected === 'normal' || data.selected === 'normal-and-navigate-back') {
let goBack = async () => {
// We can only try to navigate back on the old tab because
// we need to have the activeTab permission as we're not
// requesting the generic scripting permission from the user
await browser.scripting.executeScript({
target: {
tabId: id
},
func: () => {
window.history.back()
}
})
}
if (data.selected === 'normal' || (data.selected === 'normal-and-navigate-back' && !incognito)) {
if (incognito === false) {
await this.#duplicateSameTypeOfTab(id)
} else {
await this.#createNewTabInWindow(url, false, true)
await this.#getAndCloseAdvancedDuplicationPageAndClearData()
}
if (data.selected === 'normal-and-navigate-back') {
// We can only try to navigate back on the old tab because
// we need to have the activeTab permission as we're not
// requesting the generic scripting permission from the user
await browser.scripting.executeScript({
target: {
tabId: id
},
func: () => {
window.history.back()
}
})
await goBack()
}
return true
}
if (data.selected === 'private') {
if (data.selected === 'private' || (data.selected === 'normal-and-navigate-back' && incognito)) {
if (incognito === true) {
await this.#duplicateSameTypeOfTab(id)
} else {
await this.#createNewTabInWindow(url, true, true)
await this.#getAndCloseAdvancedDuplicationPageAndClearData()
}
if (data.selected === 'normal-and-navigate-back') {
await goBack()
}
return true
}
if (data.selected === 'window' || data.selected === 'move-window') {
Expand Down
4 changes: 4 additions & 0 deletions src/page/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ buttons.forEach((b) => b.deleter = new IdempotentElementDeleter(b.element))
buttons.get('window').element.classList.remove('normal-style')
buttons.get('move-window').element.classList.add('private-style')
buttons.get('move-window').element.classList.remove('normal-style')
buttons.get('normal-and-navigate-back').element.classList.add('private-style')
buttons.get('normal-and-navigate-back').element.classList.remove('normal-style')
let navigateBackTabNav = document.querySelector('#normal-and-navigate-back-tab-name')
navigateBackTabNav.textContent = 'Private Browsing'
}
const { allowedIncognitoAccess } = response
if (allowedIncognitoAccess === false) {
Expand Down
9 changes: 1 addition & 8 deletions src/page/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,8 @@ <h1 id="header">
<span><span class="button-shortcut">M</span>ove to new Window</span>
<span class="shortcut window-shortcut">4</span>
</button>
<!--
TODO: Probably more helpful if this dynamically swaps between opening
in a Normal tab and Private tab to match the tab the window was in
as opening a private tab back in a non private window and navigating
the private tab back seems very niche compared to keeping both of them
private
-->
<button id="normal-and-navigate-back" class="grid-button-item normal-style" tabindex="1">
<span>Normal Tab and navigate <span class="button-shortcut">B</span>ack</span>
<span><span id="normal-and-navigate-back-tab-name">Normal</span> Tab and navigate <span class="button-shortcut">B</span>ack</span>
<span class="shortcut dark-shortcut">5</span>
</button>
</div>
Expand Down

0 comments on commit ff59310

Please sign in to comment.