From e3162e0a095db4610c3f486fe5c4267ed7a7f3a1 Mon Sep 17 00:00:00 2001 From: MxtOUT <14999077+MxtOUT@users.noreply.github.com> Date: Tue, 17 Sep 2019 12:28:20 +0200 Subject: [PATCH] Add clientside method for excluding tags --- js/content/store.js | 55 ++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/js/content/store.js b/js/content/store.js index aad7df43d..154a5b1e6 100644 --- a/js/content/store.js +++ b/js/content/store.js @@ -2554,10 +2554,10 @@ let SearchPageClass = (function(){ return tagsValue ? tagsValue.split(',') : []; } - for (let i=0, len=tarFilterDivs.length; i -1 ? "checked" : ""; + for (let val of tarFilterDivs) { + let item_checked = tags.indexOf(`-${val.dataset.value}`) > -1 ? "checked" : ''; let excludeItem = HTMLParser.htmlToElement( `
@@ -2565,8 +2565,8 @@ let SearchPageClass = (function(){ ${val.dataset.loc}
`); - excludeItem.addEventListener("click", function(e) { - let control = e.target.closest(".tab_filter_control") + excludeItem.addEventListener("click", e => { + let control = e.target.closest(".tab_filter_control"); let rgValues = getTags(); let value = String(control.dataset.value); @@ -2586,8 +2586,7 @@ let SearchPageClass = (function(){ } control.classList.toggle('checked'); - document.querySelector("#tags").value = rgValues.join(','); - ExtensionLayer.runInPageContext(() => AjaxSearchResults()); + filtersChanged(); }); excludeContainer.append(excludeItem); @@ -2648,19 +2647,38 @@ let SearchPageClass = (function(){ return Number(reviewsString) < reviewsBelow; } + function isTagExcluded(node, tags) { + if (!node.dataset.dsTagids) return false; + let nodeTags = JSON.parse(node.dataset.dsTagids); + return nodeTags.some(tag => tags.includes(tag)); + } + function filtersChanged(nodes = document.querySelectorAll(".search_result_row")) { + let hideOwned = document.querySelector("#es_owned_games.checked"); + let hideWishlisted = document.querySelector("#es_wishlist_games.checked"); + let hideInCart = document.querySelector("#es_cart_games.checked"); + let hideNotDiscounted = document.querySelector("#es_notdiscounted_games.checked"); + let hideNotInterested = document.querySelector("#es_notinterested.checked"); + let hideMixed = document.querySelector("#es_notmixed.checked"); + let hideNegative = document.querySelector("#es_notnegative.checked"); + let hidePriceAbove = document.querySelector("#es_notpriceabove.checked"); + let hideReviewsBelow = document.querySelector("#es_noreviewsbelow.checked"); + let priceAbove = Number(document.querySelector("#es_notpriceabove_val").value.replace(',', '.')); let reviewsBelow = Number(document.querySelector("#es_noreviewsbelow_val").value); + let hideTags = Array.from(document.querySelectorAll("#es_tagfilter_exclude_container > .checked")).map(tag => Math.abs(Number(tag.dataset.value))); + for (let node of nodes) { - if (document.querySelector("#es_owned_games.checked") && node.classList.contains("ds_owned")) { node.style.display = "none"; continue; } - if (document.querySelector("#es_wishlist_games.checked") && node.classList.contains("ds_wishlist")) { node.style.display = "none"; continue; } - if (document.querySelector("#es_cart_games.checked") && node.classList.contains("ds_incart")) { node.style.display = "none"; continue; } - if (document.querySelector("#es_notdiscounted.checked") && !node.querySelector(".search_discount span")) { node.style.display = "none"; continue; } - if (document.querySelector("#es_notinterested.checked") && node.classList.contains("ds_ignored")) { node.style.display = "none"; continue; } - if (document.querySelector("#es_notmixed.checked") && node.querySelector(".search_reviewscore span.search_review_summary.mixed")) { node.style.display = "none"; continue; } - if (document.querySelector("#es_notnegative.checked") && node.querySelector(".search_reviewscore span.search_review_summary.negative")) { node.style.display = "none"; continue; } - if (document.querySelector("#es_notpriceabove.checked") && isPriceAbove(node, priceAbove)) { node.style.display = "none"; continue; } - if (document.querySelector("#es_noreviewsbelow.checked") && isReviewsBelow(node, reviewsBelow)) { node.style.display = "none"; continue; } + if (hideOwned && node.classList.contains("ds_owned")) { node.style.display = "none"; continue; } + if (hideWishlisted && node.classList.contains("ds_wishlist")) { node.style.display = "none"; continue; } + if (hideInCart && node.classList.contains("ds_incart")) { node.style.display = "none"; continue; } + if (hideNotDiscounted && !node.querySelector(".search_discount span")) { node.style.display = "none"; continue; } + if (hideNotInterested && node.classList.contains("ds_ignored")) { node.style.display = "none"; continue; } + if (hideMixed && node.querySelector(".search_reviewscore span.search_review_summary.mixed")) { node.style.display = "none"; continue; } + if (hideNegative && node.querySelector(".search_reviewscore span.search_review_summary.negative")) { node.style.display = "none"; continue; } + if (hidePriceAbove && isPriceAbove(node, priceAbove)) { node.style.display = "none"; continue; } + if (hideReviewsBelow && isReviewsBelow(node, reviewsBelow)) { node.style.display = "none"; continue; } + if (hideTags.length && isTagExcluded(node, hideTags)) { node.style.display = "none"; continue; } node.style.display = "block"; } } @@ -2749,10 +2767,7 @@ let SearchPageClass = (function(){ GDynamicStore.OnReady(() => { - // Callback that will fire when the user browses through pages - ${!SyncedStorage.get("contscroll") ? `Ajax.Responders.register({ onComplete: () => Messenger.postMessage("ajaxCompleted") });` : ""} - - // For each AS hide filter + // For each AS filter $J(".tab_filter_control[id^='es_']").each(function() { let $Control = $J(this); $Control.click(() => updateURL($Control));