MouseHunt - Shop's Helper

Adds useful features to the shop

目前為 2021-03-19 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         MouseHunt - Shop's Helper
// @author       Hazado
// @namespace    https://greasyfork.org/en/scripts/423438
// @version      1.3
// @description  Adds useful features to the 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==

/*ToDO List
Persistent Minimize with reset button
 */

if (!localStorage.getItem("maxOwnedItems")) {
  localStorage.setItem("maxOwnedItems", "Y");
}
if (!localStorage.getItem("hideDonation")) {
  localStorage.setItem("hideDonation", "N");
}

$(document).ready(function () {
  var observerMaxItem = new MutationObserver(callback);
  var observerOptionsMaxItem = {
    childList: true,
    attributes: true,
    subtree: true
  };
  if ($('.mousehuntHud-page-tabHeader.cheese_shoppe').get(0) || $('.mousehuntHud-page-tabHeader.trapsmith').get(0) || $('.mousehuntHud-page-tabHeader.charm_shoppe').get(0) || $('.mousehuntHud-page-tabHeader.general_store').get(0) || $('.mousehuntHud-page-tabHeader.cartographer').get(0) || $('.mousehuntHud-page-tabHeader.kings_cart').get(0)) {
    AddShopPageFeatures();
    hideMaxOwned();
    hideDonation();
    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('cheese_shoppe') || $nodes.hasClass('trapsmith') || $nodes.hasClass('charm_shoppe') || $nodes.hasClass('general_store') || $nodes.hasClass('cartographer') || $nodes.hasClass('kings_cart')) {
        AddShopPageFeatures();
        hideMaxOwned();
        hideDonation();
        minimize();
      } else if ($nodes.hasClass('mousehuntHud-page-tabContent game_settings')) {
        if (!$('div:contains("Hide Max Owned Items in Shop")').get(0)) {
          addSetting()
        }
      }
    }
  })
};

function addSetting() {
  //Add Shop's Helper Header
  $('.mousehuntHud-page-tabContent.game_settings').append('<div class="gameSettingTitle">Shop\'s Helper</div><div class="separator"></div><div class="description">Settings provided by "MouseHunt - Shop\'s Helper" script</div><div class="settingRowTable"></div>')

  //Hide Max owned items
  if (localStorage.getItem("maxOwnedItems") == "Y") {
    $('.settingRowTable').eq(3).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">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(3).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">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(3).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">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>')
  }

  //Hide Donation Items
  if (localStorage.getItem("hideDonation") == "Y") {
    $('.settingRowTable').eq(3).append('<div class="settingRow"><div class="settingRow-label"><div class="name">Hide Donation Items in Shop</div><div class="defaultSettingText">Disabled</div><div class="description">It hides all donation items when enabled.</div></div><div class="settingRow-action"><div class="SettingRow-action-inputContainer"><div class="mousehuntSettingSlider active" onclick=\'if (localStorage.getItem("hideDonation") =="Y"){localStorage.setItem("hideDonation", "N");}else{localStorage.setItem("hideDonation", "Y");};app.pages.PreferencesPage.toggleGameSetting(this);\'></div></div></div></div>')
  } else {
    $('.settingRowTable').eq(3).append('<div class="settingRow"><div class="settingRow-label"><div class="name">Hide Donation Items in Shop</div><div class="defaultSettingText">Disabled</div><div class="description">It hides all donation items when enabled.</div></div><div class="settingRow-action"><div class="SettingRow-action-inputContainer"><div class="mousehuntSettingSlider" onclick=\'if (localStorage.getItem("hideDonation") =="Y"){localStorage.setItem("hideDonation", "N");}else{localStorage.setItem("hideDonation", "Y");};app.pages.PreferencesPage.toggleGameSetting(this);\'></div></div></div></div>')
  }
}

//Global Minimize
function minimize() {
  if (jQuery._data(document.getElementsByClassName('itemPurchaseView-content-name')[0], 'events') == undefined) {
    $('.itemPurchaseView-container').children().children().filter('.itemPurchaseView-content-container').children().filter('.itemPurchaseView-content-name').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 hideMaxOwned() {
  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 hideDonation() {
  if (localStorage.getItem("hideDonation") == "Y") {
    $('[class*="donation"]').css('visibility', "collapse");
    $('[class*="donation"]').css('margin-bottom', "-2px");
    $('.itemPurchaseView-container.super_brie_cheese.view').eq(1).css('visibility', "collapse");
    $('.itemPurchaseView-container.super_brie_cheese.view').eq(1).css('margin-bottom', "-2px");
  }
}

//Search function for each page
function filter(search) {
  $('.shopsPage-header-container').parents().slice(0, 6).filter('.active').children().children().filter('.itemPurchaseView-container').children().children().children().filter('.itemPurchaseView-content-name').each(function () {
    if ($(this).text().toLowerCase().includes(search.toLowerCase())) {
      if (localStorage.getItem("maxOwnedItems") == "Y" && $(this).parents().eq(2).hasClass('own_max')) {}
      else {
        $(this).parents().eq(2).css('visibility', "");
        $(this).parents().eq(2).css('margin-bottom', "");
      }
    } else {
      $(this).parents().eq(2).css('visibility', "collapse");
      $(this).parents().eq(2).css('margin-bottom', "-2px");
    }
  })
}

//Quantity filter for each page
function quantity(search) {
  $('.shopsPage-header-container').parents().slice(0, 6).filter('.active').children().children().filter('.itemPurchaseView-container').each(function () {
    if (parseInt($(this).attr('data-num-owned')) >= parseInt(search) && parseInt(search) > 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");
    } else {
      $(this).children().children().filter('.itemPurchaseView-image-container').children().filter('.itemPurchaseView-image').css('display', "");
      $(this).children().children().filter('.itemPurchaseView-image-container').children().filter('.itemViewStatBlock').css('display', "");
      $(this).children().children().filter('.itemPurchaseView-image-container').children().filter('.itemPurchaseView-image-trapPreview-link').css('display', "");
      $(this).children().children().filter('.itemPurchaseView-action-container').css('display', "");
      $(this).children().children().filter('.itemPurchaseView-content-container').children().filter('.itemPurchaseView-content-details').css('display', "");
      $(this).children().children().filter('.itemPurchaseView-content-container').children().filter('.itemPurchaseView-content-description').css('display', "");
    }
  })
}

function AddShopPageFeatures() {
  //Adds Search Box to each page
  if ($('.shopsPage-header-container').parents().slice(0, 6).children().filter('.mousehuntHud-page-subTabHeader-container').has('input').length == 0) {
    $('.shopsPage-header-container').parents().slice(0, 6).children().filter('.mousehuntHud-page-subTabHeader-container').append('<input data-filter="search" type="text" value="" maxlength="20" placeholder="Search" style="float: right;width: 100px">');
    $('.shopsPage-header-container').parents().slice(1, 4).children().filter('.shopsPage-header-container').after('<div class="mousehuntHud-page-subTabHeader-container"  style="margin-bottom: 44px;"><input data-filter="search" type="text" value="" maxlength="20" placeholder="Search" style="float: right;width: 100px"></div>');
    $('.shopsPage-header-container').parents().slice(5).children().filter('.shopsPage-header-container').after('<div class="mousehuntHud-page-subTabHeader-container"  style="margin-bottom: 44px;"><input data-filter="search" type="text" value="" maxlength="20" placeholder="Search" style="float: right;width: 100px"></div>');
    $('.shopsPage-header-container').parents().slice(0, 6).children().filter('.mousehuntHud-page-subTabHeader-container').children().filter('input').filter("[placeholder='Search']").on("input", function () {
      filter($(this).val());
    });

    //Adds Quantity filter to each page
    $('.shopsPage-header-container').parents().slice(0, 6).children().filter('.mousehuntHud-page-subTabHeader-container').children().filter('input').before('<input data-filter="search" type="text" value="" maxlength="5" placeholder="Quantity" title="Will minimize any item of equal or greater quantity" style="float: right;width: 50px">');
    $('.shopsPage-header-container').parents().slice(0, 6).children().filter('.mousehuntHud-page-subTabHeader-container').children().filter('input').filter("[placeholder='Quantity']").on("input", function () {
      localStorage.setItem('hide_quantity_' + $('.shopsPage-header-container').parents().slice(0, 6).filter('.active').attr('data-tab'), $(this).val());
      quantity($(this).val());
    });

    //Adds Buy Max link
    $('.itemPurchaseView-action-form.clear-block').append('<a href="#" class="itemPurchaseView-action-form-button max" onclick="$(this).parents().filter(\'.itemPurchaseView-action-state.view\').children().filter(\'.itemPurchaseView-action-form.clear-block\').children().filter(\'.itemPurchaseView-action-quantity\').children().filter(\'input\').val(parseInt($(this).parents().filter(\'.itemPurchaseView-action-state.view\').children().filter(\'.itemPurchaseView-action-purchaseHelper\').children().filter(\'.itemPurchaseView-action-purchaseHelper-maxPurchases-container\').children().filter(\'.itemPurchaseView-action-maxPurchases\').text().replaceAll(\',\', \'\')) || 0); app.pages.ShopsPage.confirmPurchase(this); return false;" style="height: 0px;">Buy Max</a>');
  }

  //Sets Quantity filter to saved variable
  $('.shopsPage-header-container').parents().slice(0, 6).children().filter('.mousehuntHud-page-subTabHeader-container').children().filter('input').filter("[placeholder='Quantity']").val(parseInt(localStorage.getItem('hide_quantity_' + $('.shopsPage-header-container').parents().slice(0, 6).filter('.active').attr('data-tab'))) || 0);
  //Performs First Filter
  quantity(parseInt(localStorage.getItem('hide_quantity_' + $('.shopsPage-header-container').parents().slice(0, 6).filter('.active').attr('data-tab'))) || 0);

  //Hides/Shows Buy Max Button
  $('.itemPurchaseView-action-form-button.max').parents().filter('.itemPurchaseView-container').each(function () {
    if ($(this).hasClass('cannot_buy')) {
      $(this).children().children().filter('.itemPurchaseView-action-container').children().filter('.itemPurchaseView-action-state.view').children().filter('.itemPurchaseView-action-form.clear-block').children().filter('.itemPurchaseView-action-form-button.max').css('display', "none")
    } else {
      $(this).children().children().filter('.itemPurchaseView-action-container').children().filter('.itemPurchaseView-action-state.view').children().filter('.itemPurchaseView-action-form.clear-block').children().filter('.itemPurchaseView-action-form-button.max').css('display', "")
    }
  });
}