Geocaching Puzzle Helper

Show hidden user added elements on Geocaching Mystery Cache Page

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

// ==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/*
// @version 1.4
// @namespace    https://gf.qytechs.cn/en/scripts/464566-geocaching-puzzle-helper
// @homepage     https://gf.qytechs.cn/en/scripts/464566-geocaching-puzzle-helper
// @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);
            }

            item = getAllLinks(elem);
            if (item.length > 0) {
                addButton(elem,"Links",item.join('\r\n'),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 getAllLinks(rootElem) {
        var comments = [];
        // Fourth argument, which is actually obsolete according to the DOM4 standard, is required in IE 11
        var iterator = rootElem.getElementsByTagName('a');
        for (var i = 0; i < iterator.length; i++) {
            var elem = iterator[i];
            comments.push(elem.href);
        }

        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++) {
            var elem = All[i];
            if (elem.getAttribute(attribute1) !== null) {
                if (elem.getAttribute(attribute1).toLowerCase() == value1) { comments.push( elem.innerHTML); }
                if (elem.getAttribute(attribute1).toLowerCase() == value2) { comments.push( elem.innerHTML); }
            }
            if (elem.style.color == value3) { comments.push( elem.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(this.title);
        return false;
    }



})();

QingJ © 2025

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