Skip to content

Commit

Permalink
Fix highlighting on search page for dynamically loaded items
Browse files Browse the repository at this point in the history
  • Loading branch information
MxtOUT committed Sep 17, 2019
1 parent 4a5f034 commit d22ba5d
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions js/content/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3046,40 +3046,44 @@ let SearchPageClass = (function(){
let inputObserver = new MutationObserver(modifyLinks);
inputObserver.observe(hiddenInput, {attributes: true, attributeFilter: ["value"]});

let contscrollObserver;
if (SyncedStorage.get("contscroll")) {
contscrollObserver = new MutationObserver(mutations => {
EarlyAccess.showEarlyAccess();
mutations.forEach(mutation => {
Highlights.highlightAndTag(mutation.addedNodes);
filtersChanged(mutation.addedNodes);
});
});
contscrollObserver.observe(document.querySelectorAll("#search_result_container > div")[1], {childList: true});
}

Messenger.addMessageListener("ajaxCompleted", () => {
if (SyncedStorage.get("contscroll")) {
mutations.forEach(mutation => {
for (let node of mutation.removedNodes) {
// Under certain circumstances the search result container will get removed and then added again, thus disconnecting the MutationObserver
if (node.id && node.id === "search_result_container") {
contscrollObserver.observe(document.querySelectorAll("#search_result_container > div")[1], {childList: true});
break;
let removeObserver = new MutationObserver(mutations => {
mutations.forEach(mutation => {
for (let node of mutation.addedNodes) {
// Under certain circumstances the search result container will get removed and then added again, thus disconnecting the MutationObserver
if (node.id === "search_result_container") {
observeAjax(node.querySelectorAll(".search_result_row"));

if (!SyncedStorage.get("contscroll")) {
toggleFilter("price-above", "#es_notpriceabove");
toggleFilter("reviews-below", "#es_noreviewsbelow");
modifyLinks();
filtersChanged();
}
ajaxObserver.observe(node.querySelector("#search_resultsRows"), {childList: true});
break;
}
})
} else {
toggleFilter("price-above", "#es_notpriceabove");
toggleFilter("reviews-below", "#es_noreviewsbelow");
modifyLinks();
}
}
});
});
removeObserver.observe(document.querySelector("#search_results"), { childList: true });

function observeAjax(addedNodes) {
EarlyAccess.showEarlyAccess();

Highlights.highlightAndTag(addedNodes);
filtersChanged(addedNodes);
}

Highlights.highlightAndTag(document.querySelectorAll(".search_result_row"));
filtersChanged();
}, false);
let ajaxObserver = new MutationObserver(mutations => {
let rows = [];
for (let mutation of mutations) {
rows = rows.concat(
Array.from(mutation.addedNodes).filter(node => node.classList && node.classList.contains("search_result_row"))
);
}
observeAjax(rows);
});
ajaxObserver.observe(document.querySelector("#search_resultsRows"), {childList: true});
};

return SearchPageClass;
Expand Down

0 comments on commit d22ba5d

Please sign in to comment.