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

Experimental: Opera keyboard shortcut to open TFAC #45

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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: 10 additions & 17 deletions src/opera/ext-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,15 @@ try {
console.error(e)
}

// Opera does not support the chrome_url_overrides property
// in manifest.json, so this is a workaround.
// However, we cannot distribute the extension, because as
// of 2021.8.05, Opera acceptance criteria don't allow custom
// new tab pages:
// "Extensions cannot replace Opera’s default start page."
// https://dev.opera.com/extensions/acceptance-criteria/
const redirectURLS = [
'opera://startpage/',
'browser://startpage/',
'chrome://startpage/',
'chrome://startpageshared/'
]

chrome.tabs.onUpdated.addListener(async function (tabId, changeInfo, tab) {
if (redirectURLS.includes(tab.url)) {
await chrome.tabs.update(tab.id, { url: 'http://tab.gladly.io/newtab/' })
// When the user calls a new tab key shortcut defined in manifest.json,
// open Tab for a Cause.
// This is a workaround because Opera:
// * does not support the chrome_url_overrides property
// * does not allow replacing the start page. See:
// https://dev.opera.com/extensions/acceptance-criteria/
const NEW_TAB_URL = 'http://tab.gladly.io/newtab/'
chrome.commands.onCommand.addListener((commandName) => {
if (commandName === 'open-tab') {
chrome.tabs.create({ url: NEW_TAB_URL })
}
})
8 changes: 8 additions & 0 deletions src/opera/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
"background": {
"service_worker": "ext-background.js"
},
"commands": {
"open-tab": {
"suggested_key": {
"default": "Ctrl+K"
},
"description": "Open Tab for a Cause."
}
},
"permissions": ["tabs"],
"update_url": "http://clients2.google.com/service/update2/crx",
"version": "1.0"
Expand Down
10 changes: 10 additions & 0 deletions src/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ global.localStorage = {

// Mock Chrome extension APIs
global.chrome = {
commands: {
onCommand: {
addListener: jest.fn()
}
},
runtime: {
onInstalled: {
addListener: jest.fn()
Expand All @@ -35,6 +40,11 @@ global.chrome = {

// Mock Firefox extension APIs
global.browser = {
commands: {
onCommand: {
addListener: jest.fn()
}
},
runtime: {
onInstalled: {
addListener: jest.fn()
Expand Down