Skip to content

Instantly share code, notes, and snippets.

@danielkwok21
Last active November 29, 2022 07:20
Show Gist options
  • Save danielkwok21/c6544e52b8933f1cc870bdc3e3c5979e to your computer and use it in GitHub Desktop.
Save danielkwok21/c6544e52b8933f1cc870bdc3e3c5979e to your computer and use it in GitHub Desktop.
<script>
const params = new URLSearchParams(window.location.search)
const halalButtonEl = document.getElementById("halalButton")
let isFilterHalal = false
if (isFilterHalal) {
toggleHalalButton(false)
} else {
toggleHalalButton(true)
}
halalButtonEl.onclick = () => {
const posts = document.getElementsByClassName("ue_post_blocks_box")
if (isFilterHalal) {
toggleHalalButton(true)
for (let i = 0; i < posts.length; i++) {
const post = posts[i]
post.style.display = 'block'
}
} else {
toggleHalalButton(false)
for (let i = 0; i < posts.length; i++) {
const post = posts[i]
const toHide = !post.innerHTML.includes("Halal")
if (toHide) {
post.style.display = 'none'
} else {
post.style.display = 'visible'
}
}
}
isFilterHalal = !isFilterHalal
}
function toggleHalalButton(isToggled) {
if (isToggled) {
halalButtonEl.style.backgroundColor = 'white'
halalButtonEl.style.color = '#81b759'
} else {
halalButtonEl.style.backgroundColor = '#81b759'
halalButtonEl.style.color = 'white'
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment