// ==UserScript== // @name MouseHunt - Gifting Buttons // @author Tran Situ (tsitu) // @namespace https://greasyfork.org/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/* // @downloadURL none // ==/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); } })();