Greasy Fork

Greasy Fork is available in English.

MouseHunt - Gifting Buttons

Adds buttons to easily ignore/accept/return all gifts

当前为 2019-01-12 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         MouseHunt - Gifting Buttons
// @author       Tran Situ (tsitu)
// @namespace    http://greasyfork.icu/en/users/232363-tsitu
// @version      1.1
// @description  Adds buttons to easily ignore/accept/return all gifts
// @match        http://www.mousehuntgame.com/*
// @match        https://www.mousehuntgame.com/*
// ==/UserScript==

(function() {
  const observerTarget = document.querySelector("#overlayPopup");
  if (observerTarget) {
    MutationObserver =
      window.MutationObserver ||
      window.WebKitMutationObserver ||
      window.MozMutationObserver;

    const observer = new MutationObserver(function() {
      // Callback
      const claimableExists = document.querySelector(
        ".giftSelectorView-tabContent.selectClaimableGift"
      );
      if (claimableExists) {
        // Render buttons if 'Claim Free Gifts' dialog is in DOM
        buildUI();
      }
    });

    observer.observe(document.querySelector("#overlayPopup"), {
      childList: true
    });
  }

  function buildUI() {
    const ignoreAllButton = document.createElement("button");
    ignoreAllButton.innerText = "Ignore All";
    ignoreAllButton.addEventListener("click", function() {
      const rows = document.getElementsByClassName(
        "giftSelectorView-friendRow-actionContainer"
      );
      for (let row of rows) {
        const button = row.querySelectorAll(
          ".giftSelectorView-friendRow-action.ignore:not(.selected):not(.disabled)"
        )[0];
        if (button) button.click();
      }
    });

    const unignoreAllButton = document.createElement("button");
    unignoreAllButton.innerText = "↩️";
    unignoreAllButton.addEventListener("click", function() {
      const rows = document.getElementsByClassName(
        "giftSelectorView-friendRow-actionContainer"
      );
      for (let row of rows) {
        const button = row.querySelectorAll(
          ".giftSelectorView-friendRow-action.ignore.selected"
        )[0];
        if (button) button.click();
      }
    });

    const acceptAllButton = document.createElement("button");
    acceptAllButton.innerText = "Accept All";
    acceptAllButton.addEventListener("click", function() {
      const rows = document.getElementsByClassName(
        "giftSelectorView-friendRow-actionContainer"
      );
      for (let i = 0; i < rows.length; i++) {
        // Oldest first
        const row = rows[rows.length - i - 1];
        const button = row.querySelectorAll(
          ".giftSelectorView-friendRow-action.claim:not(.selected):not(.disabled)"
        )[0];
        if (button) button.click();
      }
    });

    const unacceptAllButton = document.createElement("button");
    unacceptAllButton.innerText = "↩️";
    unacceptAllButton.addEventListener("click", function() {
      const rows = document.getElementsByClassName(
        "giftSelectorView-friendRow-actionContainer"
      );
      for (let row of rows) {
        const button = row.querySelectorAll(
          ".giftSelectorView-friendRow-action.claim.selected"
        )[0];
        if (button) button.click();
      }
    });

    const returnAllButton = document.createElement("button");
    returnAllButton.innerText = "Return All";
    returnAllButton.addEventListener("click", function() {
      const rows = document.getElementsByClassName(
        "giftSelectorView-friendRow-actionContainer"
      );
      for (let i = 0; i < rows.length; i++) {
        // Oldest first
        const row = rows[rows.length - i - 1];
        const button = row.querySelectorAll(
          ".giftSelectorView-friendRow-action.return:not(.selected):not(.disabled)"
        )[0];
        if (button) button.click();
      }
    });

    const unreturnAllButton = document.createElement("button");
    unreturnAllButton.innerText = "↩️";
    unreturnAllButton.addEventListener("click", function() {
      const rows = document.getElementsByClassName(
        "giftSelectorView-friendRow-actionContainer"
      );
      for (let row of rows) {
        const button = row.querySelectorAll(
          ".giftSelectorView-friendRow-action.return.selected"
        )[0];
        if (button) button.click();
      }
    });

    const container = document
      .getElementsByClassName(
        "giftSelectorView-tabContent selectClaimableGift"
      )[0]
      .getElementsByClassName("giftSelectorView-actionContainer")[0];

    const buttonSpan = document.createElement("span");
    buttonSpan.style.cssFloat = "left";

    buttonSpan.appendChild(ignoreAllButton);
    buttonSpan.appendChild(unignoreAllButton);
    buttonSpan.appendChild(document.createTextNode("\u00A0\u00A0"));
    buttonSpan.appendChild(acceptAllButton);
    buttonSpan.appendChild(unacceptAllButton);
    buttonSpan.appendChild(document.createTextNode("\u00A0\u00A0"));
    buttonSpan.appendChild(returnAllButton);
    buttonSpan.appendChild(unreturnAllButton);
    container.appendChild(buttonSpan);
  }
})();