Skip to content

Commit

Permalink
Adding favourites safety to the mythic equips upgrade page, adding my…
Browse files Browse the repository at this point in the history
…thic rarity to the equips filter
  • Loading branch information
Numbers committed Nov 21, 2022
1 parent 7141879 commit c3b97bc
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
1.28.7: Adding favourites safety to the mythic equips upgrade page, adding mythic rarity to the equips filter
1.28.6: Pre-emptively adding back the deeplink to the booster equip page from the resource bars
1.28.5: Some quick fixes following the 16/11 game update
1.28.4: Fixing censorship of koban images on HH.com
Expand Down
8 changes: 4 additions & 4 deletions dist/hh-plus-plus.dev.user.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/hh-plus-plus.meta.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name Hentai Heroes++ BDSM version
// @description Adding things here and there in the Hentai Heroes game. Also supports HHCore-based games such as GH and CxH.
// @version 1.28.6
// @version 1.28.7
// @match https://*.hentaiheroes.com/*
// @match https://nutaku.haremheroes.com/*
// @match https://*.gayharem.com/*
Expand Down
4 changes: 2 additions & 2 deletions dist/hh-plus-plus.user.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hh-plus-plus",
"version": "1.28.6",
"version": "1.28.7",
"description": "Adding things here and there in the Hentai Heroes game. Also supports HHCore-based games such as GH and CxH.",
"private": "true",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion src/modules/MarketEquipsFilterModule/EquipHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ EquipHelpers.filterOptions = new (class {
{value: 'common', bgColor: '#8d8e9f'},
{value: 'rare', bgColor: '#23b56b'},
{value: 'epic', bgColor: '#ffb244'},
{value: 'legendary', bgColor: '#9150bf', bgImage: `url(${Helpers.getCDNHost()}/legendary.png)`}
{value: 'legendary', bgColor: '#9150bf', bgImage: `url(${Helpers.getCDNHost()}/legendary.png)`},
{value: 'mythic', bgColor: 'transparent', bgImage: 'radial-gradient(closest-side at 50% 50%, rgb(245, 168, 102) 0px, rgb(236, 0, 57) 51%, rgb(158, 14, 39) 100%)'}
]}
get stats () {return [
{value: 'rainbow', icon: 'pictures/misc/items_icons/16.svg'},
Expand Down
45 changes: 34 additions & 11 deletions src/modules/MarketEquipsFilterModule/EquipManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ const SLOT_CONTAINER_WIDTH = 106 // 90px width + 1rem right margin

class EquipManager {

constructor($container, name) {
constructor($container, name, skipFilter) {
this.$container = $container
this.$content = $container.find('.player-inventory-content')
this.managedEquips = {}
this.allEquipIdsInOrder = []
this.visibleEquipIds = []
this.favouriteKeys = {}
this.elementCache = {}
this.keysForIds = {}
this.name = name
this.skipFilter = skipFilter

this.activeFilter = {
subtype: EquipHelpers.filterDefault,
Expand All @@ -25,8 +25,14 @@ class EquipManager {
}
}

get $content () {
return this.$container.find('.player-inventory-content, .items-container')
}

init () {
const {player_inventory: {armor: initialArmor}} = window
const {materials_items, player_inventory} = window

const initialArmor = materials_items || player_inventory.armor

initialArmor.forEach(armor => {
const equipKey = EquipHelpers.makeEquipKey(armor)
Expand Down Expand Up @@ -70,7 +76,10 @@ class EquipManager {
}

this.setupHooks()
this.attachFilterButtonAndPanel()

if (!this.skipFilter) {
this.attachFilterButtonAndPanel()
}
}

setupHooks () {
Expand Down Expand Up @@ -99,7 +108,7 @@ class EquipManager {

this.reconsileAfterNextDOMChange()
})
Helpers.onAjaxResponse(/action=market_get_armor/, (response) => {
const collectFromLazyLoad = (response) => {
const {items} = response

if (!items || !items.length) {return}
Expand All @@ -119,7 +128,9 @@ class EquipManager {
})

this.reconsileAfterNextDOMChange()
})
}
Helpers.onAjaxResponse(/action=market_get_armor/, collectFromLazyLoad)
Helpers.onAjaxResponse(/action=mythic_armor_load_material_items/, collectFromLazyLoad)

Helpers.onAjaxResponse(/action=market_sell/, (response, opt) => {
const searchParams = new URLSearchParams(opt.data)
Expand Down Expand Up @@ -205,6 +216,18 @@ class EquipManager {
this.reconcileElements()
this.checkSelection()
})

if (this.name === 'upgrade') {
const $upgradeButton = this.$container.find('button#level-up')
new MutationObserver(() => {
const disabled = $upgradeButton.prop('disabled')
if (disabled) {return}

if (this.$container.find('.selected [data-is-favourite=true]').length) {
$upgradeButton.prop('disabled', true)
}
}).observe($upgradeButton[0], {attributes: true, attributeFilter:['disabled']})
}
}

reconsileAfterNextDOMChange (extraCallback) {
Expand Down Expand Up @@ -309,8 +332,8 @@ class EquipManager {
}

reconcileElements () {
const $content = this.$container.find('.player-inventory-content')
$content.find('.slot:not(.empty)').each((i, slot) => {
// const $content = this.$container.find('.player-inventory-content')
this.$content.find('.slot:not(.empty)').each((i, slot) => {
const $slot = $(slot)

const {key} = this.assertEquipAnnotatedWithKey($slot)
Expand All @@ -334,12 +357,12 @@ class EquipManager {
return
}

$content.append($slot)
this.$content.append($slot)
})

$content.append($content.find('.slot-container.empty'))
this.$content.append(this.$content.find('.slot-container.empty'))
this.padWithEmptySlots()
$content.getNiceScroll().resize()
this.$content.getNiceScroll().resize()

this.annotateEquipsWithFavourites()
this.checkSelection()
Expand Down
41 changes: 25 additions & 16 deletions src/modules/MarketEquipsFilterModule/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MarketEquipsFilterModule extends CoreModule {
}

shouldRun () {
return Helpers.isCurrentPage('shop')
return Helpers.isCurrentPage('shop') || Helpers.isCurrentPage('mythic-equipment-upgrade')
}

run () {
Expand All @@ -34,24 +34,33 @@ class MarketEquipsFilterModule extends CoreModule {
Helpers.defer(() => {
this.injectCSSVars()

const containers = [
{
$container: $('#my-hero-equipement-tab-container'),
name: 'equippable'
},
{
$container: $('#equipement-tab-container .right-container'),
name: 'sellable'
}
]
let containers = []

containers.forEach(({$container, name}) => {
const manager = new EquipManager($container, name)
if (Helpers.isCurrentPage('shop')) {
containers = [
{
$container: $('#my-hero-equipement-tab-container'),
name: 'equippable'
},
{
$container: $('#equipement-tab-container .right-container'),
name: 'sellable'
}
]

} else if (Helpers.isCurrentPage('mythic-equipment-upgrade')) {
containers = [
{
$container: $('.inventory-section'),
name: 'upgrade',
skipFilter: true,
},
]
}
containers.forEach(({$container, name, skipFilter}) => {
const manager = new EquipManager($container, name, skipFilter)
manager.init()
})

// const favouriteSafetyObserver = new MutationObserver(() => this.checkSelection())
// favouriteSafetyObserver.observe($('#inventory .armor .inventory_slots > div:first-child()')[0], {subtree: true, attributes: true, attributeFilter: ['class']})
})

this.hasRun = true
Expand Down

0 comments on commit c3b97bc

Please sign in to comment.