IMVU Product Minimal Revision Viewer

Adds a simple CFL revision dropdown next to "Try it On" for IMVU products, showing only real revisions.

目前為 2025-04-13 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         IMVU Product Minimal Revision Viewer
// @namespace    http://tampermonkey.net/
// @version      1.1.1
// @description  Adds a simple CFL revision dropdown next to "Try it On" for IMVU products, showing only real revisions.
// @author       heapsofjoy
// @match        *://*.imvu.com/shop/product.php?products_id=*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // Step 1: Get product ID
    const urlParams = new URLSearchParams(window.location.search);
    const productId = urlParams.get('products_id');
    if (!productId) return;

    const baseUrl = `https://userimages-akm.imvu.com/productdata/${productId}`;

    // Step 2: Locate "Try it On" button
    const tryOnLink = document.getElementById('try-on-link');
    if (!tryOnLink) return;

    // Step 3: Create a wrapper span to contain both buttons
    const wrapper = document.createElement('span');
    wrapper.style.display = 'inline-flex';
    wrapper.style.alignItems = 'center';
    wrapper.style.gap = '6px';
    tryOnLink.parentNode.insertBefore(wrapper, tryOnLink);

    // Step 4: Create CFL button
    const toggleButton = document.createElement('button');
    toggleButton.textContent = 'contents.json';
    toggleButton.style.background = '#eee';
    toggleButton.style.border = '1px solid #ccc';
    toggleButton.style.borderRadius = '3px';
    toggleButton.style.padding = '2px 6px';
    toggleButton.style.fontSize = '12px';
    toggleButton.style.cursor = 'pointer';

    // Step 5: Create dropdown container
    const dropdown = document.createElement('div');
    dropdown.style.display = 'none';
    dropdown.style.position = 'absolute';
    dropdown.style.background = '#fff';
    dropdown.style.border = '1px solid #ccc';
    dropdown.style.padding = '6px';
    dropdown.style.borderRadius = '4px';
    dropdown.style.boxShadow = '0 2px 5px rgba(0,0,0,0.1)';
    dropdown.style.maxHeight = '180px';
    dropdown.style.overflowY = 'auto';
    dropdown.style.fontSize = '12px';
    dropdown.style.zIndex = '999';

    // Step 6: Toggle visibility
    toggleButton.addEventListener('click', () => {
        dropdown.style.display = dropdown.style.display === 'block' ? 'none' : 'block';
    });

    // Step 7: Function to handle revision checking
    function checkRevision(revision, misses = 0, maxMisses = 10) {
        const url = `${baseUrl}/${revision}/_contents.json`;
        fetch(url, { method: 'HEAD' })
            .then((response) => {
                if (response.ok) {
                    const link = document.createElement('a');
                    link.href = url;
                    link.textContent = `Revision ${revision}`;
                    link.target = '_blank';
                    link.style.display = 'block';
                    link.style.color = '#007bff';
                    link.style.textDecoration = 'none';
                    link.style.margin = '3px 0';
                    dropdown.appendChild(link);
                    checkRevision(revision + 1, 0, maxMisses); // Reset misses on success
                } else {
                    if (misses < maxMisses) {
                        checkRevision(revision + 1, misses + 1, maxMisses); // Allow up to maxMisses failures
                    }
                }
            })
            .catch(() => {
                if (misses < maxMisses) {
                    checkRevision(revision + 1, misses + 1, maxMisses); // Handle fetch failure
                }
            });
    }

    // Start checking from revision 1
    checkRevision(1, 0, 10);

    // Step 8: Optional fallback if no revisions found
    setTimeout(() => {
        if (dropdown.children.length === 0) {
            const msg = document.createElement('div');
            msg.textContent = 'No revisions found.';
            msg.style.color = '#666';
            dropdown.appendChild(msg);
        }
    }, 2000);

    // Step 9: Insert everything
    const container = document.createElement('div');
    container.style.position = 'relative';
    container.appendChild(toggleButton);
    container.appendChild(dropdown);

    wrapper.appendChild(container);
    wrapper.appendChild(tryOnLink);
})();