LovElizabeth / Create or Delete All VPS by One Click

// ==UserScript==
// @name         Create or Delete All VPS by One Click
// @namespace    http://tampermonkey.net/
// @version      2.5
// @description  Create Ping or detele all VPS by One Click.
// @author       Princess Jasmine
// @match        https://my.vultr.com/*
// @grant        none
// @copyright 2020, LovElizabeth (https://openuserjs.org/users/LovElizabeth)
// @license MIT
// ==/UserScript==


(function() {
    var store_selected = window.localStorage

    if(window.location.pathname == "/"){
        moudle_1()
    }else if ((window.location.pathname == "/deploy/") && (store_selected.getItem("flag") == "true")){
        moudle_2()
    }

    $('#del_servers').click(function(){
        moudle_3()
        window.location.reload()
    })

    if (store_selected.getItem("to_del") != ""){
        moudle_4()
    }
    
    $('#copy_ip_addrs').click(function(){
        moudle_5()
    })
    
    function moudle_1() {



        var city_e = ["City","Tokyo","Seoul","Singapore","Amsterdam","Paris","Frankfurt","London","Atlanta","New York (NJ)","Chicago","Dallas","Los Angeles","Miami","Seattle","Silicon Valley","Toronto","Sydney"]
        var os_e = ["OS","CentOS","Debian","Fedora","FreeBSD","OpenBSD","Ubuntu","Windows"]
        var plan_e = ["Price","$5","$10","$20","$40","$80","$160"]

        $('div.block1290.block1290deploy').append('<input id="del_servers" style="color: #ff0000" type="button" value="Delete All"></button>')
        $('div.block1290.block1290deploy').append('<input id="new_server" type="button" value="New VPS"></button>')
        $('div.block1290.block1290deploy').append('<input id="copy_ip_addrs" type="button" value="Ping.bat"></button>')
        $('div.block1290.block1290deploy').append('<select id="select_city"></select>')
        $('div.block1290.block1290deploy').append('<select id="select_os"></select>')
        $('div.block1290.block1290deploy').append('<select id="select_plan"></select>')

        store_selected.setItem("flag","false")
        for (let i =0;i<city_e.length;i++){
            $('#select_city').append(new Option(city_e[i],city_e[i]))
        }

        for (let i =0;i<os_e.length;i++){
            $('#select_os').append(new Option(os_e[i],os_e[i]))
        }

        for (let i =0;i<plan_e.length;i++){
            $('#select_plan').append(new Option(plan_e[i],i))
        }

        $('#select_city').change(function(){
            store_selected.setItem("city",$('#select_city option:selected').text())
        })

        $('#select_os').change(function(){
            store_selected.setItem("os",$('#select_os option:selected').text())
        })

        $('#select_plan').change(function(){
            store_selected.setItem("plan",$('#select_plan option:selected').val())
        })

        $('#new_server').click(function () {
            store_selected.setItem("flag","true")
            $('span.fonticon_plus').click()
        })


    }



    function moudle_2(){



        store_selected.setItem("flag","false")
        var city = $('span.deploy_checkbox_line1.deploy_checkbox_line1_soldout span')
        for (var i = 0;i < city.length;i++){
            if (city[i].textContent == store_selected.getItem("city")){
                city[i].click()
                break
            }
        }

        var os = $('#servertype_x64_section label.servertype_label')
        for (var j = 0;j < os.length;j++){
            if ($(os[j]).attr('data-osname') == store_selected.getItem("os")){
                os[j].click()
                $(os[j]).children().eq(4).children().eq(0).click()
                break
            }
        }

        var temp_plan = "VPSPLANID20"
        var plan = temp_plan+store_selected.getItem("plan").toString()

        $("#server_size_container label[for='"+plan+"']").click()
        $('label[for="vm_ipv6_requested"]').click()
        $('#confirmordersubmit').click()}

    function moudle_3() {


        var to_del_id_list = Array()
        var to_del_id = $('div.responsivetable.responsivetable_subs div.table-row input[type="checkbox"]')

        for (var i =0;i<to_del_id.length;i++){
            if($(to_del_id[i]).is(':checked')){
                to_del_id_list.push($(to_del_id[i]).attr('value').split('_')[1])
            }

        }

        store_selected.setItem("to_del",to_del_id_list)

    }

    function moudle_4() {
        let to_del_list = new Array()
        to_del_list = store_selected.getItem("to_del").split(',')

        let temp_id = to_del_list.pop()
        $('#massaction'+temp_id).parent().parent().find('button.fonticonmore.responsivetable_subs_btn').click()
        $('#DROPDOWNPOPUP a[aria-label="Destroy Server"][dropdown-subid='+temp_id+']').click()
        $('div.dropdown-confirmation.dropdown-confirmation-red div.checkbox input[type="checkbox"]').click()
        store_selected.setItem("to_del",to_del_list)
        $('div.dropdown-actions a[name="destroy"]').click()




    }
    function moudle_5(){
        var addrs = $('div.block1290 div.table-row span.copy-content')
        var content = "@echo off \n"

        for(var i=0;i<addrs.length;i++){
              content += "C:\\WINDOWS\\system32\\ping.exe "+$(addrs[i]).attr("data-clicktoclipboard")+"\n"
        }
        content = content + "pause"

        let element = document.createElement('a')
            element.setAttribute('href', 'data:bat/plain;charset=utf-8,' + encodeURIComponent(content))
            element.setAttribute('download', "Ping.bat")
            element.style.display = 'none'
            element.click()

    }

})();