// ==UserScript== // @name Fullchan X // @namespace Violentmonkey Scripts // @match *://8chan.moe/* // @match *://8chan.se/* // @match *://8chan.cc/* // @match *://8chan.cc/* // @run-at document-end // @grant none // @version 1.14.2 // @author vfyxe // @description 8chan features script // @downloadURL https://update.greasyfork.icu/scripts/533067/Fullchan%20X.user.js // @updateURL https://update.greasyfork.icu/scripts/533067/Fullchan%20X.meta.js // ==/UserScript== class fullChanX extends HTMLElement { constructor() { super(); } init() { this.settingsEl = document.querySelector('fullchan-x-settings'); this.settingsAll = this.settingsEl.settings; this.settings = this.settingsAll.main; this.settingsThreadBanisher = this.settingsAll.threadBanisher; this.settingsMascot = this.settingsAll.mascot; this.isThread = !!document.querySelector('.opCell'); this.isDisclaimer = window.location.href.includes('disclaimer'); Object.keys(this.settings).forEach(key => { this[key] = this.settings[key]?.value; }); this.settingsButton = this.querySelector('#fcx-settings-btn'); this.settingsButton.addEventListener('click', () => this.settingsEl.toggle()); this.handleBoardLinks(); if (!this.isThread) { if (this.settingsThreadBanisher.enableThreadBanisher.value) this.banishThreads(this.settingsThreadBanisher); return; } this.quickReply = document.querySelector('#quick-reply'); this.qrbody = document.querySelector('#qrbody'); this.threadParent = document.querySelector('#divThreads'); this.threadId = this.threadParent.querySelector('.opCell').id; this.thread = this.threadParent.querySelector('.divPosts'); this.posts = [...this.thread.querySelectorAll('.postCell')]; this.postOrder = 'default'; this.postOrderSelect = this.querySelector('#thread-sort'); this.myYousLabel = this.querySelector('.my-yous__label'); this.yousContainer = this.querySelector('#my-yous'); this.gallery = document.querySelector('fullchan-x-gallery'); this.galleryButton = this.querySelector('#fcx-gallery-btn'); this.updateYous(); this.observers(); if (this.enableFileExtensions) this.handleTruncatedFilenames(); if (this.settingsMascot.enableMascot.value) this.showMascot(this.settingsMascot); this.styleUI(); if (this.settings.doNotShowLocation) { const checkbox = document.getElementById('qrcheckboxNoFlag'); if (checkbox) checkbox.checked = true; checkbox.dispatchEvent(new Event('change', { bubbles: true })); } } styleUI () { this.style.setProperty('--top', this.uiTopPosition); this.style.setProperty('--right', this.uiRightPosition); this.classList.toggle('fcx-in-nav', this.moveToNav) this.classList.toggle('fcx--dim', this.uiDimWhenInactive && !this.moveToNave); this.classList.toggle('page-thread', this.isThread); document.body.classList.toggle('fcx-replies-plus', this.enableEnhancedReplies); document.body.classList.toggle('fcx-hide-delete', this.hideDeletionBox); const style = document.createElement('style'); if (this.hideDefaultBoards !== '' && this.hideDefaultBoards.toLowerCase() !== 'all') { style.textContent += '#navTopBoardsSpan{display:block!important;}' } document.body.appendChild(style); } checkRegexList(string, regexList) { const regexObjects = regexList.map(r => { const match = r.match(/^\/(.*)\/([gimsuy]*)$/); return match ? new RegExp(match[1], match[2]) : null; }).filter(Boolean); return regexObjects.some(regex => regex.test(string)); } banishThreads(banisher) { this.threadsContainer = document.querySelector('#divThreads'); if (!this.threadsContainer) return; this.threadsContainer.classList.add('fcx-threads'); const currentBoard = document.querySelector('#labelBoard')?.textContent.replace(/\//g,''); const boards = banisher.boards.value?.split(',') || ['']; if (!boards.includes(currentBoard)) return; const minCharacters = banisher.minimumCharacters.value || 0; const banishTerms = banisher.banishTerms.value?.split('\n') || []; const banishAnchored = banisher.banishAnchored.value; const wlCyclical = banisher.whitelistCyclical.value; const wlReplyCount = parseInt(banisher.whitelistReplyCount.value); const banishSorter = (thread) => { if (thread.querySelector('.pinIndicator') || thread.classList.contains('fcx-sorted')) return; let shouldBanish = false; const isAnchored = thread.querySelector('.bumpLockIndicator'); const isCyclical = thread.querySelector('.cyclicIndicator'); const replyCount = parseInt(thread.querySelector('.labelReplies')?.textContent?.trim()) || 0; const threadSubject = thread.querySelector('.labelSubject')?.textContent?.trim() || ''; const threadMessage = thread.querySelector('.divMessage')?.textContent?.trim() || ''; const threadContent = threadSubject + ' ' + threadMessage; const hasMinChars = threadMessage.length > minCharacters; const hasWlReplyCount = replyCount > wlReplyCount; if (!hasMinChars) shouldBanish = true; if (isAnchored && banishAnchored) shouldBanish = true; if (isCyclical && wlCyclical) shouldBanish = false; if (hasWlReplyCount) shouldBanish = false; // run heavy regex process only if needed if (!shouldBanish && this.checkRegexList(threadContent, banishTerms)) shouldBanish = true; if (shouldBanish) thread.classList.add('shit-thread'); thread.classList.add('fcx-sorted'); }; const banishThreads = () => { this.threads = this.threadsContainer.querySelectorAll('.catalogCell'); this.threads.forEach(thread => banishSorter(thread)); }; banishThreads(); const observer = new MutationObserver((mutationsList) => { for (const mutation of mutationsList) { if (mutation.type === 'childList' && mutation.addedNodes.length > 0) { banishThreads(); break; } } }); observer.observe(this.threadsContainer, { childList: true }); } handleBoardLinks () { const navBoards = document.querySelector('#navTopBoardsSpan'); const customBoardLinks = this.customBoardLinks?.toLowerCase().replace(/\s/g,'').split(','); let hideDefaultBoards = this.hideDefaultBoards?.toLowerCase().replace(/\s/g,'') || ''; const urlCatalog = this.catalogBoardLinks ? '/catalog.html' : ''; if (hideDefaultBoards === 'all') { document.body.classList.add('hide-navboard'); } else { const waitForNavBoards = setInterval(() => { const navBoards = document.querySelector('#navTopBoardsSpan'); if (!navBoards || !navBoards.querySelector('a')) return; clearInterval(waitForNavBoards); hideDefaultBoards = hideDefaultBoards.split(','); const defaultLinks = [...navBoards.querySelectorAll('a')]; defaultLinks.forEach(link => { link.href += urlCatalog; const linkText = link.textContent; const shouldHide = hideDefaultBoards.includes(linkText) || customBoardLinks.includes(linkText); link.classList.toggle('hidden', shouldHide); }); }, 50); if (this.customBoardLinks?.length > 0) { const customNav = document.createElement('span'); customNav.classList = 'nav-boards nav-boards--custom'; customNav.innerHTML = '['; customBoardLinks.forEach((board, index) => { const link = document.createElement('a'); link.href = '/' + board + urlCatalog; link.textContent = board; customNav.appendChild(link); if (index < customBoardLinks.length - 1) customNav.innerHTML += '/'; }); customNav.innerHTML += ']'; navBoards?.parentNode.insertBefore(customNav, navBoards); } } } observers () { this.postOrderSelect.addEventListener('change', (event) => { this.postOrder = event.target.value; this.assignPostOrder(); }); // Thread click this.threadParent.addEventListener('click', event => this.handleClick(event)); // Your (You)s const observerCallback = (mutationsList, observer) => { for (const mutation of mutationsList) { if (mutation.type === 'childList') { this.posts = [...this.thread.querySelectorAll('.postCell')]; if (this.postOrder !== 'default') this.assignPostOrder(); this.updateYous(); this.gallery.updateGalleryImages(); if (this.settings.enableFileExtensions) this.handleTruncatedFilenames(); } } }; const threadObserver = new MutationObserver(observerCallback); threadObserver.observe(this.thread, { childList: true, subtree: false }); // Gallery this.galleryButton.addEventListener('click', () => this.gallery.open()); this.myYousLabel.addEventListener('click', (event) => { if (this.myYousLabel.classList.contains('unseen')) { this.yousContainer.querySelector('.unseen').click(); } }); if (!this.enableEnhancedReplies) return; const setReplyLocation = (replyPreview) => { const parent = replyPreview.parentElement; if (!parent || (!parent.classList.contains('innerPost') && !parent.classList.contains('innerOP'))) return; const parentMessage = parent.querySelector('.divMessage'); if (parentMessage && parentMessage.parentElement === parent) { parentMessage.insertAdjacentElement('beforebegin', replyPreview); } }; const observer = new MutationObserver(mutations => { for (const mutation of mutations) { for (const node of mutation.addedNodes) { if (node.nodeType !== 1) continue; if (node.classList.contains('inlineQuote')) { const replyPreview = node.closest('.replyPreview'); if (replyPreview) { setReplyLocation(replyPreview); } } } } }); if (this.threadParent) observer.observe(this.threadParent, {childList: true, subtree: true }); } handleClick (event) { const clicked = event.target; let replyLink = clicked.closest('.panelBacklinks a'); const parentPost = clicked.closest('.innerPost, .innerOP'); const closeButton = clicked.closest('.postInfo > a:first-child'); const anonId = clicked.closest('.labelId'); if (closeButton) this.handleReplyCloseClick(closeButton, parentPost); if (replyLink) this.handleReplyClick(replyLink, parentPost); if (anonId) this.handleAnonIdClick(anonId, event); } handleReplyCloseClick(closeButton, parentPost) { const replyLink = document.querySelector(`[data-close-id="${closeButton.id}"]`); if (!replyLink) return; const linkParent = replyLink.closest('.innerPost, .innerOP'); this.handleReplyClick(replyLink, linkParent); } handleReplyClick(replyLink, parentPost) { replyLink.classList.toggle('active'); let replyColor = replyLink.dataset.color; const replyId = replyLink.href.split('#').pop(); let replyPost = false; let labelId = false; const randomNum = () => `${Math.floor(Math.random() * 16777215).toString(16).padStart(6, '0')}` if (!replyColor) { replyPost = document.querySelector(`#${CSS.escape(replyId)}`); labelId = replyPost?.querySelector('.labelId'); replyColor = labelId?.textContent || randomNum(); } const linkQuote = [...parentPost.querySelectorAll('.replyPreview .linkQuote')] .find(link => link.textContent === replyId); if (!labelId && linkQuote) linkQuote.style = `--active-color: #${replyColor};`; const closeId = randomNum(); const closeButton = linkQuote?.closest('.innerPost').querySelector('.postInfo > a:first-child'); if (closeButton) closeButton.id = closeId; replyLink.style = `--active-color: #${replyColor};`; replyLink.dataset.color = `${replyColor}`; replyLink.dataset.closeId = closeId; } handleAnonIdClick (anonId, event) { this.anonIdPosts?.remove(); if (anonId === this.anonId) { this.anonId = null; return; } this.anonId = anonId; const anonIdText = anonId.textContent.split(' ')[0]; this.anonIdPosts = document.createElement('div'); this.anonIdPosts.classList = 'fcx-id-posts fcx-prevent-nesting'; const match = window.location.pathname.match(/^\/[^/]+\/res\/\d+\.html/); const prepend = match ? `${match[0]}#` : ''; const selector = `.postInfo:has(.labelId[style="background-color: #${anonIdText}"]) .linkQuote`; const postIds = [...this.threadParent.querySelectorAll(selector)].map(link => { const postId = link.getAttribute('href').split('#q').pop(); const newLink = document.createElement('a'); newLink.className = 'quoteLink'; newLink.href = prepend + postId; newLink.textContent = `>>${postId}`; return newLink; }); postIds.forEach(postId => this.anonIdPosts.appendChild(postId)); anonId.insertAdjacentElement('afterend', this.anonIdPosts); this.setPostListeners(this.anonIdPosts); } setPostListeners(parentPost) { const postLinks = [...parentPost.querySelectorAll('.quoteLink')]; const hoverPost = (event, link) => { const quoteId = link.href.split('#')[1]; let existingPost = document.querySelector(`.nestedPost[data-quote-id="${quoteId}"]`) || link.closest(`.postCell[id="${quoteId}"]`); if (existingPost) { this.markedPost = existingPost.querySelector('.innerPost') || existingPost.querySelector('.innerOP'); this.markedPost?.classList.add('markedPost'); return; } const quotePost = document.getElementById(quoteId); tooltips.removeIfExists(); const tooltip = document.createElement('div'); tooltip.className = 'quoteTooltip'; document.body.appendChild(tooltip); const rect = link.getBoundingClientRect(); if (!api.mobile) { if (rect.left > window.innerWidth / 2) { const right = window.innerWidth - rect.left - window.scrollX; tooltip.style.right = `${right}px`; } else { const left = rect.right + 10 + window.scrollX; tooltip.style.left = `${left}px`; } } tooltip.style.top = `${rect.top + window.scrollY}px`; tooltip.style.display = 'inline'; tooltips.loadTooltip(tooltip, link.href, quoteId); tooltips.currentTooltip = tooltip; } const unHoverPost = (event, link) => { if (!tooltips.currentTooltip) { this.markedPost?.classList.remove('markedPost'); return false; } if (tooltips.unmarkReply) { tooltips.currentTooltip.classList.remove('markedPost'); Array.from(tooltips.currentTooltip.getElementsByClassName('replyUnderline')) .forEach((a) => a.classList.remove('replyUnderline')) tooltips.unmarkReply = false; } else { tooltips.currentTooltip.remove(); } tooltips.currentTooltip = null; } const addHoverPost = (link => { link.addEventListener('mouseenter', (event) => hoverPost(event, link)); link.addEventListener('mouseleave', (event) => unHoverPost(event, link)); }); postLinks.forEach(link => addHoverPost(link)); } handleTruncatedFilenames () { this.postFileNames = [...this.threadParent.querySelectorAll('.originalNameLink[download]:not([data-file-ext])')]; this.postFileNames.forEach(fileName => { if (!fileName.textContent.includes('.')) return; const strings = fileName.textContent.split('.'); const typeStr = `.${strings.pop()}`; const typeEl = document.createElement('a'); typeEl.classList = ('file-ext originalNameLink'); typeEl.textContent = typeStr; fileName.dataset.fileExt = typeStr; fileName.textContent = strings.join('.'); fileName.parentNode.insertBefore(typeEl, fileName.nextSibling); }); } assignPostOrder () { const postOrderReplies = (post) => { const replyCount = post.querySelectorAll('.panelBacklinks a').length; post.style.order = 100 - replyCount; } const postOrderCatbox = (post) => { const postContent = post.querySelector('.divMessage').textContent; const matches = postContent.match(/catbox\.moe/g); const catboxCount = matches ? matches.length : 0; post.style.order = 100 - catboxCount; } if (this.postOrder === 'default') { this.thread.style.display = 'block'; return; } this.thread.style.display = 'flex'; if (this.postOrder === 'replies') { this.posts.forEach(post => postOrderReplies(post)); } else if (this.postOrder === 'catbox') { this.posts.forEach(post => postOrderCatbox(post)); } } updateYous () { this.yous = this.posts.filter(post => post.querySelector('.quoteLink.you')); this.yousLinks = this.yous.map(you => { const youLink = document.createElement('a'); youLink.textContent = '>>' + you.id; youLink.href = '#' + you.id; return youLink; }) let hasUnseenYous = false; this.setUnseenYous(); this.yousContainer.innerHTML = ''; this.yousLinks.forEach(you => { const youId = you.textContent.replace('>>', ''); if (!this.seenYous.includes(youId)) { you.classList.add('unseen'); hasUnseenYous = true } this.yousContainer.appendChild(you) }); this.myYousLabel.classList.toggle('unseen', hasUnseenYous); if (this.replyTabIcon === '') return; const icon = this.replyTabIcon; document.title = hasUnseenYous ? document.title.startsWith(`${icon} `) ? document.title : `${icon} ${document.title}` : document.title.replace(new RegExp(`^${icon} `), ''); } observeUnseenYou(you) { you.classList.add('observe-you'); const observer = new IntersectionObserver((entries, observer) => { entries.forEach(entry => { if (entry.isIntersecting) { const id = you.id; you.classList.remove('observe-you'); if (!this.seenYous.includes(id)) { this.seenYous.push(id); localStorage.setItem(this.seenKey, JSON.stringify(this.seenYous)); } observer.unobserve(you); this.updateYous(); } }); }, { rootMargin: '0px', threshold: 0.1 }); observer.observe(you); } setUnseenYous() { this.seenKey = `${this.threadId}-seen-yous`; this.seenYous = JSON.parse(localStorage.getItem(this.seenKey)); if (!this.seenYous) { this.seenYous = []; localStorage.setItem(this.seenKey, JSON.stringify(this.seenYous)); } this.unseenYous = this.yous.filter(you => !this.seenYous.includes(you.id)); this.unseenYous.forEach(you => { if (!you.classList.contains('observe-you')) { this.observeUnseenYou(you); } }); } showMascot(settings) { const mascot = document.createElement('img'); mascot.classList.add('fcx-mascot'); mascot.src = settings.image.value; mascot.style.opacity = settings.opacity.value * 0.01; mascot.style.top = settings.top.value; mascot.style.left = settings.left.value; mascot.style.right = settings.right.value; mascot.style.bottom = settings.bottom.value; mascot.style.height = settings.height.value; mascot.style.width = settings.width.value; document.body.appendChild(mascot); } }; window.customElements.define('fullchan-x', fullChanX); class fullChanXGallery extends HTMLElement { constructor() { super(); } init() { this.fullchanX = document.querySelector('fullchan-x'); this.imageContainer = this.querySelector('.gallery__images'); this.mainImageContainer = this.querySelector('.gallery__main-image'); this.mainImage = this.mainImageContainer.querySelector('img'); this.sizeButtons = [...this.querySelectorAll('.gallery__scale-options .scale-option')]; this.closeButton = this.querySelector('.gallery__close'); this.listeners(); this.addGalleryImages(); this.initalized = true; } addGalleryImages () { this.thumbs = [...this.fullchanX.threadParent.querySelectorAll('.imgLink')].map(thumb => { return thumb.cloneNode(true); }); this.thumbs.forEach(thumb => { this.imageContainer.appendChild(thumb); }); } updateGalleryImages () { if (!this.initalized) return; const newThumbs = [...this.fullchanX.threadParent.querySelectorAll('.imgLink')].filter(thumb => { return !this.thumbs.find(thisThumb.href === thumb.href); }).map(thumb => { return thumb.cloneNode(true); }); newThumbs.forEach(thumb => { this.thumbs.push(thumb); this.imageContainer.appendChild(thumb); }); } listeners () { this.addEventListener('click', event => { const clicked = event.target; let imgLink = clicked.closest('.imgLink'); if (imgLink?.dataset.filemime === 'video/webm') return; if (imgLink) { event.preventDefault(); this.mainImage.src = imgLink.href; } this.mainImageContainer.classList.toggle('active', !!imgLink); const scaleButton = clicked.closest('.scale-option'); if (scaleButton) { const scale = parseFloat(getComputedStyle(this.imageContainer).getPropertyValue('--scale')) || 1; const delta = scaleButton.id === 'fcxg-smaller' ? -0.1 : 0.1; const newScale = Math.max(0.1, scale + delta); this.imageContainer.style.setProperty('--scale', newScale.toFixed(2)); } if (clicked.closest('.gallery__close')) this.close(); }); } open () { if (!this.initalized) this.init(); this.classList.add('open'); document.body.classList.add('fct-gallery-open'); } close () { this.classList.remove('open'); document.body.classList.remove('fct-gallery-open'); } } window.customElements.define('fullchan-x-gallery', fullChanXGallery); class fullChanXSettings extends HTMLElement { constructor() { super(); this.settingsKey = 'fullchan-x-settings'; this.inputs = []; this.settings = {}; this.settingsTemplate = { main: { moveToNav: { info: 'Move Fullchan-X controls into the navbar.', type: 'checkbox', value: true }, enableEnhancedReplies: { info: "Enhances 8chan's native reply post previews.
Inline replies are now a native feature of 8chan, remember to enable them.
", type: 'checkbox', value: true }, hideDeletionBox: { info: "Not much point in seeing this if you're not an mod.", type: 'checkbox', value: false }, doNotShowLocation: { info: "Board with location option will be set to false by default.", type: 'checkbox', value: false }, enableFileExtensions: { info: 'Always show filetype on shortened file names.', type: 'checkbox', value: true }, customBoardLinks: { info: 'List of custom boards in nav (seperate by comma)', type: 'input', value: 'v,a,b' }, hideDefaultBoards: { info: 'List of boards to remove from nav (seperate by comma). Set as "all" to remove all.', type: 'input', value: 'interracial,mlp' }, catalogBoardLinks: { info: 'Redirect nav board links to catalog pages.', type: 'checkbox', value: true }, uiTopPosition: { info: 'Position from top of screen e.g. 100px', type: 'input', value: '50px' }, uiRightPosition: { info: 'Position from right of screen e.g. 100px', type: 'input', value: '25px' }, uiDimWhenInactive: { info: 'Dim UI when not hovering with mouse.', type: 'checkbox', value: true }, hideNavbar: { info: 'Hide navbar until hover.', type: 'checkbox', value: false }, replyTabIcon: { info: 'Set the icon/text added to tab title when you get a new (You).', type: 'input', value: '❗' } }, mascot: { enableMascot: { info: 'Enable mascot image.', type: 'checkbox', value: false }, image: { info: 'Image URL (8chan image recommended).', type: 'input', value: '/.static/logo.png' }, opacity: { info: 'Opacity (1 to 100)', type: 'input', inputType: 'number', value: '75' }, width: { info: 'Width of image.', type: 'input', value: '300px' }, height: { info: 'Height of image.', type: 'input', value: 'auto' }, bottom: { info: 'Bottom position.', type: 'input', value: '0px' }, right: { info: 'Right position.', type: 'input', value: '0px' }, top: { info: 'Top position.', type: 'input', value: '' }, left: { info: 'Left position.', type: 'input', value: '' } }, threadBanisher: { enableThreadBanisher: { info: 'Banish shit threads to the bottom of the calalog.', type: 'checkbox', value: true }, boards: { info: 'Banish theads on these boards (seperated by comma).', type: 'input', value: 'v,a' }, minimumCharacters: { info: 'Minimum character requirements', type: 'input', inputType: 'number', value: 100 }, banishTerms: { info: `Banish threads with these terms to the bottom of the catalog (new line per term).
How to use regex: Regex Cheatsheet.
NOTE: word breaks (\\b) MUST be entered as double escapes (\\\\b), they will appear as (\\b) when saved.
`, type: 'textarea', value: '/\\bcuck\\b/i\n/\\bchud\\b/i\n/\\bblacked\\b/i\n/\\bnormie\\b/i\n/\\bincel\\b/i\n/\\btranny\\b/i\n/\\bslop\\b/i\n' }, whitelistCyclical: { info: 'Whitelist cyclical threads.', type: 'checkbox', value: true }, banishAnchored: { info: 'Banish anchored threads that are under minimum reply count.', type: 'checkbox', value: true }, whitelistReplyCount: { info: 'Threads above this reply count (excluding those with banish terms) will be whitelisted.', type: 'input', inputType: 'number', value: 100 }, } }; } init() { this.fcx = document.querySelector('fullchan-x'); this.settingsMain = this.querySelector('.fcxs-main'); this.settingsThreadBanisher = this.querySelector('.fcxs-thread-banisher'); this.settingsMascot = this.querySelector('.fcxs-mascot'); this.getSavedSettings(); if (this.settings.main) { this.fcx.init(); this.loaded = true; }; this.buildSettingsOptions('main', this.settingsMain); this.buildSettingsOptions('threadBanisher', this.settingsThreadBanisher); this.buildSettingsOptions('mascot', this.settingsMascot); this.listeners(); this.querySelector('.fcx-settings__close').addEventListener('click', () => this.close()); if (!this.loaded) this.fcx.init(); this.fcx.styleUI(); document.body.classList.toggle('fcx-hide-navbar',this.settings.main.hideNavbar.value); } setSavedSettings(updated) { localStorage.setItem(this.settingsKey, JSON.stringify(this.settings)); if (updated) this.classList.add('fcxs-updated'); } getSavedSettings() { let saved = JSON.parse(localStorage.getItem(this.settingsKey)); if (!saved) return; // Ensure all top-level keys exist for (const key in this.settingsTemplate) { if (!saved[key]) saved[key] = {}; } this.settings = saved; } listeners() { this.inputs.forEach(input => { input.addEventListener('change', () => { const section = input.dataset.section; const key = input.name; const value = input.type === 'checkbox' ? input.checked : input.value; this.settings[section][key].value = value; this.setSavedSettings(true); }); }); } buildSettingsOptions(subSettings, parent) { if (!this.settings[subSettings]) this.settings[subSettings] = {} Object.entries(this.settingsTemplate[subSettings]).forEach(([key, config]) => { const wrapper = document.createElement('div'); const infoWrapper = document.createElement('div'); wrapper.classList.add('fcx-setting'); infoWrapper.classList.add('fcx-setting__info'); wrapper.appendChild(infoWrapper); const label = document.createElement('label'); label.textContent = key .replace(/([A-Z])/g, ' $1') .replace(/^./, str => str.toUpperCase()); label.setAttribute('for', key); infoWrapper.appendChild(label); if (config.info) { const info = document.createElement('p'); info.innerHTML = config.info; infoWrapper.appendChild(info); } const savedValue = this.settings[subSettings][key]?.value ?? config.value; let input; if (config.type === 'checkbox') { input = document.createElement('input'); input.type = 'checkbox'; input.checked = savedValue; } else if (config.type === 'textarea') { input = document.createElement('textarea'); input.value = savedValue; } else if (config.type === 'input') { input = document.createElement('input'); input.type = config.inputType || 'text'; input.value = savedValue; } else if (config.type === 'select' && config.options) { input = document.createElement('select'); const options = config.options.split(','); options.forEach(opt => { const option = document.createElement('option'); option.value = opt; option.textContent = opt; if (opt === savedValue) option.selected = true; input.appendChild(option); }); } if (input) { input.id = key; input.name = key; input.dataset.section = subSettings; wrapper.appendChild(input); this.inputs.push(input); this.settings[subSettings][key] = { value: input.type === 'checkbox' ? input.checked : input.value }; } parent.appendChild(wrapper); }); } open() { this.classList.add('open'); } close() { this.classList.remove('open'); } toggle() { this.classList.toggle('open'); } } window.customElements.define('fullchan-x-settings', fullChanXSettings); class ToggleButton extends HTMLElement { constructor() { super(); const data = this.dataset; this.onclick = () => { const target = data.target ? document.querySelector(data.target) : this; const value = data.value || 'active'; !!data.set ? target.dataset[data.set] = value : target.classList.toggle(value); } } } window.customElements.define('toggle-button', ToggleButton); // Create fullchan-x gallery const fcxg = document.createElement('fullchan-x-gallery'); fcxg.innerHTML = `