Modify Greenies' Name

You can add prefix to the name of your green munzees

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Modify Greenies' Name
// @namespace    http://tampermonkey.net/
// @version      0.1
// @author       CzPeet
// @match        https://www.munzee.com/m/*/*/admin/?prefix=*
// @match        https://www.munzee.com/m/*/deploys/0/type/0
// @icon         https://www.google.com/s2/favicons?domain=munzee.com
// @description  You can add prefix to the name of your green munzees
// @grant        none
// ==/UserScript==

if (document.location.href.indexOf("deploys")>0)
{
    //Get string container
    var container = document.getElementById("search-text").parentElement;
    var greenPreFix = localStorage.getItem("munzeeGreeniesPrefix");
    var myLabel = document.createElement("Label");
    myLabel.innerText = "Prefix: ";
    myLabel.id = "prefLabel";
    myLabel.setAttribute("style","margin-left: 30px; margin-right: 5px");
    container.appendChild(myLabel);
    var myText = document.createElement("Input");
    myText.value = (greenPreFix != null) ? greenPreFix : "";
    myText.id = "prefText";
    myText.addEventListener('keyup', changePrefixText);
    container.appendChild(myText);

    changePrefixText();
}
else if (document.location.href.indexOf("?prefix")>0)
{
    var prefix = new URLSearchParams(window.location.search).get("prefix");
    var oldTitle = $("#friendly_name").val();

    if (oldTitle.indexOf(prefix) != 0)
    {
        $("#friendly_name").val(prefix+" "+oldTitle);

        var buttons = document.getElementsByTagName('button');
        for (var b = 0;b<buttons.length; b++)
        {
            if ($(buttons[b]).text() == "Update")
            {
                $(buttons[b]).click();
            }
        }
    }
}

function changePrefixText()
{
    var prefValue = $("#prefText").val();
    if (prefValue != null && prefValue != "")
    {
        localStorage.setItem("munzeeGreeniesPrefix", prefValue);
        //Modify Links in sections
        modifyLinks(prefValue);
    }
    else
    {
        localStorage.removeItem("munzeeGreeniesPrefix");
    }
}

function modifyLinks(prefix)
{
    var sections = document.getElementsByTagName('section');
    for (var s=0; s<sections.length; s++)
    {
        var links = sections[s].getElementsByTagName('a');
        for (var a=0; a<links.length; a++)
        {
            links[a].setAttribute("href", links[a].getAttribute("href")+"admin/?prefix="+prefix);
        }
    }
}