Run bookmarklets from Script Kit

I love to run Bookmarklets for custom developer tools like a11y. Thanks to Script Kit I can run them without polluting my bookmarks or having to open dev tools.

An example script I love to use.

//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);
})();

There are many more scripts you can easily add e.g. https://github.com/bgrins/devtools-snippets an older collection I started to create https://github.com/JCofman/ChromeBrowserSnippets

  1. Make sure you allow your mac to run JS from Apple Events. View > Settings > Developer > Allow JavaScript from Apple Events

Open chrome-tab-snippet-runner in Script Kit

// 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();