js QQ音乐歌词显示在浏览器标题

这是一个JavaScript用户脚本,用于监听页面加载并在找到特定类名为''on'的段落元素时,将其文本内容设置为页面标题。脚本使用了setInterval定时检查并更新页面标题,同时注释中提到了MutationObserver,但未实际使用来监听DOM变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// ==UserScript==
// @name        New script - qq.com
// @namespace   Violentmonkey Scripts
// @match       https://y.qq.com/n/ryqq/player
// @grant       none
// @version     1.0
// @author      -
// @description 2021/10/21 下午3:19:39
// ==/UserScript==

(function() {
    'use strict';
    window.onload = function() {
      
      setInterval(() => {
        if(document.querySelector('p[class="on"]')){
          // console.log(document.querySelector('p[class="on"]').innerText);
          
          var doc = new DOMParser().parseFromString(document.querySelector('p[class="on"]').innerText, "text/html");
          document.title= doc.documentElement.textContent;
          
          // document.title=document.querySelector('p[class="on"]').innerText;
        }
      }, 500);
      
      
      
//       var observer = new MutationObserver(function (mutationRecordList, observer) {//https://stackoverflow.com/a/61511955/1485853
//         for(const mutation of mutationRecordList) {
//           if (mutation.type === 'childList') {
//               console.log('A child node has been added or removed.');
//           }
//           else if (mutation.type === 'attributes') {
//               console.log('The ' + mutation.attributeName + ' attribute was modified.');
//           }
//       }


        
//         if(document.querySelector('p[class="on"]')){
//           console.log(document.querySelector('p[class="on"]').innerText);
//           document.title=document.querySelector('p[class="on"]').innerText;
//         }
        
//     });
      
//       observer.observe(document.querySelector('.song_info__lyric_inner'), {subtree: true, childList: true});
    };


})();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值