// ==UserScript== // @name word-dict-link // @namespace http://tampermonkey.net/ // @version 0.1 // @description 使用欧陆背单词网页版时,自动复制当前单词到剪贴板,查询释义,需要打开软件(欧路词典、goldendict、Mdict) // @author @胡桃的精通沙 // @match https://dict.eudic.net/areas/recite/en/* // @icon https://img-static.mihoyo.com/communityweb/upload/3b8cf75f15864abfc9eeb1b9316d9224.png // @grant GM_setClipboard // ==/UserScript== (function () { // 跳转词典 function dict(word) { window.location.href = 'goldendict://' + word } document.onreadystatechange = function () { if (document.readyState == "complete") {//complete加载完成 console.log('查询脚本启动'); // 页面加载后 function checkElementExistence(selector, callback) { // 循环检测元素是否存在 if (document.querySelector(selector) !== null) { callback(); } else { setTimeout(function () { checkElementExistence('.card-question', callback); }, 500); } } // 检测到元素存在后执行 checkElementExistence('.card-question', function () { console.log('元素存在,第一次在执行'); // 第一次触发 var targetElement = document.querySelector('.card-question') targetElement.style.fontSize = '40px'; dict(targetElement.innerText) document.addEventListener('click', (e) => { e.preventDefault() // 直接点击触发 if (e.target.className == 'card-question ng-star-inserted') { console.log('点击了', e.target.innerText); var word = e.target.innerText; GM_setClipboard(word) dict(word) } // 选项触发 else { // 获取点击事件的冒泡路径上的所有元素 const allElements = e.composedPath(); // 遍历所有元素 for (const element of allElements) { if (element.classList.contains('options-container')) { setTimeout(() => { var targetElement = document.querySelector('.card-question') dict(targetElement.innerText) }, 600); break } } } }) }); } } })();