commit d97d78c5af03e6115bbd8a5cf0a89c86f7deeaa7 Author: LD-Reborn Date: Mon Nov 24 21:04:29 2025 +0100 Initial commit, added license, added readme, added wcagToMarkdownChecklist script diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4969ccf --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 LD-Reborn + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..2df8be4 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Snippets +Feel free to explore and dig for copper. + +Something's broken or you want to contribute a missing piece? Feel free to open an issue or start a discussion. \ No newline at end of file diff --git a/src/javascript/wcagToMarkdownChecklist.js b/src/javascript/wcagToMarkdownChecklist.js new file mode 100644 index 0000000..a8365b9 --- /dev/null +++ b/src/javascript/wcagToMarkdownChecklist.js @@ -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); \ No newline at end of file