hsengu / Ragial Navi Button

// ==UserScript==
// @name         Ragial Navi Button
// @namespace    http://tampermonkey.net/
// @version      0.14
// @description  Adds a "Get navi" button to ragial shop pages that copies the RO navi command with proper syntax to clipboard
// @author       Hok Uy
// @match        http://ragial.org/shop/*
// @include      http://ragial.org/shop/*
// @grant        none
// @downloadURL  https://openuserjs.org/install/hsengu/Ragial_Navi_Button.user.js
// @updateURL    https://openuserjs.org/install/hsengu/Ragial_Navi_Button.user.js
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    var output = "";
    var input = "";
    var coord = document.getElementsByClassName("c_txt")[0].textContent.replace(", ", '/');
    var map_id = document.getElementById("map_zone").style.backgroundImage;
    if(map_id.search("prontera") != -1) {
        map_id = "prontera";
        makeButton();
    }
    else if(map_id.search("payon") != -1) {
        map_id = "payon";
        makeButton();
    }
    else {
        coord = coord.replace("2F ", '');
        map_id = "moc_paraup";
        makeButton();
    }
    
    function makeButton() {
        output = "/navi " + map_id + " " + coord;
        input = document.createElement("input");

        if(output.search("\\?\\?\\?") != -1)
            return;
        input.type = "button";
        input.style.backgroundColor = "#008CBA";
        input.style.color = "white";
        input.style.border = "none";
        input.style.borderRadius = "4px";
        input.style.textAlign = "center";
        input.style.padding = "5px 10px";
        input.style.fontSize = "13px";
        input.style.float = "right";
        input.value = "Get navi";
        input.onclick = copyToClipboard;
        var child = document.getElementById("map_zone");
        var parent = child.parentNode;
        parent.insertAdjacentHTML('beforeend', '<br>');
        parent.insertAdjacentElement('beforeend', input);
        parent.insertAdjacentHTML('afterend', '<br>');
    }
    
    function copyToClipboard() {
        var text = document.createElement("input");
        document.body.appendChild(text);
        text.setAttribute("id", "text_id");
        document.getElementById("text_id").value = output;
        text.select();
        document.execCommand("copy");
        document.body.removeChild(text);
        input.style.backgroundColor = "#4CAF50";
        input.value = "Copied!";
    }
})();