mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-16 06:18:35 +02:00
Merge branch 'main' into native-update
This commit is contained in:
@@ -39,7 +39,7 @@ browser.browserAction.onClicked.addListener(toggleBookmark);
|
||||
/*
|
||||
* Switches currentTab and currentBookmark to reflect the currently active tab
|
||||
*/
|
||||
function updateActiveTab(tabs) {
|
||||
function updateAddonStateForActiveTab(tabs) {
|
||||
|
||||
function isSupportedProtocol(urlString) {
|
||||
let supportedProtocols = ["https:", "http:", "ftp:", "file:"];
|
||||
@@ -68,19 +68,19 @@ function updateActiveTab(tabs) {
|
||||
}
|
||||
|
||||
// listen for bookmarks being created
|
||||
browser.bookmarks.onCreated.addListener(updateActiveTab);
|
||||
browser.bookmarks.onCreated.addListener(updateAddonStateForActiveTab);
|
||||
|
||||
// listen for bookmarks being removed
|
||||
browser.bookmarks.onRemoved.addListener(updateActiveTab);
|
||||
browser.bookmarks.onRemoved.addListener(updateAddonStateForActiveTab);
|
||||
|
||||
// listen to tab URL changes
|
||||
browser.tabs.onUpdated.addListener(updateActiveTab);
|
||||
browser.tabs.onUpdated.addListener(updateAddonStateForActiveTab);
|
||||
|
||||
// listen to tab switching
|
||||
browser.tabs.onActivated.addListener(updateActiveTab);
|
||||
browser.tabs.onActivated.addListener(updateAddonStateForActiveTab);
|
||||
|
||||
// listen for window switching
|
||||
browser.windows.onFocusChanged.addListener(updateActiveTab);
|
||||
browser.windows.onFocusChanged.addListener(updateAddonStateForActiveTab);
|
||||
|
||||
// update when the extension loads initially
|
||||
updateActiveTab();
|
||||
updateAddonStateForActiveTab();
|
||||
|
||||
1224
examples.json
1224
examples.json
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,15 @@
|
||||
# Favourite Colour
|
||||
|
||||
Shows and stores your favourite colour, in storage.sync in the about:addons page for the add-on.
|
||||
Shows and stores your favourite colour, in storage.sync in the extension's about:addons page.
|
||||
|
||||
Demonstrates:
|
||||
|
||||
* storing data with storage.sync
|
||||
* reading data from storage.managed
|
||||
* creating an options page and opening it with `runtime.openOptionsPage()`
|
||||
* best practice for supporting automatic theme switching (dark theme) in the options page
|
||||
|
||||
* reading data from storage.managed,
|
||||
* creating an options page and opening it with `runtime.openOptionsPage()`.
|
||||
|
||||
To have Firefox read data from storage.managed, create a file with the following contents:
|
||||
To have Firefox read data from storage.managed, create a file with this content:
|
||||
|
||||
{
|
||||
"name": "favourite-colour-examples@mozilla.org",
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="color-scheme" content="dark light">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
@@ -16,21 +16,15 @@ key_path = 'Software\\Mozilla\\NativeMessagingHosts\\ping_pong'
|
||||
# Assuming current user overrides local machine.
|
||||
key_roots = ['HKEY_CURRENT_USER', 'HKEY_LOCAL_MACHINE']
|
||||
|
||||
found_key = False
|
||||
|
||||
for root in key_roots:
|
||||
key = winreg.OpenKey(getattr(winreg, root), key_path)
|
||||
for key_root in key_roots:
|
||||
try:
|
||||
print('Checking:', root, key_path)
|
||||
print('Checking:', key_root, key_path)
|
||||
key = winreg.OpenKey(getattr(winreg, key_root), key_path)
|
||||
res = winreg.QueryValueEx(key, '')
|
||||
break
|
||||
except FileNotFoundError:
|
||||
print('...error finding key')
|
||||
continue
|
||||
|
||||
found_key = True
|
||||
break
|
||||
|
||||
if not found_key:
|
||||
print('... error finding key')
|
||||
else:
|
||||
raise ValueError('Could not find a registry entry, aborting.')
|
||||
|
||||
json_path = res[0]
|
||||
|
||||
Reference in New Issue
Block a user