Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

Use firefox native click behavior in versions >= 96 #338

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
30 changes: 17 additions & 13 deletions src/modes/hints/background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import { generateHintStrings } from './hintStrings'
let hintChars = 'adsfghjkl;'
let autoActivateHint = false

const firefoxNoNativeClick =
SAKA_PLATFORM === 'firefox' &&
navigator.userAgent.match(/\bFirefox\/(\d+)/)[1] < 96

export default {
onOptionsChange: options => {
onOptionsChange: (options) => {
hintChars = options.hintChars.length >= 2 ? options.hintChars : 'bad'
autoActivateHint = options.autoActivateHint
},
Expand Down Expand Up @@ -51,56 +55,56 @@ export default {
}
} catch (e) {}
},
openLinkInIncognitoWindow: url => {
openLinkInIncognitoWindow: (url) => {
// TODO: consider more robust URL verification like Vimium's
browser.windows.create({ url, incognito: true })
},
// Needed to activate links on firefox because it ignores keyboard modifiers
// or doesn't execute default behaviors on click events
...(SAKA_PLATFORM === 'chrome'
? {}
: {
openLinkInBackgroundTab: url => {
// or doesn't execute default behaviors on click events (in versions < 96)
...(firefoxNoNativeClick
? {
openLinkInBackgroundTab: (url) => {
const arg = {
url: url,
active: false
}
browser.tabs
.query({ currentWindow: true, active: true })
.then(t => {
.then((t) => {
arg.cookieStoreId = t[0].cookieStoreId
})
.finally(() => {
browser.tabs.create(arg)
})
},
openLinkInForegroundTab: url => {
openLinkInForegroundTab: (url) => {
const arg = {
url: url,
active: true
}
browser.tabs
.query({ currentWindow: true, active: true })
.then(t => {
.then((t) => {
arg.cookieStoreId = t[0].cookieStoreId
})
.finally(() => {
browser.tabs.create(arg)
})
},
openLinkInNewWindow: url => {
openLinkInNewWindow: (url) => {
const arg = {
url: url
}
browser.tabs
.query({ currentWindow: true, active: true })
.then(t => {
.then((t) => {
arg.cookieStoreId = t[0].cookieStoreId
})
.finally(() => {
browser.windows.create(arg)
})
}
})
}
: {})
}
}
12 changes: 8 additions & 4 deletions src/modes/hints/client/activate.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ export function activate (event, target) {
* is selected using hints mode.
* @type {{ [key: string]: (event: KeyboardEvent, target: HTMLElement) => string }}
*/
const firefoxNoNativeClick =
SAKA_PLATFORM === 'firefox' &&
navigator.userAgent.match(/\bFirefox\/(\d+)/)[1] < 96

const activators = {
openLink: (event, target) => {
if (
SAKA_PLATFORM === 'firefox' &&
firefoxNoNativeClick &&
target.nodeName === 'A' &&
target.target === '_blank'
) {
Expand All @@ -40,7 +44,7 @@ const activators = {
},
openLinkInBackgroundTab: (event, target) => {
mouseEvent(target, 'click', { ctrlKey: !isMac, metaKey: isMac })
if (SAKA_PLATFORM === 'firefox') {
if (firefoxNoNativeClick) {
backgroundOpenLink('openLinkInBackgroundTab', target)
}
target.focus()
Expand All @@ -52,15 +56,15 @@ const activators = {
metaKey: isMac,
shiftKey: true
})
if (SAKA_PLATFORM === 'firefox') {
if (firefoxNoNativeClick) {
backgroundOpenLink('openLinkInForegroundTab', target)
}
target.focus()
return 'Reset'
},
openLinkInNewWindow: (event, target) => {
mouseEvent(target, 'click', { shiftKey: true })
if (SAKA_PLATFORM === 'firefox') {
if (firefoxNoNativeClick) {
backgroundOpenLink('openLinkInNewWindow', target)
}
target.focus()
Expand Down