diff options
| author | 2022-11-20 13:36:37 +0000 | |
|---|---|---|
| committer | 2022-11-20 13:36:37 +0000 | |
| commit | 7b49952105a808b866625b4fee5a2b4edecfeb6e (patch) | |
| tree | d29cb4ab470e0d23f64e6b478b2e68ba6eea94aa /pydis_site/static/js/content | |
| parent | Include users with no messages in response, and simplify response format (diff) | |
| parent | Merge pull request #798 from python-discord/fix-manage-py-no-args (diff) | |
Merge branch 'main' into messages-in-past-n-days-endpoint
Diffstat (limited to 'pydis_site/static/js/content')
| -rw-r--r-- | pydis_site/static/js/content/listing.js | 41 | 
1 files changed, 41 insertions, 0 deletions
| diff --git a/pydis_site/static/js/content/listing.js b/pydis_site/static/js/content/listing.js new file mode 100644 index 00000000..4b722632 --- /dev/null +++ b/pydis_site/static/js/content/listing.js @@ -0,0 +1,41 @@ +/** + * Trim a tag listing to only show a few lines of content. + */ +function trimTag() { +    const containers = document.getElementsByClassName("tag-container"); +    for (const container of containers) { +        if (container.textContent.startsWith("Contains the following tags:")) { +            // Tag group, no need to trim +            continue; +        } + +        // Remove every element after the first two paragraphs +        while (container.children.length > 2) { +            container.removeChild(container.lastChild); +        } + +        // Trim down the elements if they are too long +        const containerLength = container.textContent.length; +        if (containerLength > 300) { +            if (containerLength - container.firstChild.textContent.length > 300) { +                // The first element alone takes up more than 300 characters +                container.removeChild(container.lastChild); +            } + +            let last = container.lastChild.lastChild; +            while (container.textContent.length > 300 && container.lastChild.childNodes.length > 0) { +                last = container.lastChild.lastChild; +                last.remove(); +            } + +            if (container.textContent.length > 300 && (last instanceof HTMLElement && last.tagName !== "CODE")) { +                // Add back the final element (up to a period if possible) +                const stop = last.textContent.indexOf("."); +                last.textContent = last.textContent.slice(0, stop > 0 ? stop + 1: null); +                container.lastChild.appendChild(last); +            } +        } +    } +} + +trimTag(); | 
