Question: Is there a simpler way to add filter options?
Link to site: https://test-writing.squarespace.com/330?noredirect
Password: abc
I want to create Filter options in Filter Embed widget, something like this
I don’t see an option to add Filter so currently I edit File name, use format like this
File 01 ##English, Natural, Free
then use JS code like this to convert strings after ## to filter options
<script>
setTimeout(() => {
const languages = new Set();
const types = new Set();
const galleryItems = document.querySelectorAll('.eapp-file-embed-item-component');
galleryItems.forEach(item => {
const nameElement = item.querySelector('.eapp-file-embed-item-name');
if (nameElement) {
const fullName = nameElement.textContent.trim();
const hashIndex = fullName.indexOf('##');
if (hashIndex !== -1) {
const beforeHash = fullName.substring(0, hashIndex).trim();
const afterHash = fullName.substring(hashIndex + 2).trim();
nameElement.textContent = beforeHash;
const parts = afterHash.split(',').map(part => part.trim());
if (parts.length >= 2) {
const language = parts[0];
const type = parts[1];
languages.add(language);
types.add(type);
item.setAttribute('data-language', language);
item.setAttribute('data-type', type);
if (afterHash.includes('Member')) {
const wrapper = item.querySelector('.eapp-file-embed-item-wrapper');
if (wrapper) {
const loginNotice = document.createElement('div');
loginNotice.className = 'login-notice';
loginNotice.textContent = 'Login to download';
loginNotice.style.cssText = 'color: #666; font-size: 12px; margin-top: 4px;';
wrapper.appendChild(loginNotice);
}
}
}
}
}
});
const titleElement = document.querySelector('.eapp-file-embed-title-component');
if (titleElement) {
const filterContainer = document.createElement('div');
filterContainer.className = 'gallery-filter-bar';
filterContainer.style.cssText = 'margin: 20px 0; text-align: center;';
const languageWrapper = document.createElement('div');
languageWrapper.style.cssText = 'display: inline-block; margin: 0 15px;';
const languageLabel = document.createElement('label');
languageLabel.textContent = 'Language:';
languageLabel.style.cssText = 'display: block; margin-bottom: 5px; font-weight: bold;';
const languageSelect = document.createElement('select');
languageSelect.style.cssText = 'padding: 8px 12px; border: 1px solid #ccc; border-radius: 5px; background: white;';
const allLanguagesOption = document.createElement('option');
allLanguagesOption.value = '';
allLanguagesOption.textContent = 'All Languages';
languageSelect.appendChild(allLanguagesOption);
languages.forEach(lang => {
const option = document.createElement('option');
option.value = lang;
option.textContent = lang;
languageSelect.appendChild(option);
});
const typeWrapper = document.createElement('div');
typeWrapper.style.cssText = 'display: inline-block; margin: 0 15px;';
const typeLabel = document.createElement('label');
typeLabel.textContent = 'Type:';
typeLabel.style.cssText = 'display: block; margin-bottom: 5px; font-weight: bold;';
const typeSelect = document.createElement('select');
typeSelect.style.cssText = 'padding: 8px 12px; border: 1px solid #ccc; border-radius: 5px; background: white;';
const allTypesOption = document.createElement('option');
allTypesOption.value = '';
allTypesOption.textContent = 'All Types';
typeSelect.appendChild(allTypesOption);
types.forEach(type => {
const option = document.createElement('option');
option.value = type;
option.textContent = type;
typeSelect.appendChild(option);
});
function filterItems() {
const selectedLanguage = languageSelect.value;
const selectedType = typeSelect.value;
galleryItems.forEach(item => {
const itemLanguage = item.getAttribute('data-language') || '';
const itemType = item.getAttribute('data-type') || '';
const languageMatch = !selectedLanguage || itemLanguage === selectedLanguage;
const typeMatch = !selectedType || itemType === selectedType;
if (languageMatch && typeMatch) {
item.style.display = '';
} else {
item.style.display = 'none';
}
});
}
languageSelect.addEventListener('change', filterItems);
typeSelect.addEventListener('change', filterItems);
languageWrapper.appendChild(languageLabel);
languageWrapper.appendChild(languageSelect);
typeWrapper.appendChild(typeLabel);
typeWrapper.appendChild(typeSelect);
filterContainer.appendChild(languageWrapper);
filterContainer.appendChild(typeWrapper);
titleElement.parentNode.insertBefore(filterContainer, titleElement.nextSibling);
}
}, 3000);
</script>
Thank you!

