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

Base with vue-webextension

parent 8ef8afae
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
Showing
with 13584 additions and 2797 deletions
> 1%
last 2 versions
not dead
module.exports = {
root: true,
env: {
node: true,
webextensions: true,
},
extends: ["plugin:vue/essential", "eslint:recommended", "@vue/prettier"],
parserOptions: {
parser: "babel-eslint",
},
rules: {
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
},
};
.DS_Store
node_modules node_modules
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
# Vue Browser Extension Output
*.pem
*.pub
*.zip
/artifacts
# Virtual Keyboard # Virtual Keyboard
## Setup
`npm i`
## Development ## Development
`npm run start:firefox` `npm run serve`
module.exports = {
presets: ["@vue/cli-plugin-babel/preset"],
};
extension-dist/icons/keyboard-32.png

2.71 KiB

extension-dist/icons/keyboard-96.png

3.97 KiB

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
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 = e => {
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 = e => {
return false
}
buttonA.onmouseup = e => {
if (selectedInput) addChar(selectedInput, "a")
}
buttonB.onmouseup = e => {
if (selectedInput) addChar(selectedInput, "b")
}
{
"manifest_version": 2,
"name": "Virtual keyboard",
"version": "0.0.1",
"description": "Adds a customizable virtual keyboard on text input areas.",
"icons": {
"48": "icons/keyboard-48.png",
"96": "icons/keyboard-96.png"
},
"browser_action": {
"default_icon": {
"19": "icons/keyboard-19.png",
"32": "icons/keyboard-32.png"
},
"default_title": "Virtual Keyboard"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["index.js"],
"css": ["style.css"]
}
]
}
input:not(:focus-within) {
border-color: black;
transition: border-color 0.001s;
}
This diff is collapsed.
{ {
"name": "virtual-keyboard", "name": "virtual-keyboard",
"version": "0.0.1", "version": "0.1.0",
"description": "Adds a customizable virtual keyboard on text input areas.", "description": "Customizable unicode virtual keyboard on text input.",
"main": "extension-dist/index.js", "private": true,
"scripts": { "scripts": {
"start:firefox": "web-ext run --source-dir ./extension-dist/" "serve": "vue-cli-service build --mode development --watch",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
}, },
"dependencies": { "dependencies": {
"web-ext": "6.1.0" "axios": "^0.20.0",
"core-js": "^3.6.5",
"vue": "^2.6.11",
"vue-router": "^3.2.0",
"vuex": "^3.4.0"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-plugin-router": "~4.5.0",
"@vue/cli-plugin-vuex": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"@vue/eslint-config-prettier": "^6.0.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-vue": "^6.2.2",
"lint-staged": "^9.5.0",
"prettier": "^2.2.1",
"sass": "^1.26.5",
"sass-loader": "^8.0.2",
"vue-cli-plugin-browser-extension": "latest",
"vue-template-compiler": "^2.6.11"
},
"gitHooks": {
"pre-commit": "lint-staged"
},
"lint-staged": {
"*.{js,jsx,vue}": [
"vue-cli-service lint",
"git add"
]
} }
} }
{
"name": "virtual-keyboard",
"version": "0.0.1",
"description": "Adds a customizable virtual keyboard on text input areas.",
"main": "extension-dist/index.js",
"scripts": {
"start:firefox": "web-ext run --source-dir ./virtual-keyboard/"
},
"dependencies": {
"web-ext": "6.1.0"
}
}
{
"extName": {
"message": "Virtual keyboard",
"description": ""
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<div id="app"></div>
</body>
</html>
public/favicon.ico

4.19 KiB

public/icons/keyboard-128.png

4.63 KiB

public/icons/keyboard-16.png

2.13 KiB

File moved
public/icons/keyboard-38.png

4.3 KiB

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