9dm每日计算自动填入

9dm每日计算验证自动填入;旧的收藏页面域名com重定向到新的net;搜索计算自动验证

目前為 2023-02-06 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         9dm每日计算自动填入
// @namespace    http://tampermonkey.net/
// @version      2.2.0
// @description  9dm每日计算验证自动填入;旧的收藏页面域名com重定向到新的net;搜索计算自动验证
// @author       liuyubing
// @match        *://www.9dmdamaomod.com/*
// @match        *://www.9dmdamaomod.net/*
// @match        *://www.9damaogame.net/*
// @grant        none
// ==/UserScript==

(function () {
  "use strict";
  const { search, protocol, pathname } = window.location;
  if (/\/gonggao\//.test(pathname)) {
    // 如果pathname为/gonggao/则为com到net重定向地址
    window.open(protocol + "//www.9dmdamaomod.net" + search ? "/forum.php" + search : "", "_self");
  }

  // 每日计算自动填入
  setTimeout(() => {
    if (document.getElementsByName("answer").length) {
      document.getElementsByName("answer")[0].value = document
        .querySelector("b")
        .innerText.replace(/[^0-9]/gi, ",")
        .split(",")
        .filter((i) => Number(i))
        .reduce((a, b) => Number(a) + Number(b));
      document.getElementsByName("secqsubmit")[0].click();
    }
  }, 100);

  // 搜索计算自动验证
  setTimeout(() => {
    const nodeNum1 = document.getElementById("num1");
    if (!nodeNum1) return;
    const nodeNumAll = nodeNum1.parentNode.querySelectorAll("span");
    let sum = 0;
    nodeNumAll.forEach((item) => {
      if (item.id.includes("num")) {
        sum += +item.innerText ? +item.innerText : 0;
      }
    });
    const nodeInput = document.querySelector(".v-code input");
    nodeInput.value = sum;

    var event = document.createEvent("Event");
    // TODO: 后续此方法废弃后需要修改
    event.initEvent("keydown", true, false);
    event = Object.assign(event, {
      ctrlKey: false,
      metaKey: false,
      altKey: false,
      which: 13,
      keyCode: 13,
      key: "Enter",
      code: "Enter",
    });
    nodeInput.focus();
    nodeInput.dispatchEvent(event);
  }, 100);
})();