Skip to content

Instantly share code, notes, and snippets.

@trungpv1601
Created December 30, 2024 08:04
Show Gist options
  • Save trungpv1601/525674da39757a105421e18c618c3aa2 to your computer and use it in GitHub Desktop.
Save trungpv1601/525674da39757a105421e18c618c3aa2 to your computer and use it in GitHub Desktop.
const tags = ["JavaScript", "Web Development", "Programming", "Tech", "Coding"];
for (const tag of tags) {
const tagDiv = document.querySelector('div.tags-input[contenteditable="true"]');
const tagInput = document.querySelector('div.tags-input[contenteditable="true"] p[data-testid="editorParagraphText"]');
if (!tagDiv || !tagInput) {
console.error("Oops.");
} else {
console.log("Found.");
}
const anchor = document.createElement('a');
anchor.href = '#';
anchor.dataset.href = '#';
anchor.className = 'markup--anchor markup--p-anchor';
anchor.rel = 'token';
anchor.textContent = tag;
tagInput.textContent = '';
tagInput.appendChild(anchor);
const enterEvent = new KeyboardEvent('keydown', {
key: 'Enter',
code: 'Enter',
keyCode: 13,
which: 13,
bubbles: true,
cancelable: true,
composed: true
});
tagDiv.dispatchEvent(enterEvent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment