Skip to content

Instantly share code, notes, and snippets.

@raksheetbhat
Created March 31, 2025 05:56
Show Gist options
  • Save raksheetbhat/335d819297f5e6ece9c411338488f3e6 to your computer and use it in GitHub Desktop.
Save raksheetbhat/335d819297f5e6ece9c411338488f3e6 to your computer and use it in GitHub Desktop.
Chrome extension to autofill form
function setFormValues(inputTxt) {
// var inputTxt = "CREATE CATALOG mysql_catalog WITH (connector = 'mysql',connection-url = 'jdbc:mysql://your-mysql-host:3306/database_name',connection-user = 'your_username',connection-password = 'your_password');";
var regex = /([a-zA-Z-]+)\s*=\s*'([^']*)'/g;
for (const match of inputTxt.matchAll(regex)) {
console.log(`${match[1]} ${match[2]}`);
var key = match[1];
var val = match[2];
if (document.getElementById(key)) {
document.getElementById(key).value = val;
}
}
}
async function getCurrentTab() {
let queryOptions = { active: true, lastFocusedWindow: true };
// `tab` will either be a `tabs.Tab` instance or `undefined`.
let [tab] = await chrome.tabs.query(queryOptions);
return tab;
}
function ex(tabId, data) {
chrome.scripting.executeScript({
target: { tabId: tabId },
func: setFormValues,
args: [data]
})
.then(() => console.log("injected a function"));
}
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('submit').addEventListener('click', function () {
var val = document.getElementById('trino-command').value;
getCurrentTab()
.then(data => ex(data.id, val));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment