2024 / 12 / 5
无障碍优化:
1. 让屏幕阅读器跳过时间戳,通过为 <div class="time">
添加 aria-hidden="true"
属性
2. 让屏幕阅读器跳过顶部导航区域,通过为 <div class="top">
添加 aria-hidden="true"
属性
3. 让屏幕阅读器跳过 YouTube 视频标题,通过为包含 "- YouTube" 的段落添加 aria-hidden="true"
属性
功能增强:
1. 将外部的 select.js
文件内容直接内联到 HTML 文件中,减少了外部文件依赖
2. 添加了笔记随机排序功能,每次刷新页面时,笔记的显示顺序都会随机变化
在导出文件夹里打开 PowerShell 命令,粘贴以下命令到 PowerShell 窗口,然后回车执行即可。
# 确保使用正确的编码 $htmlFiles = Get-ChildItem -Filter "*.html" foreach ($file in $htmlFiles) { # 使用 UTF8 编码读取文件 $content = Get-Content $file.FullName -Raw -Encoding UTF8 Write-Host "处理文件: $($file.Name)" # 添加 aria-hidden 属性到特定元素 $newContent = $content -replace '<div class="time">', '<div class="time" aria-hidden="true">' $newContent = $newContent -replace '<div class="top">', '<div class="top" aria-hidden="true">' # 修改以 "- YouTube" 结尾的 p 标签 $newContent = $newContent -replace '<p>([^<]*?- YouTube)</p>', '<p aria-hidden="true">$1</p>' # 替换外部 JS 文件引用为内联 JavaScript $inlineScript = @" <script> var x, i, j, l, ll, selElmnt, a, b, c; x = document.getElementsByClassName("custom-select"); l = x.length; for (i = 0; i < l; i++) { selElmnt = x[i].getElementsByTagName("select")[0]; ll = selElmnt.length; a = document.createElement("DIV"); a.setAttribute("class", "select-selected"); a.innerHTML = selElmnt.options[selElmnt.selectedIndex].innerHTML; x[i].appendChild(a); b = document.createElement("DIV"); b.setAttribute("class", "select-items select-hide"); for (j = 0; j < ll; j++) { c = document.createElement("DIV"); c.innerHTML = selElmnt.options[j].innerHTML; c.addEventListener("click", function(e) { var y, i, k, s, h, sl, yl; s = this.parentNode.parentNode.getElementsByTagName("select")[0]; sl = s.length; h = this.parentNode.previousSibling; for (i = 0; i < sl; i++) { if (s.options[i].innerHTML == this.innerHTML) { s.selectedIndex = i; h.innerHTML = this.innerHTML; y = this.parentNode.getElementsByClassName("same-as-selected"); yl = y.length; for (k = 0; k < yl; k++) { y[k].removeAttribute("class"); } this.setAttribute("class", "same-as-selected"); break; } } h.click(); }); b.appendChild(c); } x[i].appendChild(b); a.addEventListener("click", function(e) { e.stopPropagation(); closeAllSelect(this); this.nextSibling.classList.toggle("select-hide"); this.classList.toggle("select-arrow-active"); }); } function closeAllSelect(elmnt) { var x, y, i, xl, yl, arrNo = []; x = document.getElementsByClassName("select-items"); y = document.getElementsByClassName("select-selected"); xl = x.length; yl = y.length; for (i = 0; i < yl; i++) { if (elmnt == y[i]) { arrNo.push(i); } else { y[i].classList.remove("select-arrow-active"); } } for (i = 0; i < xl; i++) { if (arrNo.indexOf(i)) { x[i].classList.add("select-hide"); } } } document.addEventListener("click", closeAllSelect); </script> "@ # 替换外部脚本引用为内联脚本 $newContent = $newContent -replace '<script src=''./file/js/select.js''></script>', $inlineScript # 添加随机排序脚本 $shuffleScript = @" <script> function shuffleMemos() { const memosContainer = document.querySelector('.memos'); const memos = Array.from(document.querySelectorAll('.memo')); for (let i = memos.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); memosContainer.appendChild(memos[j]); } } window.addEventListener('load', shuffleMemos); </script> "@ $newContent = $newContent -replace '</body>', "$shuffleScript`n</body>" # 使用 UTF8 编码保存文件 $utf8NoBOM = New-Object System.Text.UTF8Encoding $false [System.IO.File]::WriteAllText($file.FullName, $newContent, $utf8NoBOM) Write-Host "已完成修改" }