-
-
Save Vusys/9558c24b909fa843e057938de56f528f to your computer and use it in GitHub Desktop.
This file contains 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
// ==UserScript== | |
// @name WH Tweaks | |
// @namespace vusys | |
// @version 0.4 | |
// @description try to take over the world! | |
// @author Vusys | |
// @match https://warehouse.renmx.com/v2 | |
// @require https://code.jquery.com/jquery-3.2.1.min.js | |
// @require https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js | |
// @require https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js | |
// @require https://cdn.datatables.net/1.10.16/js/dataTables.bootstrap.min.js | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
$('style').remove(); | |
$('body').html(''); | |
$('title').html('Warehouse'); | |
$('body').append($('<link>').attr({ | |
'href': 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css', | |
'rel': 'stylesheet' | |
})); | |
$('body').append($('<link>').attr({ | |
'href': 'https://cdn.datatables.net/1.10.16/css/dataTables.bootstrap.min.css', | |
'rel': 'stylesheet' | |
})); | |
var csrf = ''; | |
function renderTabView(data) { | |
var catgories = new Set(); | |
var categoryData = {}; | |
catgories.add('Everything'); | |
$.each(data, function (index, value) { | |
if (index === 'CSRFToken') { | |
csrf = value; | |
return true; | |
} | |
catgories.add(value.Category); | |
}); | |
var ret = $('<div>'); | |
var nav = $('<ul>').addClass('nav nav-tabs').attr('role', 'tablist'); | |
var tabpanels = $('<div>').addClass('tab-content'); | |
catgories.forEach(function (value) { | |
var tab = $('<li>').attr('role', 'presentation'); | |
var link = $('<a>').attr({ | |
//'class' : value == 'Everything' ? 'active' : '', | |
'href': '#' + value.toString().replace(' ', ''), | |
'aria-controls': value, | |
'role': 'tab', | |
'data-toggle': 'tab' | |
}).text(value); | |
tab.append(link); | |
nav.append(tab); | |
var panel = $('<div>').addClass('tab-pane').attr({ | |
//'class' : value == 'Everything' ? 'active' : '', | |
'role': 'tabpanel', | |
'id': value.toString().replace(' ', '') | |
}).html(renderSubTable(data, value)); | |
tabpanels.append(panel); | |
}); | |
ret.append(nav); | |
ret.append(tabpanels); | |
return ret; | |
} | |
function getStackSize(itemName) { | |
size = null; | |
$.each([' Door', ' Axe', ' Hoe', ' Pickaxe', ' Shovel', ' Sword'], function (i, n) { | |
if (itemName.toString().indexOf(n) > 0) { | |
size = 1; | |
} | |
}); | |
if (size === 1) { | |
return size; | |
} | |
stackSizeMap = { | |
'Sign': 16, | |
'Ender Pearl': 16, | |
'Flint and Steel': 1, | |
}; | |
image = stackSizeMap[itemName] == undefined ? 64 : stackSizeMap[itemName]; | |
return image; | |
} | |
function renderSubTable(data, category) { | |
ret = $('<table>').addClass('table table-striped').append( | |
$('<thead>').html('<tr><th></th><th>Item</th><th>Quantity</th><th>Get</th></tr>') | |
); | |
body = $('<tbody>'); | |
$.each(data, function (index, value) { | |
if (value.Category != category && category != 'Everything') { | |
return true; | |
} | |
if (index === 'CSRFToken') { | |
return true; | |
} | |
var row = $('<tr>'); | |
row.append($('<td>').html('<img style="width:32px;height:32px;" src="https://c.pixita.com/' + value.image + '"/>')); | |
row.append($('<td>').html(index)); | |
row.append($('<td>').html(value['Quantity Stored'])); | |
row.append($('<td>').html('<button type="button" class="btn btn-default btn-get-item" data-item-name="' + index + '" data-size="1i">1 item</button> <button type="button" class="btn btn-default btn-get-item" data-item-name="' + index + '" data-size="1s">1 stack</button>')); | |
body.append(row); | |
}); | |
ret.append(body); | |
return ret; | |
} | |
$(document).on("click", '.btn-get-item', function (event) { | |
btn = $(this); | |
btn.attr('disabled', true); | |
switch ($(this).data('size')) { | |
case '1i': | |
size = 1; | |
break; | |
case '1s': | |
size = getStackSize(btn.data('item-name')); | |
break; | |
} | |
$.get("/submit.php?csrf=" + csrf + "&item=" + btn.data('item-name') + "&quantity=" + size, function (data) { | |
btn.attr('disabled', false); | |
}); | |
}); | |
$.getJSON("/json.php", function (data) { | |
ret = renderTabView(data); | |
$('body').append($('<div>').addClass('container').html(ret)); | |
$('table').DataTable({ | |
"paging": false | |
}); | |
$('ul a:first').tab('show'); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment