Jacob Cofman

Jacob Cofman

//a11y.js
(function () {
var tota11y = document.createElement('SCRIPT');
tota11y.type = 'text/javascript';
tota11y.src = 'https://cdnjs.cloudflare.com/ajax/libs/tota11y/0.1.6/tota11y.min.js';
document.getElementsByTagName('head')[0].appendChild(tota11y);
})();
// Menu: Chrome Snippet runner
// Description: List all scripts or bookmarklets you have and runs them inside chrome.
// Author: jcofman
// Twitter: @jcofman
import "@johnlindquist/kit";
import { readdirSync, readFileSync } from "fs";
let SNIPPETS_FOLDER = await env("SNIPPET_FOLDER", {
hint: md(
`Path to folder e.g. /Users/jacobcofman/Documents/chrome-snippets`
),
ignoreBlur: true,
secret: false,
})
let snippetsFolder = await env("SNIPPET_FOLDER")
if (!(await isDir(snippetsFolder))) {
mkdir("-p", snippetsFolder)
}
const getSnippets = (folder) => {
const snippets = [];
const files = readdirSync(folder);
files.forEach((file) => {
if (file.endsWith(".js")) {
snippets.push(file);
}
});
return snippets;
};
let snippetsToRun = getSnippets(SNIPPETS_FOLDER);
let snippetFileToRun = await arg(
"Select Snippet to run:",
snippetsToRun.map((file) => file)
);
const snippetFileContentToRun = readFileSync(
SNIPPETS_FOLDER + "/" + snippetFileToRun,
"utf8"
);
const runSnippet = async () => {
await applescript(String.raw`
tell application "Google Chrome"
execute front window's active tab javascript "${snippetFileContentToRun}"
end tell
`);
}
await runSnippet();
// Name: DeepL
// Author: Jacob Cofman
// Twitter: @jcofman
// Description: Translates text using https://www.deepl.com/translator
import "@johnlindquist/kit"
let DEEPL_AUTH_KEY = await env("DEEPL_AUTH_KEY", {
hint: md(
`Get a [DeepL API Key](https://www.deepl.com/docs-api/accessing-the-api/)`
),
ignoreBlur: true,
secret: true,
})
let text = await getSelectedText();
let targetLanguage = await arg("Select a traget Language e.g: DE or EN")
let response = await post(
`https://api-free.deepl.com/v2/translate?auth_key=${DEEPL_AUTH_KEY}&text=${text}&target_lang=${targetLanguage}`
)
setSelectedText(response.data.translations[0].text)