First commit

This commit is contained in:
Violet Millie 2024-01-26 15:08:29 +00:00
commit 7795c1d2cc
11 changed files with 355 additions and 0 deletions

189
.gitignore vendored Normal file
View File

@ -0,0 +1,189 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
# Logs
logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Caches
.cache
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
# Runtime data
pids
_.pid
_.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# IntelliJ based IDEs
.idea
# Finder (MacOS) folder config
.DS_Store
# VS Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
# Local History for Visual Studio Code
.history/
# Built Visual Studio Code Extensions
*.vsix

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"editor.tabSize": 2
}

4
README.md Normal file
View File

@ -0,0 +1,4 @@
# akkoma-keybinds
A Firefox extension adding keybinds to the Akkoma front end.

BIN
bun.lockb Executable file

Binary file not shown.

17
package.json Normal file
View File

@ -0,0 +1,17 @@
{
"name": "akkoma-keybinds",
"module": "dist/extension/content.js",
"type": "module",
"scripts": {
"web-ext": "web-ext run -s dist -p default -u social.violetmillie.me",
"run-dev": "rm -rf dist && mkdir dist && cp src/extension/manifest.json dist && bun web-ext & bun build src/extension/typescript/content.ts --outdir dist/ --watch"
},
"devDependencies": {
"@types/bun": "latest",
"web-ext": "^7.11.0"
},
"peerDependencies": {
"typescript": "^5.0.0"
}
}

View File

@ -0,0 +1,26 @@
{
"name": "Akkoma Keybinds",
"description": "Introduces keybind controls to the Akkoma front end",
"version": "0.1",
"browser_specific_settings": {
"gecko": {
"id": "akkomakeybinds@violetmillie.me",
"strict_min_version": "42.0"
}
},
"background": {
"scripts": ["Background.js"]
},
"content_scripts": [
{
"matches": ["https://social.violetmillie.me/*"],
"js": ["Content.js"]
}
],
"manifest_version": 2
}

View File

@ -0,0 +1,30 @@
import KeybindManager from "./KeybindManager";
import RegisterKeybinds from "./RegisterKeybinds";
console.log("Akkoma keybinds loaded!");
const manager = new KeybindManager();
RegisterKeybinds(manager);
document.addEventListener("keydown", (ev) => {
const keybind = manager.getBindForKey(ev.key);
if (!keybind) {
return;
}
if (
ev.isComposing ||
(ev.target !== document.body && !keybind.allowWhileComposing)
) {
return;
}
// const keybind = manager.getBindForKey(ev.key);
ev.preventDefault();
keybind.execute();
});

View File

@ -0,0 +1,31 @@
export type Keybind = {
/** A string contaning the key that must be pressed to trigger the keybinding */
key: string;
/** The callback function to be called when the keybind is triggered */
execute: Function;
/** Whether the keybind can be triggered when composing */
allowWhileComposing?: boolean;
};
export default class KeybindManager {
constructor() {}
registeredKeybinds: Keybind[] = [];
getBindForKey(key: string): Keybind | undefined {
return this.registeredKeybinds.find(
(registeredKey) => registeredKey.key === key
);
}
registerKeybind(keybind: Keybind) {
if (this.getBindForKey(keybind.key)) {
return;
}
this.registeredKeybinds.push(keybind);
}
}

View File

@ -0,0 +1,8 @@
import type KeybindManager from "./KeybindManager";
import ComposeKeybind from "./keybinds/ComposeKeybind";
export default async function (keybindManager: KeybindManager) {
keybindManager.registerKeybind(ComposeKeybind);
}

View File

@ -0,0 +1,24 @@
import type { Keybind } from "../KeybindManager";
const keybind: Keybind = {
key: "n",
execute: function () {
// console.log("Hello");
const element = document.querySelector(
".signed-in > div:nth-child(2) > form:nth-child(1) > div:nth-child(1) > div:nth-child(3) > textarea:nth-child(1)"
);
if (!element) {
return;
}
const composeArea = element as HTMLElement;
composeArea.focus();
composeArea.textContent = "Hello";
},
};
export default keybind;

23
tsconfig.json Normal file
View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
/* Linting */
"skipLibCheck": true,
"strict": true,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true
}
}