Skip to content

Commit

Permalink
Add clientside method for excluding tags
Browse files Browse the repository at this point in the history
  • Loading branch information
MxtOUT committed Sep 17, 2019
1 parent d22ba5d commit e3162e0
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions js/content/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2554,19 +2554,19 @@ let SearchPageClass = (function(){
return tagsValue ? tagsValue.split(',') : [];
}

for (let i=0, len=tarFilterDivs.length; i<len; i++) {
let val = tarFilterDivs[i];
let tags = getTags();

let item_checked = getTags().indexOf("-"+val.dataset.value) > -1 ? "checked" : "";
for (let val of tarFilterDivs) {
let item_checked = tags.indexOf(`-${val.dataset.value}`) > -1 ? "checked" : '';

let excludeItem = HTMLParser.htmlToElement(
`<div class="tab_filter_control ${item_checked}" data-param="tags" data-value="-${val.dataset.value}" data-loc="${val.dataset.loc}">
<div class="tab_filter_control_checkbox"></div>
<span class="tab_filter_control_label">${val.dataset.loc}</span>
</div>`);

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);
Expand All @@ -2586,8 +2586,7 @@ let SearchPageClass = (function(){
}

control.classList.toggle('checked');
document.querySelector("#tags").value = rgValues.join(',');
ExtensionLayer.runInPageContext(() => AjaxSearchResults());
filtersChanged();
});

excludeContainer.append(excludeItem);
Expand Down Expand Up @@ -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";
}
}
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit e3162e0

Please sign in to comment.