mirror of https://gitgud.io/fatchan/jschan.git
parent
8003f4de08
commit
13f5dbfa5b
6 changed files with 71 additions and 6 deletions
@ -0,0 +1,53 @@ |
||||
let imageSources = new Set(JSON.parse(localStorage.getItem('hiddenimages'))); |
||||
|
||||
const toggleAllHidden = (state) => imageSources.forEach(i => toggleSource(i, state)); |
||||
|
||||
const toggleSource = (source, state) => { |
||||
const images = document.querySelectorAll(`img.file-thumb[src="${source}"]`); |
||||
images.forEach(i => i.classList[state?'add':'remove']('vh')); |
||||
} |
||||
|
||||
toggleAllHidden(true); |
||||
|
||||
const toggleHandler = (e) => { |
||||
const thumbSource = e.target.dataset.src |
||||
const hidden = imageSources.has(thumbSource); |
||||
imageSources[hidden?'delete':'add'](thumbSource); |
||||
setLocalStorage('hiddenimages', JSON.stringify([...imageSources])); |
||||
toggleSource(thumbSource, !hidden); |
||||
} |
||||
|
||||
document.querySelectorAll('.hide-image').forEach(el => { |
||||
el.addEventListener('click', toggleHandler, false); |
||||
}); |
||||
|
||||
const handleHiddenImages = (e) => { |
||||
//hide any images from this post that should already be hidden
|
||||
const hasHiddenImages = e.detail.json.files.forEach(f => { |
||||
if (imageSources.has(f.filename)) { |
||||
toggleSource(f.filename, true); |
||||
} |
||||
}); |
||||
//add the hide toggle link and event listener
|
||||
if (!e.detail.hover) { |
||||
e.detail.post.querySelector('.hide-image').addEventListener('click', toggleHandler, false); |
||||
} |
||||
} |
||||
|
||||
window.addEventListener('addPost', handleHiddenImages, false); |
||||
|
||||
window.addEventListener('settingsReady', () => { |
||||
|
||||
imageSourcesList = document.getElementById('hiddenimages-setting'); |
||||
imageSourcesList.value = [...imageSources]; |
||||
const imageSourcesListClearButton = document.getElementById('hiddenimages-clear'); |
||||
const clearImageSources = () => { |
||||
toggleAllHidden(false); |
||||
imageSources = new Set(); |
||||
imageSourcesList.value = ''; |
||||
setLocalStorage('hiddenimages', '[]'); |
||||
console.log('cleared hidden images list'); |
||||
} |
||||
imageSourcesListClearButton.addEventListener('click', clearImageSources, false); |
||||
|
||||
}); |
Loading…
Reference in new issue