// ==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 // @grant GM_addStyle // ==/UserScript== //调整顶部进度条、页面左右空白 GM_addStyle('.card-container.full{ margin-left: 20px !important; margin-right: 20px !important;}'); //按钮宽度固定、居中 GM_addStyle('.options-container{ width: 300px;margin-left: auto !important; margin-right: auto !important;}'); (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 () { // 第一次触发 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 } } } }) }); } } })();