Geocaching Puzzle Helper

Show hidden user added elements on Geocaching Mystery Cache Page

当前为 2023-04-21 提交的版本,查看 最新版本

// ==UserScript==
// @name Geocaching Puzzle Helper
// @description Show hidden user added elements on Geocaching Mystery Cache Page
// @match http://www.geocaching.com/geocache/*
// @match https://www.geocaching.com/geocache/*
// @match http://geocaching.com/geocache/*
// @match https://geocaching.com/geocache/*
// @grant GM_addStyle
// @grant GM_getValue
// @grant GM_setValue
// @version 1.0
// @require
// @namespace    http://gf.qytechs.cn/
// @homepageURL
// @supportURL
// @license         MIT
// ==/UserScript==

(function() {
    'use strict';

    scanElemForStuff(document.getElementById("ctl00_ContentBody_ShortDescription"));
    scanElemForStuff(document.getElementById("ctl00_ContentBody_LongDescription"));
    
    function addButton(parent, text, title, onclick) {
        const button = document.createElement('button');
        button.innerHTML = text;
        button.onclick = onclick;
        button.title = title;
        button.addEventListener('contextmenu', (e) => e.preventDefault());

        parent.insertBefore(button, parent.firstChild);
        return button;
    }

    function scanElemForStuff(elem) {
        var item;
        if (elem != null) {

            item = getExtraText(elem);
            if (item.length > 0) {
                addButton(elem,"Extra",item.flat(),onClickHandler);
            }

            item = getWhiteText(elem);
            if (item.length > 0) {
                addButton(elem,"White Text",item.flat(),onClickHandler);
            }

            item = getAllComments(elem);
            if (item.length > 0) {
                addButton(elem,"Comments",item.flat(),onClickHandler);
            }


        }
    }

    function getAllComments(rootElem) {
        var comments = [];
        // Fourth argument, which is actually obsolete according to the DOM4 standard, is required in IE 11
        var iterator = document.createNodeIterator(rootElem, NodeFilter.SHOW_COMMENT, null, false);
        var curNode;
        while (curNode = iterator.nextNode()) {
            comments.push(curNode.nodeValue);
        }
        return comments;
    }

    function getWhiteText(rootElem) {
        var comments = [];
        var attribute1 = "color";
        var value1 = "#ffffff";
        var value2 = "white";
        var value3= "rgb(255, 255, 255)"
        var element_type = element_type || "*";
        var All = rootElem.getElementsByTagName(element_type);
        for (var i = 0; i < All.length; i++) {
            if (All[i].getAttribute(attribute1) == value1) { comments.push( All[i].innerHTML); }
            if (All[i].getAttribute(attribute1) == value2) { comments.push( All[i].innerHTML); }
            if (All[i].style.color == value3) { comments.push( All[i].innerHTML); }
        }

        return comments;
    }

        function getExtraText(rootElem) {
        var comments = [];
        var attributes = ["alt", "name", "id"];

        var element_type = element_type || "*";
        var All = rootElem.getElementsByTagName(element_type);
        for (var i = 0; i < All.length; i++) {
            for (var j = 0; j < All.length; j++) {
                if (All[i].getAttribute(attributes[j]) != null) { comments.push( All[i].getAttribute(attributes[j])); }
            }
        }

        return comments;
    }

    function onClickHandler(e) {
        alert(e.elem.title);
    }



})();



QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址