Last active
March 18, 2025 05:18
-
-
Save Ethkuil/b810312a3a2270d7bea0aa1c99ba12b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getVisibleText(element) { | |
if (element.nodeType === Node.TEXT_NODE) { | |
return element.textContent.trim(); | |
} | |
if (window.getComputedStyle(element).display === 'none') { | |
return ''; | |
} | |
return Array.from(element.childNodes) | |
.map(child => getVisibleText(child)) | |
.join(''); | |
} | |
function words() { | |
// 获取目标表格 | |
const frame = document.querySelector('frame[name="x1"]'); | |
if (!frame) throw new Error('未找到目标 frame'); | |
const table = frame.contentDocument.querySelector('#zabba > p > table'); | |
if (!table) throw new Error('未找到目标表格'); | |
// 收集结果(跳过第一行表头) | |
const results = [...table.querySelectorAll('tr:not([style*="display: none"]')] | |
.slice(1) | |
.map(tr => { | |
const visibleTds = [...tr.querySelectorAll('td:not([style*="display: none"])')]; | |
const rank = getVisibleText(visibleTds[1]); | |
const freq = getVisibleText(visibleTds[2]); | |
const word = getVisibleText(visibleTds[3]); | |
const pos = getVisibleText(visibleTds[4]).toLowerCase(); | |
return `${rank}\t${word}\t${pos}\t${freq}`; | |
}); | |
// 用换行符连接结果 | |
const finalText = results.join('\n'); | |
// 复制到剪贴板 | |
if (finalText.length === 0) throw new Error('未找到有效的数据'); | |
window.prompt("请按Ctrl+C复制文本", finalText); | |
} | |
words(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment