curseforge show all file versions

show all the versions listed for a file, rather than hiding them behind a +2 thing you need to hover over

当前为 2022-08-10 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         curseforge show all file versions
// @namespace    https://github.com/adrianmgg
// @version      1.0.0
// @description  show all the versions listed for a file, rather than hiding them behind a +2 thing you need to hover over
// @author       amgg
// @match        https://www.curseforge.com/minecraft/mc-mods/*/files
// @match        https://www.curseforge.com/minecraft/mc-mods/*/files/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=curseforge.com
// @grant        unsafeWindow
// @run-at       document-start
// @license      MIT
// @compatible   chrome
// @compatible   firefox
// ==/UserScript==


// the list of other versions is present in the initial html (in the title of an
// element), but they remove that after they set up the +2 hover thing, so if we
// want to get that info we need to get to those elements right away before they
// have a chance to modify it.


// replaces the .extra-versions placeholder with a list versions, changes styles
// to make it display nicely
function modifyExtraVersionsElem(elem) {
    // in case we happen to get the same one multiple times
    if(elem.parentElement === null) return;
    for(const version of elem.title.split('<br />')) {
        const div = document.createElement('div');
        div.classList.add('mr-2');
        div.textContent = version;
        elem.parentElement.appendChild(div);
    }
    elem.parentElement.classList.add('flex-col');
    elem.parentElement.parentElement.style.paddingTop = '2.5px';
    elem.parentElement.parentElement.style.paddingBottom = '2.5px';
    elem.parentElement.parentElement.style.verticalAlign = 'bottom';
    elem.parentElement.removeChild(elem);
}

const observer = new MutationObserver((mutations, observer) => {
    for(const mutation of mutations) {
        if(mutation.type === 'childList') {
            for(const node of mutation.addedNodes) {
                if(node.nodeType === Node.ELEMENT_NODE) {
                    if(node.classList.contains('extra-versions')) {
                        modifyExtraVersionsElem(node);
                    }
                    node.querySelectorAll('.extra-versions').forEach(modifyExtraVersionsElem);
                }
            }
        }
    }
});

observer.observe(document, { childList: true, subtree: true });

// once the page is finished loading we don't need to be watching for new nodes,
// so we disconnect the observer
window.addEventListener('DOMContentLoaded', (e) => {
    observer.disconnect();
});