PixelBoii

Untitled

Nov 9th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.56 KB | None | 0 0
  1. // Cookie Settings
  2. document.cookie = 'same-site-cookie=foo; SameSite=Lax';
  3. document.cookie = 'cross-site-cookie=bar; SameSite=None; Secure';
  4.  
  5. chrome.storage.sync.get(
  6. function(options) {
  7. // Skapa knappen
  8. var btnReplace = document.createElement("BUTTON");
  9. btnReplace.innerHTML = "Insert Steam Market Price";
  10. btnReplace.onclick = function(){replacePrices()};
  11. btnReplace.style.cssText = 'background: linear-gradient(to right, #e9b10b 50%, #24252f 50%); background-size: 200% 100%; background-position: right bottom; color: #e9b10b; padding: 1em; margin-left: 1.875rem; border-radius: 3px; font-size: .8125rem; font-weight: 700; border: 1px solid #e9b10b; width: 12.5rem; height: 2.9rem;';
  12.  
  13. // Placera knappen
  14. setTimeout(placeButton, 3500);
  15.  
  16. function placeButton() {
  17. document.getElementsByClassName("price-range-compact")[0].appendChild(btnReplace);
  18. }
  19.  
  20. function resetButton() {
  21. btnReplace.style.cssText = 'background: linear-gradient(to right, #e9b10b 50%, #24252f 50%); background-size: 200% 100%; background-position: 100%; transition: all 3s ease-out; color: #e9b10b; padding: 1em; margin-left: 1.875rem; border-radius: 3px; font-size: .8125rem; font-weight: 700; border: 1px solid #e9b10b; width: 12.5rem; height: 2.9rem;';
  22. }
  23.  
  24. // Udda nummer är wear
  25. // Jämna nummer är skinet
  26. // 0 är ett annat element
  27. let bundleNumber = 0;
  28. let bothNumber = 0;
  29. let wearNumber = 1;
  30. let skinNumber = 2;
  31. let alreadyExecuted = false;
  32. let priceNumber = 0;
  33. let bundleActive = false;
  34. var skins = [];
  35. let itemNumber = 0;
  36. let sortBy;
  37.  
  38. // Prisrutan
  39. let prices;
  40.  
  41. function replacePrices() {
  42. // Prisrutan
  43. prices = document.getElementsByClassName('item__price');
  44.  
  45. sortBy = document.getElementsByClassName('v-popover')[2].textContent.trim();
  46.  
  47. // Ändra Knappen
  48. btnReplace.innerHTML = "Reload Steam Market Prices";
  49. btnReplace.onclick = function(){reloadPrices()};
  50.  
  51. for (i = 0; i < 5; i++) {
  52. secondaryButton = document.getElementsByClassName('button-secondary')[i];
  53.  
  54. if (options.priceSource === 'lootfarm') {
  55. if (secondaryButton.classList.contains('button-secondary--gold')) {
  56. if (i === 0 || i === 1) {
  57. foundPriceSource = options.priceSource + 'csgo';
  58. }
  59.  
  60. if (i === 2) {
  61. foundPriceSource = options.priceSource + 'dota2';
  62. }
  63.  
  64. if (i === 3) {
  65. foundPriceSource = options.priceSource + 'rust';
  66. }
  67.  
  68. if (i === 4) {
  69. foundPriceSource = options.priceSource + 'h1z1';
  70. }
  71. }
  72. } else {
  73. foundPriceSource = options.priceSource;
  74. }
  75. }
  76.  
  77. chrome.runtime.sendMessage(
  78. {priceSource: 'getItems'},
  79. marketName => {
  80. skins = marketName;
  81. });
  82. itemNumber += 1;
  83.  
  84. getPrices();
  85. }
  86.  
  87. function getPrices() {
  88. alreadyExecuted = false;
  89. for (elt of prices) {
  90. chrome.runtime.sendMessage(
  91. {priceSource: foundPriceSource, itemURL: skins[priceNumber], id: priceNumber},
  92. price => {
  93. // Create Div
  94. var valueIcon = document.createElement('div');
  95. valueIcon.innerHTML = '<div style="background: url(https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Steam_icon_logo.svg/512px-Steam_icon_logo.png) 50%/100% auto no-repeat; height: 1rem; width: 1rem; margin-left: 0.7rem; margin-right: 0.35rem;"></div>'
  96. valueIcon.id = 'valueIcon';
  97.  
  98. // Create Span
  99. var value = document.createElement('span');
  100. value.textContent = price.value;
  101. value.style.cssText = 'font-size: .8125rem; color: silver; font-weight: 700;';
  102. value.id = 'valueSpan';
  103.  
  104. // Append Those
  105. document.getElementsByClassName('item__price')[price.id].appendChild(valueIcon);
  106. document.getElementsByClassName('item__price')[price.id].appendChild(value);
  107.  
  108. // Loading Bar
  109. var idAmount = document.querySelectorAll('[id$=valueIcon]');
  110. loaded = idAmount.length / skins.length * 100;
  111. loaded = 100 - loaded;
  112. btnReplace.style.cssText = 'background: linear-gradient(to right, #e9b10b 50%, #24252f 50%); background-size: 200% 100%; background-position:' + loaded + '%; transition: all .5s ease-out; color: #fff; text-shadow: 2px 2px 4px #000000; padding: 1em; margin-left: 1.875rem; border-radius: 3px; font-size: .8125rem; font-weight: 700; border: 1px solid #e9b10b; width: 12.5rem; height: 2.9rem;';
  113.  
  114. window.setInterval(function(){ // Set interval for checking
  115. if (alreadyExecuted == false) {
  116. if(loaded != 0){
  117. resetButton();
  118. alreadyExecuted = true;
  119. }
  120. }
  121. }, 25000);
  122.  
  123. });
  124.  
  125. priceNumber = priceNumber + 1;
  126. }
  127. }
  128.  
  129. function reloadPrices() {
  130. for (elt of prices) {
  131. if (document.getElementById('valueIcon')) {
  132. var removeValueIcon = document.getElementById('valueIcon');
  133. removeValueIcon.remove();
  134. }
  135.  
  136. if (document.getElementById('valueSpan')) {
  137. var removeValue = document.getElementById('valueSpan');
  138. removeValue.remove();
  139. }
  140. }
  141.  
  142. bundleNumber = 0;
  143. bothNumber = 0;
  144. wearNumber = 1;
  145. skinNumber = 2;
  146. priceNumber = 0;
  147. skins = [];
  148. prices = '';
  149. replacePrices();
  150. }
  151. });
Advertisement
Add Comment
Please, Sign In to add comment