Greasy Fork 还支持 简体中文。

One Bazaar

try to take over the world!

  1. // ==UserScript==
  2. // @name One Bazaar
  3. // @namespace onebazaar.zero.nao
  4. // @version 1.2
  5. // @description try to take over the world!
  6. // @author nao
  7. // @match https://www.torn.com/bazaar.php*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=torn.com
  9. // @grant none
  10. // ==/UserScript==
  11. let percentage = 5;
  12. let done = [];
  13. let itemsdata = [];
  14. let bought=[];
  15. function update() {
  16. let content = ``;
  17. for (let val of itemsdata){
  18. if (!bought.includes(val[2])){
  19. content += (val[1]);
  20. }
  21. }
  22. $("#itemList").html(content);
  23. $(".itembuynao").off("click");
  24. $(".itembuynao").on("click", async function () {
  25. let iid = $(this).attr("id");
  26. let iitemid = $(this).attr("itemid");
  27. let iamount = $(this).attr("amount");
  28. let iuid = $(this).attr("userid");
  29. let ip = $(this).attr("price");
  30. await buy(iuid, iid, iitemid, iamount, ip);
  31. });
  32. }
  33. function insert() {
  34. let cont = `<div id="displayContainer" style="
  35. display: grid;
  36. grid-template-columns: 40% auto;
  37. background: rgb(51 177 227);
  38. width: 40vw;
  39. height: 150px;
  40. color: yellow;
  41. border-radius: 10px;
  42. padding: 10px;
  43. z-index:10;
  44. ::-webkit-scrollbar {
  45. width: 5px;
  46. }
  47. ::-webkit-scrollbar-track {
  48. border-radius: 8px;
  49. background-color: #e7e7e7;
  50. border: 1px solid #cacaca;
  51. }
  52. ::-webkit-scrollbar-thumb {
  53. border-radius: 8px;
  54. background-color: #3b9ab7;
  55. }
  56. ">
  57. <div id="itemList" style=" overflow-y: scroll;">
  58. </div>
  59. <div id = "actionsHistory" style=" overflow-y: scroll;">
  60. <p class="actionsElement">{result}</p>
  61. </div>`;
  62. if ($("div[class^='topSection']").length == 0) {
  63. setTimeout(insert, 300);
  64. return;
  65. }
  66. if ($("#displayContainer").length == 0) {
  67. $(".content-wrapper").prepend(cont);
  68. }
  69. }
  70. async function buy(userid, id, itemid, amount, price) {
  71. await $.post(`https://www.torn.com/bazaar.php?sid=bazaarData&step=buyItem&rfcv=${getRFC()}`, {
  72. userID: userid,
  73. id: id,
  74. itemid: itemid,
  75. amount: amount,
  76. price: price,
  77. beforeval: price * amount
  78. }, function (response) {
  79. console.log(response);
  80. response = JSON.parse(response);
  81. console.log(response);
  82. addResult(response.text, response.success ? "green" : "red");
  83. if (response.success && response.text.includes("bought")){
  84. $(`#${id}`).remove();
  85. bought.push(id);
  86. }
  87. })
  88. }
  89. function addResult(resultMsg, rescol) {
  90. let curtime = $(".server-date-time").html().split("-")[0];
  91. let resmsg = `<p style="color: ${rescol}">${curtime} ${resultMsg}</p>`;
  92. $("#actionsHistory").prepend(resmsg);
  93. }
  94. function getRFC() {
  95. var rfc = $.cookie('rfc_v');
  96. if (!rfc) {
  97. var cookies = document.cookie.split('; ');
  98. for (var i in cookies) {
  99. var cookie = cookies[i].split('=');
  100. if (cookie[0] == 'rfc_v') {
  101. return cookie[1];
  102. }
  103. }
  104. }
  105. return rfc;
  106. }
  107. if (window.location.href.includes("userId")){
  108. insert();
  109. const { fetch: origFetch } = window;
  110. window.fetch = async (...args) => {
  111. console.log("onebazaar called with args:", args);
  112. const response = await origFetch(...args);
  113. /* work with the cloned response in a separate promise
  114. chain -- could use the same chain with `await`. */
  115. if (response.url && response.url.includes('/bazaar.php?sid=bazaarData&step=getBazaarItems')) {
  116. let clonedResponse = response.clone();
  117. let clonedJ = await clonedResponse.json();
  118. let uid = clonedJ.ID;
  119. // console.log("userid" + uid);
  120. for (let item of clonedJ.list) {
  121. let id = item.bazaarID;
  122. let itemid = item.ID;
  123. let amount = item.amount;
  124. let price = item.price;
  125. let mv = item.averageprice;
  126. let isBlockedForBuying = item.isBlockedForBuying;
  127. let name = item.name;
  128. // console.log(item);
  129. if (!isBlockedForBuying && parseInt(price) <= (100 - percentage) / 100 * mv && !done.includes(id)) {
  130. let con = `<button style="color:white; margin:5px; height:40px" class="itembuynao torn-btn" userid=${uid} id=${id} itemid=${itemid} amount=${amount} price=${price}>${name} $${(price * amount).toLocaleString()}</button>`;
  131. while ($("#itemList").length == 0) {
  132. console.log("itemlist");
  133. }
  134. done.push(id);
  135. itemsdata.push([parseInt(mv - price), con, id]);
  136. }
  137. }
  138. }
  139. itemsdata = itemsdata.sort(function (a, b) {
  140. return b[0] - a[0];
  141. });
  142. update();
  143. return response;
  144. };
  145. }