扇贝阅读单词自动发音

文章阅读页面,点击单词显示释义的同时自动发音该单词

  1. // ==UserScript==
  2. // @name 扇贝阅读单词自动发音
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-05-17
  5. // @description 文章阅读页面,点击单词显示释义的同时自动发音该单词
  6. // @author CTRN43062
  7. // @match https://web.shanbay.com/reading/web-news/articles/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=shanbay.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. let wordCardObs = null;
  16. const metaInfo = document.querySelector('.meta-info')
  17.  
  18. // Your code here...
  19. const obs = new MutationObserver((mutationsList) => {
  20. for(const m of mutationsList) {
  21. if(m.type === 'childList') {
  22. const { addedNodes, removedNodes } = m
  23.  
  24. if(addedNodes.length === 1 && addedNodes[0].className === 'word-card') {
  25. const wordCard = addedNodes[0]
  26. wordCard.querySelector('.volume').click()
  27.  
  28. wordCardObs = new MutationObserver((mutationList) => {
  29. for(const m of mutationList) {
  30. if(m.type === 'attributes') {
  31. setTimeout(() => metaInfo.querySelector('.volume').click(), 200)
  32. }
  33. }
  34. })
  35.  
  36. wordCardObs.observe(wordCard, { 'attributes': true })
  37. } else if (removedNodes.length === 1 && removedNodes[0].className === 'word-card' && wordCardObs) {
  38. wordCardObs.disconnect()
  39. }
  40. }
  41. }
  42. })
  43.  
  44. obs.observe(metaInfo, { childList: true, subtree:true})
  45. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址