GeoGuessr Tips - Floating TOC

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

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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);

})();