Skip to content
Snippets Groups Projects
Commit 67c6943e authored by Valentin Rigal's avatar Valentin Rigal
Browse files

Load example content script

parent 1f472f27
No related branches found
No related tags found
2 merge requests!4Setup CI,!3Setup the stack to use Vue in both the web extension and a regular html form
const inputFields = document.getElementsByTagName("input");
const replacements = {
a: "b",
};
// Create a simple keyboard
const buttonA = document.createElement("button");
buttonA.textContent = 'Insert "a"';
const buttonB = document.createElement("button");
buttonB.textContent = 'Insert "b"';
const keyboard = document.createElement("div");
keyboard.appendChild(buttonA);
keyboard.appendChild(buttonB);
let selectedInput = null;
const addChar = (i, char) => {
const start = i.selectionStart;
i.value = i.value.slice(0, start) + char + i.value.slice(i.selectionEnd);
// Updating the input value moves the caret to the end by default
i.selectionStart = i.selectionEnd = start + 1;
};
for (const input of inputFields) {
input.onkeydown = (e) => {
const character = replacements[e.key];
if (!character) return;
addChar(input, character);
return false;
};
// Handle the case where the input is already focused
if (document.activeElement === input) {
input.parentElement.appendChild(keyboard);
selectedInput = input;
}
input.onfocus = () => {
input.parentElement.appendChild(keyboard);
selectedInput = input;
};
// https://css-tricks.com/a-css-approach-to-trap-focus-inside-of-an-element/
input.ontransitionend = (e) => {
if (input.matches(":focus") || keyboard.contains(document.activeElement))
e.target.focus();
else {
input.parentElement.removeChild(keyboard);
selectedInput = null;
}
};
}
keyboard.onclick = () => {
return false;
};
buttonA.onmouseup = () => {
if (selectedInput) addChar(selectedInput, "a");
};
buttonB.onmouseup = () => {
if (selectedInput) addChar(selectedInput, "b");
};
......@@ -24,5 +24,12 @@
"options_ui": {
"page": "options.html",
"browser_style": true
}
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["js/content.js"],
"css": ["css/content.css"]
}
]
}
......@@ -13,6 +13,17 @@ module.exports = {
},
},
pluginOptions: {
browserExtension: {},
browserExtension: {
components: {
contentScripts: true,
},
componentOptions: {
contentScripts: {
entries: {
content: "src/content/content.js",
},
},
},
},
},
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment