派蒙答题器

派蒙的十万个为什么,自动搜答案

目前為 2021-11-21 提交的版本,檢視 最新版本

// ==UserScript==
// @name         派蒙答题器
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  派蒙的十万个为什么,自动搜答案
// @author       You
// @match        https://webstatic.mihoyo.com/*
// @grant        GM_xmlhttpRequest
// @license MIT
// ==/UserScript==

(function () {
  'use strict';
  GM_xmlhttpRequest({
    method: 'GET',
    url: 'https://wiki.biligame.com/ys/%E3%80%8C%E6%B4%BE%E8%92%99%E7%9A%84%E5%8D%81%E4%B8%87%E4%B8%AA%E4%B8%BA%E4%BB%80%E4%B9%88%E3%80%8D%E9%A2%98%E5%BA%93',
    onload(res) {
      var parser = new DOMParser();
      var dom = parser.parseFromString(res.response, "text/html");

      const check = () => {
        var quesElem = document.querySelector('[class|="components-game-assets-qa-info___text"]');
        var ques = quesElem.textContent
        dom.querySelectorAll('.wikitable tbody tr').forEach(elem => {
          if (elem.children[0].textContent.indexOf(ques) > -1) {
            var ans = elem.children[1].textContent
            quesElem.textContent += `  - ${ans}`
          }
        })
      }
      // 选择需要观察变动的节点
      const targetNode = document.querySelector('[class|="components-game-assets-qa___qa-page"]');

      // 观察器的配置(需要观察什么变动)
      const config = {
        attributes: true, // 开启监听属性
        childList: true, // 开启监听子节点
        subtree: true // 开启监听子节点下面的所有节点
      };

      // 当观察到变动时执行的回调函数
      const callback = function (mutationsList, observer) {
        // Use traditional 'for loops' for IE 11
        for (let mutation of mutationsList) {
          if (mutation.type === 'childList') {
            console.log('A child node has been added or removed.');
            check()
          }
          else if (mutation.type === 'attributes') {
            console.log('The ' + mutation.attributeName + ' attribute was modified.');
          }

        }
      };

      // 创建一个观察器实例并传入回调函数
      const observer = new MutationObserver(callback);

      // 以上述配置开始观察目标节点
      observer.observe(targetNode, config);

      check()
      // 之后,可停止观察
      //observer.disconnect();

    }
  })
})();

QingJ © 2025

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