Facebook
From Sexy Rhinoceros, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 661
  1. window.setInterval(addDataAboutItemPriceMinusSteamCommissionOnPageOfItemWhichIsSoldViaMonopolySystem, 200);
  2.  
  3.  
  4. function roundToTwo(num)
  5. {
  6. return +(Math.round(num + "e+2") + "e-2");
  7.  
  8. }
  9.  
  10. function getStringWithOneCharChanged(str, index, chr)
  11. {
  12. if (index > str.length - 1)
  13. {
  14. return str;
  15.  
  16. }
  17.  
  18. return str.substr(0, index) + chr + str.substr(index + 1);
  19.  
  20. }
  21. function addInfoAboutMoneyWithSteamCommissionIntoCellWithItemPrice(tableTdElemWithPriceValue)
  22. {
  23. if (tableTdElemWithPriceValue == null)
  24. {
  25. return;
  26.  
  27. }
  28.  
  29. if
  30. (
  31. (tableTdElemWithPriceValue.innerHTML.indexOf('<br') < 0) &&
  32. (tableTdElemWithPriceValue.innerHTML.indexOf('(') < 0) &&
  33. (tableTdElemWithPriceValue.innerHTML.indexOf('|') < 0)
  34. )
  35. {
  36.  
  37. var strPrice = tableTdElemWithPriceValue.innerHTML;
  38.  
  39.  
  40. var strPriceWithoutCurrencySymbols = '';
  41.  
  42. var strRegEx = /([0-9]+[0-9., ]*)/g;
  43. matches = strPrice.match(strRegEx);
  44.  
  45. var strPrefixBeforeSubstringWithPriceInInitialTdValue = '';
  46. var strSuffixAfterSubstringWithPriceInInitialTdValue = '';
  47.  
  48. if (matches.length >= 1)
  49. {
  50. strPriceWithoutCurrencySymbols = matches[0];
  51.  
  52. strPrefixBeforeSubstringWithPriceInInitialTdValue = strPrice.substring(0, strPrice.indexOf(strPriceWithoutCurrencySymbols));
  53.  
  54. strSuffixAfterSubstringWithPriceInInitialTdValue = strPrice.substring(strPrice.indexOf(strPriceWithoutCurrencySymbols) + strPriceWithoutCurrencySymbols.length, strPrice.length);
  55.  
  56. if (strPriceWithoutCurrencySymbols[strPriceWithoutCurrencySymbols.length - 1] == ' ')
  57. {
  58. strSuffixAfterSubstringWithPriceInInitialTdValue = ' ' + strSuffixAfterSubstringWithPriceInInitialTdValue;
  59.  
  60. }
  61.  
  62. }
  63. else
  64. {
  65. return;
  66.  
  67. }
  68.  
  69.  
  70. var positionOfLastCommaOrPointInStringWithPrice = -1;
  71.  
  72. for (var i = 0; i < strPriceWithoutCurrencySymbols.length; i++)
  73. {
  74. if
  75. (
  76. (strPriceWithoutCurrencySymbols[i] == '.') ||
  77. (strPriceWithoutCurrencySymbols[i] == ',')
  78. )
  79. {
  80. positionOfLastCommaOrPointInStringWithPrice = i;
  81.  
  82. }
  83.  
  84. }
  85. if (positionOfLastCommaOrPointInStringWithPrice >= 0)
  86. {
  87. for (var i = 0; i < strPriceWithoutCurrencySymbols.length; i++)
  88. {
  89. if
  90. (
  91. (i != positionOfLastCommaOrPointInStringWithPrice) &&
  92. (
  93. (strPriceWithoutCurrencySymbols[i] == ',') ||
  94. (strPriceWithoutCurrencySymbols[i] == '.')
  95. )
  96. )
  97. {
  98. strPriceWithoutCurrencySymbols = getStringWithOneCharChanged(strPriceWithoutCurrencySymbols, i, ' ');
  99.  
  100. }
  101.  
  102. }
  103.  
  104. }
  105.  
  106.  
  107. strPriceWithoutCurrencySymbols = strPriceWithoutCurrencySymbols.replace(' ', '');
  108.  
  109. var strPriceWithoutCurrencySymbolsAndWithDecimalPointNotComma = strPriceWithoutCurrencySymbols.replace(',', '.');
  110.  
  111. var priceMinusSteamCommission = parseFloat(strPriceWithoutCurrencySymbolsAndWithDecimalPointNotComma) * 0.87;
  112.  
  113. priceMinusSteamCommission = roundToTwo(priceMinusSteamCommission);
  114.  
  115. var strPriceMinusSteamCommission = priceMinusSteamCommission.toLocaleString();
  116.  
  117.  
  118. var positionOfDecimalPointOrComma = Math.max(strPriceMinusSteamCommission.indexOf('.'), strPriceMinusSteamCommission.indexOf(','));
  119.  
  120. if (positionOfDecimalPointOrComma > 0)
  121. {
  122. if (positionOfDecimalPointOrComma == strPriceMinusSteamCommission.length - 2)
  123. {
  124. strPriceMinusSteamCommission = strPriceMinusSteamCommission + '0';
  125.  
  126. }
  127.  
  128. }
  129. else
  130. {
  131. strPriceMinusSteamCommission = strPriceMinusSteamCommission + ".00";
  132.  
  133. }
  134. strPriceMinusSteamCommission = strPrefixBeforeSubstringWithPriceInInitialTdValue + strPriceMinusSteamCommission + strSuffixAfterSubstringWithPriceInInitialTdValue;
  135.  
  136. strPriceMinusSteamCommission = strPriceMinusSteamCommission.trim();
  137.  
  138. tableTdElemWithPriceValue.innerHTML = tableTdElemWithPriceValue.innerHTML + '<span style="color:#48aaf9"> | ' + strPriceMinusSteamCommission + ' </span>';
  139.  
  140. }
  141.  
  142. }
  143. function addDataAboutItemPriceMinusSteamCommissionOnPageOfItemWhichIsSoldViaMonopolySystem()
  144. {
  145. var xPathRes = document.evaluate("//div[@id='market_commodity_forsale_table']//table[contains(@class, 'market_commodity_orders_table')]//tr[position()>1]/td[1]", document, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
  146.  
  147.  
  148. var arrayOfActualTdElements = [];
  149. var actualTdElem = xPathRes.iterateNext();
  150. var counter = 0;
  151.  
  152. while (actualTdElem)
  153. {
  154.  
  155. arrayOfActualTdElements[counter++] = actualTdElem;
  156. actualTdElem = xPathRes.iterateNext();
  157.  
  158. }
  159.         for (var i = 0; i < arrayOfActualTdElements.length - 1; i++)
  160. {
  161. addInfoAboutMoneyWithSteamCommissionIntoCellWithItemPrice(arrayOfActualTdElements[i]);
  162.  
  163. }
  164.  
  165. }

Replies to Untitled rss

Title Name Language When
Re: Untitled Small Duck text 3 Years ago.