Greasy Fork

The West - Market best bids

Market utility for highlighting the best bids.

目前为 2015-02-11 提交的版本。查看 最新版本

// ==UserScript==
// @name The West - Market best bids
// @namespace TomRobert
// @author Esperiano (modified by Darius II; updated by Tom Robert)
// @description Market utility for highlighting the best bids.
// @include http*://*.the-west.*/game.php*
// @version 0.4.1
// @grant none
// ==/UserScript==
TWMBB_inject = function () {
  if (document.getElementById('TWMBB_js'))
  {
    alert('Script already installed');
    return;
  }
  var twmbbjs = document.createElement('script');
  twmbbjs.setAttribute('type', 'text/javascript');
  twmbbjs.setAttribute('language', 'javascript');
  twmbbjs.setAttribute('id', 'TWMBB_js');
  twmbbjs.innerHTML = '(' + (function () {
    version = '0.4.1',
    name = 'Market best bids',
    author = 'Esperiano (modified by Darius II; updated by Tom Robert)',
    id_scripts = '7391';
    min_gameversion = '2.05';
    max_gameversion = Game.version.toString();
    website = 'https://greasyfork.org/scripts/7391',
    TheWestApi.register('TWMBB', name, min_gameversion, max_gameversion, author, website).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>');
    var windows = document.getElementById('windows');
    windows.addEventListener('DOMNodeInserted', OnNodeInserted, false);
    function OnNodeInserted(event) {
      if ($('#market_buytable').length) {
        var purchase = document.getElementById('market_buytable');
        var items = purchase.getElementsByClassName('row');
        var nrow = items.length - 1;
        //Anzahl Verkaufsstücke
        var qty = items[nrow].getElementsByClassName('mpb_stack'); //Download Mengen
        qty = qty[0].getElementsByTagName('div');
        qty = qty[0].textContent;
        //Sofortkauf
        if (items[nrow].getElementsByClassName('mpb_buynow')) {
          var purchase_original = items[nrow].getElementsByClassName('mpb_buynow'); //Sofortkauf Download
          purchase = purchase_original[0].textContent;
          purchase = purchase.replace('$', '');
          purchase = purchase.replace(/\./g, '');
          purchase = purchase.replace(/\,/g, ''); //'$', Punkte und Kommas entfernen
        }
        if (purchase) {
          var price_purchase = purchase / qty;
        }
        //Auktionspreis

        var bid_original = items[nrow].getElementsByClassName('mpb_bid'); //Auktionspreis Download
        bid = bid_original[0].textContent;
        bid = bid.replace('$', '');
        bid = bid.replace(/\./g, '');
        bid = bid.replace(/\,/g, '');
        if (bid) {
          var price_bid = bid / qty;
        }
        var name_original = items[nrow].getElementsByClassName('mpb_article'); //Name des Verkaufsgegenstandes
        var item;
        var price_original;
        name = name_original[0].textContent;
        for (i = 0; i < 185206; i++) {
          if (ItemManager.get(i)) {
            item = ItemManager.get(i).name;
            if (item == name) {
              price_original = ItemManager.get(i).price;
            }
          }
        }
        if (price_purchase < price_original) {
          purchase_original[0].style.color = 'green';
          if (!bid) {
            name_original[0].style.color = 'green';
          }
        }
        if ((price_purchase > price_original) && (price_purchase <= price_original * 2)) {
          purchase_original[0].style.color = 'blue';
          if (!bid) {
            name_original[0].style.color = 'blue';
          }
        }
        if (price_purchase > price_original * 2) {
          purchase_original[0].style.color = 'red';
          if (!bid) {
            name_original[0].style.color = 'red';
          }
        }
        if (price_bid < price_original) {
          bid_original[0].style.color = 'green';
          name_original[0].style.color = 'green';
        }
        if ((price_bid > price_original) && (price_bid <= price_original * 2)) {
          bid_original[0].style.color = 'blue';
          name_original[0].style.color = 'blue';
        }
        if (price_bid > price_original * 2) {
          name_original[0].style.color = 'red';
          bid_original[0].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);