// ==UserScript==
// @name The West - Market best bids
// @namespace TomRobert
// @author Esperiano (updated by Tom Robert)
// @description Market utility for highlighting the best bids!
// @include https://*.the-west.*/game.php*
// @version 0.4.7
// @grant none
// @downloadURL none
// ==/UserScript==
TWMBB_inject = function () {
var twmbbjs = document.createElement('script');
twmbbjs.setAttribute('type', 'text/javascript');
twmbbjs.setAttribute('language', 'javascript');
twmbbjs.innerHTML = '(' + (function () {
twmbb = {
version: '0.4.7',
name: 'Market best bids',
author: 'Esperiano (updated by Tom Robert)',
minGame: '2.05',
maxGame: Game.version.toString(),
website: 'https://greasyfork.org/scripts/7391',
updateUrl: 'https://raw.githack.com/TomRobert/tw/master/sU.js',
updateAd: 'http://adf.ly/1dbA7K',
items: JSON.parse(localStorage.getItem('mbb_items')) || {
},
};
var fmfb = function (l) {
return 'https://forum.the-west.' + l + '/index.php?conversations/add&to=Tom Robert';
},
twmbbApi = TheWestApi.register('TWMBB', twmbb.name, twmbb.minGame, twmbb.maxGame, twmbb.author, twmbb.website);
twmbbApi.setGui('
Market utility for highlighting the best bids.
Green – Bid is lower than the purchase price.
Black - Bid is equal to the purchase price.
Blue – Bid is between 100% and 200% of the purchase price.
Red – Bid is more than 200% of the purchase price.
The sold item will always have the color of the lowest bid!
' + twmbb.name + ' v' + twmbb.version +
'
Contact:
');
if (!twmbb.items.oldData) {
twmbb.items.oldData = 'done';
for (var k in localStorage)
if (typeof k === 'string' && k.indexOf('mbb_') === 0)
localStorage.removeItem(k);
}
var count = 0;
for (var i = 0; i <= 185205; i++) {
var item = ItemManager.getByBaseId(i);
if (item !== undefined && twmbb.items[i] === undefined) {
var name = item.name;
if (item.type == 'recipe') {
name = name.split(':');
if (name.length == 2)
name = name[1];
}
twmbb.items[i] = [
name,
item.price
];
count++;
}
}
if (count > 0) localStorage.setItem('mbb_items', JSON.stringify(twmbb.items));
$('#windows').on('DOMNodeInserted', function (e) {
var element = e.target;
if ($(element).is('div[class*=\'marketOffersData\']')) {
var price_original,
bid_original = $(element).children() [4], //Auktionspreis
purchase_original = $(element).children() [3], //Sofortkauf
qty = $(element).children() [2].textContent, //Anzahl Verkaufsstücke
name_original = $(element).children() [1]; //Name des Verkaufsgegenstandes
for (var key in twmbb.items) {
if (twmbb.items[key][0] === name_original.textContent) {
price_original = twmbb.items[key][1];
}
}
if (purchase_original.textContent) {
var purchase = purchase_original.textContent.replace(/\$|\.|\,/g, ''); //'$', Punkte und Kommas entfernen
var price_purchase = purchase / qty;
if (price_purchase < price_original) {
purchase_original.style.color = 'green';
if (!bid_original.textContent) {
name_original.style.color = 'green';
}
}
if ((price_purchase > price_original) && (price_purchase <= price_original * 2)) {
purchase_original.style.color = 'blue';
if (!bid_original.textContent) {
name_original.style.color = 'blue';
}
}
if (price_purchase > price_original * 2) {
purchase_original.style.color = 'red';
if (!bid_original.textContent) {
name_original.style.color = 'red';
}
}
}
if (bid_original.textContent) {
var bid = bid_original.textContent.replace(/\$|\.|\,/g, ''); //'$', Punkte und Kommas entfernen
var price_bid = bid / qty;
if (price_bid < price_original) {
bid_original.style.color = 'green';
name_original.style.color = 'green';
}
if ((price_bid > price_original) && (price_bid <= price_original * 2)) {
bid_original.style.color = 'blue';
name_original.style.color = 'blue';
}
if (price_bid > price_original * 2) {
name_original.style.color = 'red';
bid_original.style.color = 'red';
}
}
}
});
twmbb.Updater = function () {
$.getScript(twmbb.updateUrl, function () {
if (scriptUpdate.twmbb > twmbb.version) {
var updateMessage = new west.gui.Dialog('Update: ' + twmbb.name, 'A new version of the script is available
v' + scriptUpdate.twmbb + ':
' + scriptUpdate.twmbbNew + '', west.gui.Dialog.SYS_WARNING).addButton('Update', function () {
updateMessage.hide();
window.open(twmbb.updateAd);
}).addButton('Update [NoAds]', function () {
updateMessage.hide();
location.href = twmbb.website + '/code.user.js';
}).addButton('cancel').show();
}
});
};
setTimeout(twmbb.Updater, 2000);
}).toString() + ')();';
document.body.appendChild(twmbbjs);
};
if (location.href.indexOf('.the-west.') != - 1 && location.href.indexOf('game.php') != - 1)
setTimeout(TWMBB_inject, 2500, false);