Initial commit, added license, added readme, added wcagToMarkdownChecklist script

This commit is contained in:
2025-11-24 21:04:29 +01:00
commit d97d78c5af
3 changed files with 78 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
/*
Extracts the table of contents from [see supported pages] into your clipboard as a markdown checklist
Supported pages:
- https://www.w3.org/TR/WCAG21/
- https://www.w3.org/TR/WCAG22/
- https://www.w3.org/TR/wcag-3.0/
How to use:
1. Open the page
2. Copy the script below
3. Open the developer console (usually with "F12" and by then navigating to "Console" in the developer settings)
4. Paste the script and press enter to confirm
5. A red button appears on the page. Click it.
6. The checklist is now in your clipboard. Paste it whereever you need.
*/
let indentation = "\t"; // Choose your indentation
const copyButton = document.createElement('button');
copyButton.textContent = 'Copy TOC to Clipboard';
copyButton.style.position = 'fixed';
copyButton.style.top = '20px';
copyButton.style.right = '90px';
copyButton.style.zIndex = '1000';
copyButton.style.backgroundColor = 'red';
copyButton.style.color = 'white';
copyButton.style.scale = '2';
copyButton.addEventListener('click', function() {
let elements = document.querySelectorAll(".toc .tocline .tocxref:has(bdi)");
let text = "";
elements.forEach(element => {
let text1 = element.childNodes[0].textContent;
let text2 = element.childNodes[1].textContent;
let segmentCount = text1.replace(". ", "").split(".").length;
text += indentation.repeat(segmentCount - 1) + "- [ ] " + text1 + text2 + "\n";
});
navigator.clipboard.writeText(text)
.then(() => {
console.log("Copied to clipboard successfully!");
this.textContent = "Copied!";
setTimeout(() => {
this.textContent = "Copy TOC to Clipboard";
}, 2000);
})
.catch(err => {
console.error("Failed to copy: ", err);
alert("Failed to copy to clipboard. Please try again or copy manually.");
});
});
document.body.appendChild(copyButton);