1、单词森林(F12打开控制台使用)
- 获取单词:
// 获取所有 class 为 "word" 的元素
const wordElements = document.querySelectorAll('.word');
// 创建一个数组来存储 innerText
const innerTexts = [];
// 遍历每个元素并获取其 innerText
wordElements.forEach(element => {
innerTexts.push(element.innerText);
});
// 将结果复制到剪贴板
const result = innerTexts.join('\n'); // 用换行符连接
console.log(result)
- 调用goldendict查单词(点击单词那一行跳转):
// 获取 tbody 元素
const tbody = document.querySelector('tbody');
// 为 tbody 添加点击事件监听器
tbody.addEventListener('click', (event) => {
// 检查点击的目标是否是 tr 或其子元素
const tr = event.target.closest('tr');
if (tr) {
// 获取 tr 中 class 为 "word" 的 strong 元素
const wordElement = tr.querySelector('strong.word');
if (wordElement) {
// 打印单词
console.log(wordElement.innerText);
window.location.href = 'goldendict://' + wordElement.innerText
}
}
});
2、欧路背单词
- 调用goldendict查单词(油猴脚本):
// ==UserScript==
// @name 欧路背单词联动Goldendict
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 使用欧陆背单词网页版时,点击单词即可跳转
// @author Your name
// @match https://dict.eudic.net/areas/recite/en/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
// 等待整个页面加载完成
window.onload = function () {
//GM_addStyle(` .card-question{ font-size: 50px !important; color:#00ff5a; }`);
// 创建 <style> 标签
const style = document.createElement('style');
document.head.appendChild(style);
// 获取样式表对象
const sheet = style.sheet;
// 注入 CSS 规则
sheet.insertRule(' .card-question{ font-size: 50px !important; color:#00ff5a; }', 0);
// 跳转词典
function dict(word) {
window.location.href = 'goldendict://' + word
}
document.body.addEventListener('click', function (event) {
console.log('target', event.target)
// 检查点击的目标元素是否匹配 .card-question.ng-star-inserted
const targetElement = event.target.closest('.card-question.ng-star-inserted');
if (targetElement) {
// 如果匹配,触发自定义事件
console.log('目标元素被点击:', targetElement.innerText);
dict(targetElement.innerText)
}
});
}
})();