MouseHunt - Hide max owned items

Hides max owned items in shop

当前为 2021-03-17 提交的版本,查看 最新版本

// ==UserScript==
// @name         MouseHunt - Hide max owned items
// @author       Hazado
// @namespace    https://greasyfork.org/en/scripts/423438
// @version      1.2
// @description  Hides max owned items in shop
// @include      https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
// @match        http://www.mousehuntgame.com/*
// @match        https://www.mousehuntgame.com/*
// ==/UserScript==

if (!localStorage.getItem("maxOwnedItems")) {
  localStorage.setItem("maxOwnedItems", "Y");
}
if (!localStorage.getItem('hideCollector')) {
  localStorage.setItem('hideCollector', "0");
}

$(document).ready(function () {
  var observerMaxItem = new MutationObserver(callback);
  var observerOptionsMaxItem = {
    childList: true,
    attributes: true,
    subtree: true
  };
  if ($('.mousehuntHud-page-tabHeader.cheese_shoppe').get(0)) {
    hideMaxOwned();
    minimize();
    observerMaxItem.observe($('.mousehuntHud-page-tabContentContainer').get(0), observerOptionsMaxItem);
  } else if ($('.mousehuntHud-page-tabHeader.trapsmith').get(0)) {
    hideMaxOwned();
    minimize();
    observerMaxItem.observe($('.mousehuntHud-page-tabContentContainer').get(0), observerOptionsMaxItem);
  } else if ($('.mousehuntHud-page-tabHeader.charm_shoppe').get(0)) {
    hideMaxOwned();
    minimize();
    observerMaxItem.observe($('.mousehuntHud-page-tabContentContainer').get(0), observerOptionsMaxItem);
  } else if ($('.mousehuntHud-page-tabHeader.general_store').get(0)) {
    hideMaxOwned();
    minimize();
    observerMaxItem.observe($('.mousehuntHud-page-tabContentContainer').get(0), observerOptionsMaxItem);
  } else if ($('.mousehuntHud-page-tabHeader.cartographer').get(0)) {
    hideMaxOwned();
    minimize();
    observerMaxItem.observe($('.mousehuntHud-page-tabContentContainer').get(0), observerOptionsMaxItem);
  } else if ($('.mousehuntHud-page-tabHeader.kings_cart').get(0)) {
    hideMaxOwned();
    minimize();
    observerMaxItem.observe($('.mousehuntHud-page-tabContentContainer').get(0), observerOptionsMaxItem);
  } else if ($('.mousehuntHud-page-tabContent.game_settings').get(0)) {
    addSetting();
    observerMaxItem.observe($('.mousehuntHud-page-tabContentContainer').get(0), observerOptionsMaxItem);
  } else if ($('.mousehuntHud-page-tabContentContainer').get(0)) {
    //not on profile at all. probably at camp.
    observerMaxItem.observe($('.mousehuntHud-page-tabContentContainer').get(0), observerOptionsMaxItem);
  } else {
    return false
  }
});

function callback(mutationList, observer) {
  mutationList.forEach(mutation => {
    if (mutation.type == 'attributes') {
      let $nodes = $(mutation.target);
      if ($nodes.hasClass('mousehuntHud-page-tabHeader cheese_shoppe')) {
        hideMaxOwned();
      } else if ($nodes.hasClass('mousehuntHud-page-tabContent cheese_shoppe')) {
        hideMaxOwned();
      } else if ($nodes.hasClass('mousehuntHud-page-tabHeader trapsmith')) {
        hideMaxOwned();
      } else if ($nodes.hasClass('mousehuntHud-page-tabContent trapsmith')) {
        hideMaxOwned();
      } else if ($nodes.hasClass('mousehuntHud-page-tabHeader charm_shoppe')) {
        hideMaxOwned();
      } else if ($nodes.hasClass('mousehuntHud-page-tabContent charm_shoppe')) {
        hideMaxOwned();
      } else if ($nodes.hasClass('mousehuntHud-page-tabHeader general_store')) {
        hideMaxOwned();
      } else if ($nodes.hasClass('mousehuntHud-page-tabContent general_store')) {
        hideMaxOwned();
      } else if ($nodes.hasClass('mousehuntHud-page-tabHeader cartographer')) {
        hideMaxOwned();
      } else if ($nodes.hasClass('mousehuntHud-page-tabContent cartographer')) {
        hideMaxOwned();
      } else if ($nodes.hasClass('mousehuntHud-page-tabHeader kings_cart')) {
        hideMaxOwned();
      } else if ($nodes.hasClass('mousehuntHud-page-tabContent kings_cart')) {
        hideMaxOwned();
      } else if ($nodes.hasClass('mousehuntHud-page-tabContent game_settings')) {
        if (!$('div:contains("Hide Max Owned Items in Shop")').get(0)) {
          addSetting()
        }
      }
    }
  })
};

$(document).ajaxSuccess(function () {
  if (window.location.href.includes("shop.php")) {
    minimize();
  } else if (window.location.href.includes("shops.php")) {
    minimize();
  }
});

function hideMaxOwned() {
  hideCollector();
  if (localStorage.getItem("maxOwnedItems") == "Y") {
    $('[class*="own_max"]').css('visibility', "collapse");
    $('[class*="own_max"]').css('margin-bottom', "-2px");
  } else if (localStorage.getItem("maxOwnedItems") == "NAME") {
    $('[class*="own_max"]').children().children().filter('.itemPurchaseView-image-container').children().filter('.itemPurchaseView-image').css('display', "none");
    $('[class*="own_max"]').children().children().filter('.itemPurchaseView-image-container').children().filter('.itemViewStatBlock').css('display', "none");
    $('[class*="own_max"]').children().children().filter('.itemPurchaseView-image-container').children().filter('.itemPurchaseView-image-trapPreview-link').css('display', "none");
    $('[class*="own_max"]').children().children().filter('.itemPurchaseView-action-container').css('display', "none");
    $('[class*="own_max"]').children().children().filter('.itemPurchaseView-content-container').children().filter('.itemPurchaseView-content-details').css('display', "none");
    $('[class*="own_max"]').children().children().filter('.itemPurchaseView-content-container').children().filter('.itemPurchaseView-content-description').css('display', "none");
  }
}

function addSetting() {
  if (localStorage.getItem("maxOwnedItems") == "Y") {
    $('.settingRowTable').eq(2).append('<div class="settingRow"><div class="settingRow-label"><div class="name">Hide Max Owned Items in Shop</div><div class="defaultSettingText">Hidden</div><div class="description">Setting provided by "MouseHunt - Hide max owned items" script</br>It hides all items you own the max of when enabled.</div></div><div class="settingRow-action"><div class="settingRow-action-inputContainer"><div class="dropdownContainer"><select name="maxOwnedItems" onchange="localStorage.setItem(\'maxOwnedItems\',$(this)[0].value)" style="width: 184px;"><option value="Y" selected="">Hidden</option><option value="NAME">Minimized</option><option value="N">None</option></select></div></div></div></div></div>')
  } else if (localStorage.getItem("maxOwnedItems") == "NAME") {
    $('.settingRowTable').eq(2).append('<div class="settingRow"><div class="settingRow-label"><div class="name">Hide Max Owned Items in Shop</div><div class="defaultSettingText">Hidden</div><div class="description">Setting provided by "MouseHunt - Hide max owned items" script</br>It hides all items you own the max of when enabled.</div></div><div class="settingRow-action"><div class="settingRow-action-inputContainer"><div class="dropdownContainer"><select name="maxOwnedItems" onchange="localStorage.setItem(\'maxOwnedItems\',$(this)[0].value)" style="width: 184px;"><option value="Y">Hidden</option><option value="NAME" selected="">Minimized</option><option value="N">None</option></select></div></div></div></div></div>')
  } else {
    $('.settingRowTable').eq(2).append('<div class="settingRow"><div class="settingRow-label"><div class="name">Hide Max Owned Items in Shop</div><div class="defaultSettingText">Hidden</div><div class="description">Setting provided by "MouseHunt - Hide max owned items" script</br>It hides all items you own the max of when enabled.</div></div><div class="settingRow-action"><div class="settingRow-action-inputContainer"><div class="dropdownContainer"><select name="maxOwnedItems" onchange="localStorage.setItem(\'maxOwnedItems\',$(this)[0].value)" style="width: 184px;"><option value="Y">Hidden</option><option value="NAME">Minimized</option><option value="N" selected="">None</option></select></div></div></div></div></div>')
  }
  $('.settingRowTable').eq(2).append('<div class="settingRow"><div class="settingRow-label"><div class="name">Hide items equal or more than X in Shop</div><div class="defaultSettingText">0</div><div class="description">Setting provided by "MouseHunt - Hide max owned items" script</br>It hides all items you own X or more of when enabled.</div></div><div class="settingRow-action"><div class="settingRow-action-inputContainer"><div class="inputBoxContainer"><div class="inputNumber">Number</div><input class="inputField number" type="text" maxlength="25" value="" placeholder="0" onkeyup="localStorage.setItem(\'hideCollector\', $(this)[0].value)" style="width: 176px;"></div></div></div></div></div>')
  $('.inputField.number')[0].value = localStorage.getItem('hideCollector');
}

function minimize() {
  $('.itemPurchaseView-container').children().children().filter('.itemPurchaseView-content-container').children().filter('.itemPurchaseView-content-name').on("click", function () {
    if ($(this).parents().eq(2).children().children().filter('.itemPurchaseView-image-container').children().filter('.itemPurchaseView-image').css('display') == "none") {
      $(this).parents().eq(2).children().children().filter('.itemPurchaseView-image-container').children().filter('.itemPurchaseView-image').css('display', "");
      $(this).parents().eq(2).children().children().filter('.itemPurchaseView-image-container').children().filter('.itemViewStatBlock').css('display', "");
      $(this).parents().eq(2).children().children().filter('.itemPurchaseView-image-container').children().filter('.itemPurchaseView-image-trapPreview-link').css('display', "");
      $(this).parents().eq(2).children().children().filter('.itemPurchaseView-action-container').css('display', "");
      $(this).parents().eq(2).children().children().filter('.itemPurchaseView-content-container').children().filter('.itemPurchaseView-content-details').css('display', "");
      $(this).parents().eq(2).children().children().filter('.itemPurchaseView-content-container').children().filter('.itemPurchaseView-content-description').css('display', "");
    } else {
      $(this).parents().eq(2).children().children().filter('.itemPurchaseView-image-container').children().filter('.itemPurchaseView-image').css('display', "none");
      $(this).parents().eq(2).children().children().filter('.itemPurchaseView-image-container').children().filter('.itemViewStatBlock').css('display', "none");
      $(this).parents().eq(2).children().children().filter('.itemPurchaseView-image-container').children().filter('.itemPurchaseView-image-trapPreview-link').css('display', "none");
      $(this).parents().eq(2).children().children().filter('.itemPurchaseView-action-container').css('display', "none");
      $(this).parents().eq(2).children().children().filter('.itemPurchaseView-content-container').children().filter('.itemPurchaseView-content-details').css('display', "none");
      $(this).parents().eq(2).children().children().filter('.itemPurchaseView-content-container').children().filter('.itemPurchaseView-content-description').css('display', "none");
    }
  });
}

function hideCollector() {
  $('.itemPurchaseView-container').each(function () {
    if (parseInt($(this).attr('data-num-owned')) >= parseInt(localStorage.getItem("hideCollector")) && parseInt(localStorage.getItem("hideCollector")) > 0) {
      $(this).children().children().filter('.itemPurchaseView-image-container').children().filter('.itemPurchaseView-image').css('display', "none");
      $(this).children().children().filter('.itemPurchaseView-image-container').children().filter('.itemViewStatBlock').css('display', "none");
      $(this).children().children().filter('.itemPurchaseView-image-container').children().filter('.itemPurchaseView-image-trapPreview-link').css('display', "none");
      $(this).children().children().filter('.itemPurchaseView-action-container').css('display', "none");
      $(this).children().children().filter('.itemPurchaseView-content-container').children().filter('.itemPurchaseView-content-details').css('display', "none");
      $(this).children().children().filter('.itemPurchaseView-content-container').children().filter('.itemPurchaseView-content-description').css('display', "none");
    }
  });
}