Greasy Fork

The West - Market best bids

Market utility for highlighting the best bids!

目前为 2015-03-27 提交的版本。查看 最新版本

// ==UserScript==
// @name The West - Market best bids
// @namespace TomRobert
// @author Esperiano (updated by Tom Robert)
// @description Market utility for highlighting the best bids!
// @include http*://*.the-west.*/game.php*
// @version 0.4.3
// @grant none
// ==/UserScript==
TWMBB_inject = function () {
  var twmbbjs = document.createElement('script');
  twmbbjs.setAttribute('type', 'text/javascript');
  twmbbjs.setAttribute('language', 'javascript');
  twmbbjs.innerHTML = '(' + (function () {
    version = '0.4.3',
    name = 'Market best bids',
    author = 'Esperiano (updated by Tom Robert)',
    min_gameversion = '2.05',
    max_gameversion = Game.version.toString(),
    website = 'https://greasyfork.org/scripts/7391';
    var twmbbApi = TheWestApi.register('TWMBB', name, min_gameversion, max_gameversion, author, website);
    twmbbApi.setGui('<br>Market utility for highlighting the best bids.<br><br><span style="color:green;">Green</span> – Bid is lower than the purchase price.<br>Black -  Bid is equal to the purchase price.<br><span style="color:blue;">Blue</span> – Bid is between 100% and 200% of the purchase price.<br><span style="color:red;">Red</span> – Bid is more than 200% of the purchase price.<br><br>The sold item will always have the color of the lowest bid!<br><br><i>' + name + ' v' + version
    + '</i><br><br><br><b>Contact:</b><ul style="margin-left:15px;"><li>Send a message to <a target=\'_blanck\' href="http://om.the-west.de/west/de/player/?ref=west_invite_linkrl&player_id=647936&world_id=13&hash=7dda">Tom Robert on German world Arizona</a></li>'
    + '<li>Message me on one of these The West Forum:<br>/ <a target=\'_blanck\' href="http://forum.the-west.de/private.php?do=newpm&u=24502">deutsches Forum</a> / '
    + '<a target=\'_blanck\' href="http://forum.the-west.net/private.php?do=newpm&u=37219">English forum</a> / <a target=\'_blanck\' href="http://forum.the-west.pl/private.php?do=newpm&u=32083">forum polski</a> / '
    + '<a target=\'_blanck\' href="http://forum.the-west.es/private.php?do=newpm&u=13770">foro español</a> /<br>/ <a target=\'_blanck\' href="http://forum.the-west.ru/private.php?do=newpm&u=27430">России форум</a> / '
    + '<a target=\'_blanck\' href="http://forum.the-west.fr/private.php?do=newpm&u=17783">forum français</a> / <a target=\'_blanck\' href="http://forum.the-west.it/private.php?do=newpm&u=14287">forum italiano</a> / '
    + '<a target=\'_blanck\' href="http://forum.beta.the-west.net/private.php?do=newpm&u=4072">beta forum</a> /<br>I will get an e-mail when you sent me the message <img src="../images/chat/emoticons/smile.png"></li></ul>');
    var items_original = [
    ];
    for (var i = 0; i < 999999; i++) {
      var item = ItemManager.get(i);
      if (item !== undefined && localStorage.getItem('Id_' + i) !== undefined) {
        items_original[i] = [
          item.name,
          item.price
        ];
        localStorage.setItem('Id_' + i, items_original[i]);
      }
    }
    $('#windows').on('DOMNodeInserted', function (e) {
      var element = e.target;
      if ($(element).is('div[class*=\'marketOffersData\']')) {
        var price_original;
        var bid_original = $(element).children() [4]; //Auktionspreis
        var purchase_original = $(element).children() [3]; //Sofortkauf
        var qty = $(element).children() [2].textContent; //Anzahl Verkaufsstücke
        var name_original = $(element).children() [1]; //Name des Verkaufsgegenstandes
        var purchase = purchase_original.textContent.replace('$', '');
        purchase = purchase.replace(/\./g, '');
        purchase = purchase.replace(/\,/g, ''); //'$', Punkte und Kommas entfernen
        if (purchase) {
          var price_purchase = purchase / qty;
        }
        var bid = bid_original.textContent.replace('$', '');
        bid = bid.replace(/\./g, '');
        bid = bid.replace(/\,/g, ''); //'$', Punkte und Kommas entfernen
        if (bid) {
          var price_bid = bid / qty;
        }
        for (var key in localStorage) {
          if (typeof key === 'string' && key.indexOf('Id_') === 0) {
            var index = key.split('_') [1];
            if (localStorage.getItem('Id_' + index).split(',') [0] === name_original.textContent) {
              price_original = localStorage.getItem('Id_' + index).split(',') [1];
            }
          }
        }
        if (price_purchase < price_original) {
          purchase_original.style.color = 'green';
          if (!bid) {
            name_original.style.color = 'green';
          }
        }
        if ((price_purchase > price_original) && (price_purchase <= price_original * 2)) {
          purchase_original.style.color = 'blue';
          if (!bid) {
            name_original.style.color = 'blue';
          }
        }
        if (price_purchase > price_original * 2) {
          purchase_original.style.color = 'red';
          if (!bid) {
            name_original.style.color = 'red';
          }
        }
        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';
        }
      }
    });
  }).toString() + ')();';
  document.body.appendChild(twmbbjs);
};
if (location.href.indexOf('.the-west.') != - 1 && location.href.indexOf('game.php') != - 1)
setTimeout(TWMBB_inject, 2500, false);