GeoGuessr Tips - Floating TOC

Floats the table of contents on the left side based on a specific XPath

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         GeoGuessr Tips - Floating TOC
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Floats the table of contents on the left side based on a specific XPath
// @author       Gemini
// @match        https://somerandomstuff1.wordpress.com/2019/02/08/geoguessr-the-top-tips-tricks-and-techniques/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to get an element by XPath
    function getElementByXpath(path) {
        return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    }

    // specific XPath provided by user
    const targetXpath = "/html/body/div[1]/div/div[1]/div/article/div/ul[1]";

    function floatTOC() {
        const tocElement = getElementByXpath(targetXpath);

        if (tocElement) {
            // Apply CSS styles to make it float on the left
            tocElement.style.position = "fixed";
            tocElement.style.left = "10px";
            tocElement.style.top = "100px"; // Distance from top of screen
            tocElement.style.width = "250px"; // Fixed width to prevent it from being too wide
            tocElement.style.maxHeight = "80vh"; // Max height to fit screen
            tocElement.style.overflowY = "auto"; // Scrollbar if the list is too long
            tocElement.style.backgroundColor = "#ffffff"; // White background to read text clearly
            tocElement.style.zIndex = "9999"; // Ensure it sits on top of other content
            tocElement.style.padding = "15px";
            tocElement.style.border = "2px solid #333";
            tocElement.style.borderRadius = "8px";
            tocElement.style.boxShadow = "0 4px 6px rgba(0,0,0,0.1)";
            tocElement.style.fontSize = "14px";
            tocElement.style.listStyleType = "none"; // Optional: removes bullet points for cleaner look

            console.log("Tampermonkey: TOC found and moved.");
        } else {
            console.log("Tampermonkey: TOC element not found at XPath: " + targetXpath);
        }
    }

    // Run the function once the page structure is ready
    window.addEventListener('load', floatTOC);

    // Fallback: Try after 2 seconds in case of dynamic loading
    setTimeout(floatTOC, 2000);

})();