Skip to content

Instantly share code, notes, and snippets.

@picheli20
Last active September 12, 2024 09:01
Show Gist options
  • Save picheli20/a0616168b8dfc13f1f4d4a487ba65cb4 to your computer and use it in GitHub Desktop.
Save picheli20/a0616168b8dfc13f1f4d4a487ba65cb4 to your computer and use it in GitHub Desktop.
Create automatically tags
(async () => {
const text = `
a 1
b 2
c 3
d 4
`;
const addRowClass = `wd-vt-simple-table-add-row`;
// const removeRowClass = `wd-vt-st-remove-row-button`;
// Click on remove on all rows
[...document.getElementsByClassName('wd-vt-st-remove-row-button')].forEach((element) => {
element.click();
});
const lines = text.trim().split('\n').filter((line) => line.trim() !== '');
// Add rows
lines.forEach(() => {
document.getElementsByClassName(addRowClass)[0].click();
});
const rowElement = `body > div.gtm-sheet-holder.wd-sheet-holder.gtm-sheet-holder--animated > div:nth-child(2) > gtm-variable-editor > div > form > gtm-veditor > div > div > div.sheet-scrollpane > div > gtm-veditor-section > div > div.gtm-veditor-index-container > div.veditor__section__content > section-content > div:nth-child(2) > vt-instance > vt-params > vt-simple-table > div > table > tbody > tr`;
const rows = [...document.querySelectorAll(rowElement)];
// Fill rows with data
for (let index = 0; index < lines.length; index++) {
const line = lines[index];
const [key, value] = line.split('\t');
const [keyElement, valueElement] = rows[index].getElementsByClassName('ctui-text-input');
await simulateKeyboard(keyElement, key);
await simulateKeyboard(valueElement, value);
}
async function simulateKeyboard(element, message) {
for (let i = 0; i < message.length; i++) {
const char = message[i];
const prevValue = element.value;
element.value = prevValue + char;
// Dispatch input event to notify the component about the change
element.dispatchEvent(new Event('input', { bubbles: true }));
}
// Optionally, dispatch a change event after typing is finished
element.dispatchEvent(new Event('change', { bubbles: true }));
}
})();
@picheli20
Copy link
Author

Variables -> Create Variables -> RegEx Table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment