I had a similar need. I had to make links for pre-filtered results. I found a solution with html parameters (adding “/?venue=“filter”” for example at the end of the html link and it’s handled by this stript but it shouldent be used as it is because I made it for my own needs…
<script type="text/javascript">
function decodeHtmlEntities(str) {
var list = [
['"', /"/g],
["'", /'/g],
["'", /'/g],
['&', /&/g],
['<', /</g],
['>', />/g],
['¡', /¡/g],
['¢', /¢/g],
['£', /£/g],
['¤', /¤/g],
['¥', /¥/g],
['¦', /¦/g],
['§', /§/g],
['¨', /¨/g],
['©', /©/g],
['ª', /ª/g],
['«', /«/g],
['¬', /¬/g],
['', /­/g],
['®', /®/g],
['¯', /¯/g],
['°', /°/g],
['±', /±/g],
['²', /²/g],
['³', /³/g],
['´', /´/g],
['µ', /µ/g],
['¶', /¶/g],
['·', /·/g],
['¸', /¸/g],
['¹', /¹/g],
['º', /º/g],
['»', /»/g],
['¼', /¼/g],
['½', /½/g],
['¾', /¾/g],
['¿', /¿/g],
['×', /×/g],
['÷', /÷/g],
['À', /À/g],
['Á', /Á/g],
['Â', /Â/g],
['Ã', /Ã/g],
['Ä', /Ä/g],
['Å', /Å/g],
['Æ', /Æ/g],
['Ç', /Ç/g],
['È', /È/g],
['É', /É/g],
['Ê', /Ê/g],
['Ë', /Ë/g],
['Ì', /Ì/g],
['Í', /Í/g],
['Î', /Î/g],
['Ï', /Ï/g],
['Ð', /Ð/g],
['Ñ', /Ñ/g],
['Ò', /Ò/g],
['Ó', /Ó/g],
['Ô', /Ô/g],
['Õ', /Õ/g],
['Ö', /Ö/g],
['Ø', /Ø/g],
['Ù', /Ù/g],
['Ú', /Ú/g],
['Û', /Û/g],
['Ü', /Ü/g],
['Ý', /Ý/g],
['Þ', /Þ/g],
['ß', /ß/g],
['à', /à/g],
['á', /á/g],
['â', /â/g],
['ã', /ã/g],
['ä', /ä/g],
['å', /å/g],
['æ', /æ/g],
['ç', /ç/g],
['è', /è/g],
['é', /é/g],
['ê', /ê/g],
['ë', /ë/g],
['ì', /ì/g],
['í', /í/g],
['î', /î/g],
['ï', /ï/g],
['ð', /ð/g],
['ñ', /ñ/g],
['ò', /ò/g],
['ó', /ó/g],
['ô', /ô/g],
['õ', /õ/g],
['ö', /ö/g],
['ø', /ø/g],
['ù', /ù/g],
['ú', /ú/g],
['û', /û/g],
['ü', /ü/g],
['ý', /ý/g],
['þ', /þ/g],
['ÿ', /ÿ/g]
];
// Boucle à travers la liste et remplace les entités HTML par les caractères correspondants
for (var i = 0; i < list.length; i++) {
str = str.replace(list[i][1], list[i][0]);
}
return str;
}
const waitForElement = (selector, root = document) => new Promise(res => {
let i = 0;
const check = () => {
const component = root.querySelector(selector);
if (component) {
res(component);
} else if (i !== 50) {
setTimeout(check, 100);
i++;
}
};
check();
});
document.addEventListener('DOMContentLoaded', function() {
var urlParams = new URLSearchParams(window.location.search);
var filterVenue = urlParams.get('venue');
var filterTag = decodeHtmlEntities(decodeURIComponent(urlParams.get('tag')));
console.log(filterVenue);
console.log(filterTag);
if (filterVenue) {
var widget = document.querySelectorAll('.elfsight-app-4040ba81-1f6f-4048-9525-7e29f9cd68f7');
for (let i = 0; i < widget.length; i++) {
if (widget[i]) {
widget[i].setAttribute('data-elfsight-app-filter-venue', filterVenue);
} else {
console.error("No widget found.");
}
}
} else {
// Si aucun paramètre de lieu, définir sur "Tous"
}
if (filterTag) {
waitForElement("#es-custom-filter").then((myfilter) => {
if (myfilter) {
var options = myfilter.options;
for (var j = 0; j < options.length; j++) {
if (options[j].text.toLowerCase() === filterTag.toLowerCase()) {
myfilter.selectedIndex = j;
var event = new Event('change');
myfilter.dispatchEvent(event);
break;
}
}
} else {
console.error("No filter found.");
}
});
} else {
// Si aucun paramètre de tag, définir sur "Tous"
}
});
</script>