jklm.fun embed

Embed of any desired game/site with cycling toggle buttons for jklm.fun

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         jklm.fun embed
// @namespace    http://tampermonkey.net
// @version      1.0
// @description  Embed of any desired game/site with cycling toggle buttons for jklm.fun
// @author       HA_LOL_XD
// @match        *://*.jklm.fun/*
// @run-at       document-end
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 1. DUAL-WINDOW PROTECTION: Only run on the main JKLM page, not inside its game iframes
    if (window.self !== window.top) return;

    // 2. GAME LIST
    const games = [
        { name: '🐠 Orb Farm', url: 'https://orb.farm' },
        { name: '⏳ Sandspiel', url: 'https://sandspiel.club' }
    ];
    let currentGameIndex = 0;

    function init() {
        // Prevent duplicate buttons if they already exist
        if (document.getElementById('jklm-embed-controls')) return;

        // 3. UI Container (Top-Right)
        const container = document.createElement('div');
        container.id = 'jklm-embed-controls';
        container.style.cssText = 'position:fixed; top:10px; right:10px; z-index:10001; display:flex; gap:5px;';

        // 4. Cycle/Toggle Button
        const btn = document.createElement('button');
        btn.innerHTML = games[currentGameIndex].name;
        btn.style.cssText = 'padding:8px 12px; cursor:pointer; background:#222; color:#fff; border:1px solid #444; border-radius:5px; font-weight:bold; font-family:sans-serif; min-width:110px;';

        // 5. Reload Button
        const reloadBtn = document.createElement('button');
        reloadBtn.innerHTML = '🔄';
        reloadBtn.style.cssText = 'padding:8px 10px; cursor:pointer; background:#333; color:#fff; border:1px solid #444; border-radius:5px;';

        // 6. Close Button
        const closeBtn = document.createElement('button');
        closeBtn.innerHTML = '✖';
        closeBtn.style.cssText = 'padding:8px 12px; cursor:pointer; background:#800; color:#fff; border:1px solid #444; border-radius:5px; font-weight:bold;';

        // 7. Game Wrapper (Bottom-Left)
        const wrapper = document.createElement('div');
        wrapper.id = 'jklm-game-wrapper';
        wrapper.style.cssText = 'position:fixed; bottom:20px; left:20px; width:400px; height:500px; z-index:10000; display:none; background:#000; border:2px solid #555; border-radius:8px; overflow:hidden; box-shadow: 0 10px 25px rgba(0,0,0,0.8);';

        const iframe = document.createElement('iframe');
        iframe.src = games[currentGameIndex].url;
        iframe.style.cssText = 'width:800px; height:1000px; border:none; transform:scale(0.5); transform-origin:0 0;';

        // LOGIC: Toggle and Cycle
        btn.onclick = () => {
            if (wrapper.style.display === 'none') {
                wrapper.style.display = 'block';
            } else {
                currentGameIndex = (currentGameIndex + 1) % games.length;
                iframe.src = games[currentGameIndex].url;
                btn.innerHTML = games[currentGameIndex].name;
            }
            btn.style.background = '#007bff';
        };

        // LOGIC: Close
        closeBtn.onclick = () => {
            wrapper.style.display = 'none';
            btn.style.background = '#222';
        };

        // LOGIC: Reload current iframe
        reloadBtn.onclick = () => {
            iframe.src = games[currentGameIndex].url;
            reloadBtn.style.background = '#28a745';
            setTimeout(() => reloadBtn.style.background = '#333', 500);
        };

        // Append everything
        wrapper.appendChild(iframe);
        container.appendChild(btn);
        container.appendChild(reloadBtn);
        container.appendChild(closeBtn);
        document.body.appendChild(container);
        document.body.appendChild(wrapper);
    }

    // Run on load
    init();

    // Watch for JKLM page transitions to re-inject buttons if they get wiped
    const observer = new MutationObserver(() => {
        if (!document.getElementById('jklm-embed-controls')) {
            init();
        }
    });
    observer.observe(document.body, { childList: true, subtree: true });
})();