Last active
February 2, 2020 18:50
-
-
Save XianThi/7b6e149b2cabde6be3e5283f99d1d39d to your computer and use it in GitHub Desktop.
e-Sim mass equipment merger script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var j, htmlstr; | |
var prompttext = ""; | |
var itemarray = Array(); | |
var intervalId = 1; | |
var itemquality = 1; | |
var selecteditemtype = null; | |
var itemtype = 1; | |
function post(e, t, n = "post") { | |
const o = document.createElement("form"); | |
o.method = n, o.action = e; | |
for (const e in t) | |
if (t.hasOwnProperty(e)) { | |
const n = document.createElement("input"); | |
n.type = "hidden", n.name = e, n.value = t[e], o.appendChild(n) | |
} | |
document.body.appendChild(o), o.submit() | |
} | |
function gethtml(callback) { | |
httpRequest = new XMLHttpRequest(); | |
httpRequest.onreadystatechange = function() { | |
if (httpRequest.readyState === 4) { // request is done | |
if (httpRequest.status === 200) { // successfully | |
callback(httpRequest.responseText); // we're calling our method | |
} | |
} | |
}; | |
httpRequest.open('GET', [location.protocol, '//', location.host].join('') + "/storage.html?storageType=EQUIPMENT"); | |
httpRequest.send(); | |
} | |
gethtml(function(result) { | |
htmlstr = result; | |
}); | |
function postdata(t) { | |
var http = new XMLHttpRequest(); | |
var url = 'equipmentAction.html'; | |
var params = ''; | |
if (Object.values(t).length > 3) { | |
for (const e in t) { | |
if (t.hasOwnProperty(e)) { | |
params += '&' + e + '=' + t[e]; | |
} | |
} | |
params = params.substring(1); | |
console.log(params); | |
http.open('POST', url, true); | |
//Send the proper header information along with the request | |
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | |
http.onreadystatechange = function() { //Call a function when the state changes. | |
if (http.readyState == 4 && http.status == 200) { | |
console.log("data posting"); | |
} | |
} | |
http.send(params); | |
console.log("data posted"); | |
} else { | |
console.log("need 3 items"); | |
clearInterval(intervalId); | |
j, htmlstr; | |
prompttext = ""; | |
itemarray = Array(); | |
intervalId = 1; | |
itemquality = 1; | |
selecteditemtype = null; | |
itemtype = 1; | |
main(); | |
intervalId = setInterval(funcint, 3000); | |
} | |
} | |
function newmergex(t, e, html) { | |
var i = {}, | |
n = [], | |
o = "<b>Q" + t + " " + e + "</b>"; | |
var obj = $($.parseHTML(html)); | |
$.each(obj.find(".equipmentDescription b"), function(t, e) { | |
if (o.toString() == e.outerHTML) { | |
var i = obj.find(".equipmentDescription").get(t).getAttribute("id").substring(4); | |
n.push(i) | |
} | |
}), n.slice(0, 3).forEach(function(t) { | |
i["itemId[" + t + "]"] = t | |
}), i.action = "MERGE", postdata(i) | |
} | |
function main() { | |
for (j = 0; j < $(".equipmentName p b").length; j++) { | |
itemarray[j] = $(".equipmentName p b")[j].innerText; | |
itemarray[6] = "Silah eklentisi"; | |
prompttext += j + " : " + $(".equipmentName p b")[j].innerText + "\n"; | |
} | |
do { | |
if (itemtype === null) { | |
break; | |
} | |
itemtype = parseInt(window.prompt("Choose one type (0,1,2,3,4,5,6,7,8) : \n" + prompttext, ""), 10); | |
} while (isNaN(itemtype) || itemtype > 10 || itemtype < 0); | |
selecteditemtype = itemarray[itemtype]; | |
do { | |
if (itemquality === null) { | |
break; | |
} | |
itemquality = parseInt(window.prompt("Choose item quality (1,2,3,4,5) :", ""), 10); | |
} while (isNaN(itemquality) || itemquality > 5 || itemquality < 1); | |
} | |
function funcint() { | |
gethtml(function(result) { | |
htmlstr = result; | |
}); | |
newmergex(itemquality, selecteditemtype, htmlstr) | |
} | |
main(); | |
intervalId = setInterval(funcint, 3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment