Skip to content

Instantly share code, notes, and snippets.

@jmerle
Last active July 9, 2016 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmerle/60bd611423bc518426c3a8cf690a33e5 to your computer and use it in GitHub Desktop.
Save jmerle/60bd611423bc518426c3a8cf690a33e5 to your computer and use it in GitHub Desktop.
HETools Helper Script
/* Variables */
var gritterLoaded = false;
var footer = document.getElementsByClassName("pagination alternate")[0];
var liTags = footer.getElementsByTagName("li");
var numberOfPages = parseInt(liTags[liTags.length - 2].innerText);
var currentWebsiteURL = window.location.protocol + "//" + window.location.hostname;
var savedDatabase = document.getElementById("list").innerHTML;
/* Functions */
function gritterNotify(opts) {
if (!gritterLoaded) {
$('<link rel="stylesheet" type="text/css" href="css/jquery.gritter.css">').appendTo("head");
$.getScript("js/jquery.gritter.min.js", function() {
$.gritter.add({
title: opts.title,
text: opts.text,
image: opts.img,
sticky: opts.sticky
});
});
gritterLoaded = true;
return;
}
$.gritter.add({
title: opts.title,
text: opts.text,
image: opts.img,
sticky: opts.sticky
});
}
function updateAPIKey(key) {
localStorage.setItem("he-tools-apikey", key);
gritterNotify({
title: "HETools Helper",
text: "Updated API key!",
image: "",
sticky: false
});
if (localStorage.getItem("he-tools-apikey") != null) {
$("#apikey").val(localStorage.getItem("he-tools-apikey")).change();
}
}
function syncHDB() {
$("#syncTabLink").off("click");
loadAll();
setTimeout(function() {
var apikey = localStorage.getItem("he-tools-apikey");
var ipList = [];
var re = /(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)/g;
var str = savedDatabase;
var m;
while ((m = re.exec(str)) !== null) {
if (m.index === re.lastIndex) {
re.lastIndex++;
}
if ($.inArray(m[0], ipList) == -1) {
ipList.push(m[0]);
}
}
$.post("https://jaspervanmerle.com/hetools/api/get-add-ips-requests-left.php", {"api-key": apikey}).done(function(data) {
var output = JSON.parse(data);
if (output["success"]) {
var requestsLeft = output.payload.requestsLeft;
var amount = ipList.length;
if (requestsLeft - amount >= 0) {
var finalList = [];
while (ipList.length > 0) {
finalList.push(ipList.splice(0, 1000));
}
jQuery.each(finalList, function(index, element) {
var ipArr = JSON.stringify(element);
$.post("https://jaspervanmerle.com/hetools/api/add-ips.php", {"api-key": apikey, "ips": ipArr});
});
gritterNotify({
title: "HETools Helper",
text: "Your HDB has been synced with HETools!",
image: "",
sticky: false
});
} else {
gritterNotify({
title: "HETools Helper",
text: "You attempted to sync your HDB too much. Please try again in an hour.",
image: "",
sticky: false
});
}
$("#syncTabLink").remove();
} else {
if (output["errorCode"] == 201) {
gritterNotify({
title: "HETools Helper",
text: "The API key you gave is not valid. Please update it in the HDH Plugin Settings on the Hacked Database page to sync your HDB again.",
image: "",
sticky: false
});
}
$("#syncTabLink").click(function() {
syncHDB();
});
}
});
}, (numberOfPages * 0.1) * 1000);
}
function openSettings() {
$("#hetools-helper-settings-modal").modal("toggle");
$(".modal-backdrop").removeClass("modal-backdrop");
}
function injectTab() {
var settingsTab = $('<li class="link"><a id="settingsTabLink"><span class="icon-tab he16-clan_adm"></span><span class="hide-phone">HETools Helper Settings</span></a></li>');
settingsTab.appendTo($("ul.nav.nav-tabs"));
$("#settingsTabLink").click(function() {
openSettings();
});
var syncTab = $('<li class="link"><a id="syncTabLink"><span class="icon-tab he16-world"></span><span class="hide-phone">Sync HDB with HETools</span></a></li>');
if (localStorage.getItem("he-tools-apikey") != null) {
syncTab.appendTo($("ul.nav.nav-tabs"));
$("#syncTabLink").click(function() {
syncHDB();
});
}
var modal = $('<div id="hetools-helper-settings-modal" class="modal fade" tabindex="-1" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> <h4 class="modal-title">HETools Helper Settings</h4> </div><div class="modal-body"> <p>To sync you Hacked Database with <a href="https://jaspervanmerle.com/hetools/" target="_blank">HETools</a>, you will need to fill in the API Key from HETools which you can find <a href="https://jaspervanmerle.com/hetools/api-settings" target="_blank">here</a>. <div class="controls"> <input type="text" id="apikey" style="box-sizing: border-box; width: 100%; height: 34px; margin-bottom: 0px;" placeholder="Put your HE Tools API Key here"> </div><button class="btn btn-primary btn-block" onclick="updateAPIKey($(\'#apikey\').val())">Update HE Tools API Key</button> </div><div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div></div></div></div>');
modal.appendTo(document.body);
if (localStorage.getItem("he-tools-apikey") != null) {
$("#apikey").val(localStorage.getItem("he-tools-apikey")).change();
}
}
function HTMLParser(string) {
var div = document.createElement("div");
div.innerHTML = string;
return div;
}
function loadAll() {
var waitTime = 0;
cycledPages = 1;
while (numberOfPages != cycledPages) {
cycledPages += 1;
retrieveAll(cycledPages);
}
}
function retrieveAll(page) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var xmlResponse = xmlhttp.responseText;
HTML = HTMLParser(xmlResponse);
var list = HTML.getElementsByTagName("ul")[3].innerHTML;
savedDatabase += list;
}
};
url = currentWebsiteURL + "/list?page=" + page;
xmlhttp.open("GET", url, true);
xmlhttp.withCredentials = true;
xmlhttp.send(null);
}
// Initializing and running
$(document).ready(function() {
times = 0;
pagesDict = {};
numberOfPages = parseInt(liTags[liTags.length - 2].innerText);
for (var index in liTags) {
if (liTags[index].className == "active") {
cycledPages = parseInt(liTags[index].innerText);
break;
}
}
if (document.getElementsByClassName("link active")[0].innerText.match("IP List|Lista de IPs") || document.getElementsByClassName("link active")[0].innerText.match("IP List|Lista de IPs")) {
injectTab();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment