mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-21 00:32:48 +02:00
Added an example for contentScripts.register
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
const hostsInput = document.querySelector("#hosts");
|
||||
const codeInput = document.querySelector("#code");
|
||||
|
||||
const defaultHosts = "*://*.org/*";
|
||||
const defaultCode = "document.body.innerHTML = '<h1>This page has been eaten<h1>'";
|
||||
|
||||
hostsInput.value = defaultHosts;
|
||||
codeInput.value = defaultCode;
|
||||
|
||||
async function registerScript() {
|
||||
let background = await browser.runtime.getBackgroundPage();
|
||||
background.register(hostsInput.value.split(","), codeInput.value)
|
||||
}
|
||||
|
||||
document.querySelector("#register").addEventListener('click', registerScript);
|
||||
Reference in New Issue
Block a user