[GC | Library] Organize SW Results

Blocked users can be synced but do not actually change anything in the SW results yet.

Este script no debería instalarse directamente. Es una biblioteca que utilizan otros scripts mediante la meta-directiva de inclusión // @require https://update.greatest.deepsurf.us/scripts/488092/1332297/%5BGC%20%7C%20Library%5D%20Organize%20SW%20Results.js

  1. // ==UserScript==
  2. // @name [GC | Library] Organize SW Results
  3. // @namespace https://greatest.deepsurf.us/en/users/1225524-kaitlin
  4. // @match https://www.grundos.cafe/block/
  5. // @match https://www.grundos.cafe/market/wizard/
  6. // @match https://www.grundos.cafe/guilds/guild/*/members/
  7. // @require https://cdn.jsdelivr.net/npm/jquery@3.6.4/dist/jquery.min.js
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // @grant GM_listValues
  11. // @grant GM_addStyle
  12. // @license MIT
  13. // @version 1.0
  14. // @author Cupkait
  15. // @icon https://i.imgur.com/4Hm2e6z.png
  16. // @description Blocked users can be synced but do not actually change anything in the SW results yet.
  17.  
  18. // ==/UserScript==
  19. function OrganizeShopWizResults() {
  20.  
  21. var divElements = $('.sw_results div');
  22. var guildsList = GM_getValue('guildsList', []);
  23. var allGuildMembers = [];
  24. const userName = /user=(.*?)"/g.exec(document.body.innerHTML)[1];
  25.  
  26.  
  27.  
  28.  
  29. function createSummaryInfo() {
  30. var newDiv = $('<div>')
  31. .addClass('summaryinfo')
  32. .css({})
  33. .html('<span id="top"><p id="name">' + itemName + '</p><p id="price">Lowest: <i>' + lowestPrice.toLocaleString() + ' NP</i></p></span><span id="bottom"><p id="qty">Total Available: <strong><u>' + shopQtyTtl +
  34. '</u></strong></p><p id="searches">You have <strong>'+searchCount+ '</strong> searches left.</p></span><img width ="50%" src="https://i.imgur.com/YmRMp3Z.png">');
  35.  
  36.  
  37.  
  38.  
  39. var oldWiz = $('#page_content > main > div.center').replaceWith(newDiv);
  40. }
  41.  
  42. $('#page_banner').html('<div class="newbanner">Savvy Shop Wiz</div>')
  43. $('#page_content > main > h1').eq(0).remove();
  44. $('#page_content > main > p').eq(0).remove();
  45.  
  46.  
  47.  
  48. $.each(guildsList, function(guildID, guildData) {
  49. var guildMembers = guildData.guildMembers;
  50. allGuildMembers = allGuildMembers.concat(guildMembers);
  51. });
  52.  
  53. allGuildMembers = $.grep(allGuildMembers, function(member) {
  54. return member !== userName;
  55. });
  56.  
  57. $('.sw_results').css({
  58. 'grid-template-columns': '2fr 1fr 2fr 2fr'
  59. });
  60.  
  61. var itemName = divElements.eq(5).text();
  62. var shopQtyTtl = 0; // Initialize the total shop quantity
  63. for (var i = 6; i < divElements.length; i += 4) {
  64. var shopQty = parseInt(divElements.eq(i).text(), 10);
  65. shopQtyTtl += shopQty;}
  66.  
  67. var searchCount = parseInt($('#page_content > main > div.center > p.nomargin.smallfont').text().split('/')[0]);
  68.  
  69.  
  70. var varianceElement = $('<div>', {
  71. 'class': divElements.eq(3).attr('class')
  72. }).html('<strong>Variance</strong>').insertAfter(divElements.eq(3));
  73.  
  74. var friendList = GM_getValue('friendList', []);
  75.  
  76. var listPriceDiffs = [];
  77. var lowestPrice;
  78.  
  79. for (var i = 7; i < divElements.length; i += 4) {
  80. var currentListPrice = parseFloat(divElements.eq(i).text().replace(/,/g, ''));
  81. var currentListPriceClass = divElements.eq(i).attr('class');
  82.  
  83. if (!divElements.eq(i).hasClass('data') || !divElements.eq(i).hasClass('sw_mine') || !divElements.eq(i).hasClass('sw_friend')) {
  84. listPriceDiffs.push({
  85. listPrice: currentListPrice,
  86. priceDiff: 0,
  87. listPriceClass: currentListPriceClass
  88. });
  89. }
  90. }
  91.  
  92. lowestPrice = Math.min(...listPriceDiffs.filter(entry => !entry.listPriceClass.includes('data') || !entry.listPriceClass.includes('sw_mine') || !entry.listPriceClass.includes('sw_friend')).map(entry => entry.listPrice));
  93.  
  94. listPriceDiffs.forEach(entry => {
  95. entry.priceDiff = entry.listPrice - lowestPrice;
  96. });
  97.  
  98. listPriceDiffs.forEach((entry, index) => {
  99. var currentElement = divElements.eq(7 + (4 * index));
  100. var varianceText;
  101. if (entry.priceDiff === 0) {
  102. varianceText = '<strong style="color: green; font-weight: bold;">- LOWEST -</strong>';
  103. } else {
  104. if ($.inArray(currentElement.prev("div").prev("div").prev("div").text().trim(), allGuildMembers) !== -1 || currentElement.hasClass('data sw_guild')) {
  105. varianceText = '<strong style="color: red;">(' + '+' + entry.priceDiff.toLocaleString() + ')</strong>';
  106. } else if ($.inArray(currentElement.prev("div").prev("div").prev("div").text().trim(), friendList) !== -1 || currentElement.hasClass('data sw_mine')) {
  107. varianceText = '<strong style="color: red;">(' + '+' + entry.priceDiff.toLocaleString() + ')</strong>';
  108. } else {
  109. varianceText = '<strong>-</strong>';
  110. }
  111. }
  112.  
  113. $('<div>', {
  114. 'class': entry.listPriceClass
  115. }).insertAfter(currentElement).html(varianceText);
  116. });
  117.  
  118. var rows = $('.market_grid.sw_results.margin-1 .data, .market_grid.sw_results.margin-1 .data.bg-alt');
  119.  
  120. rows.each(function(index) {
  121. var anchorElement = $(this).find('[href*="/browseshop/?owner="]');
  122. if (anchorElement.length) {
  123. var username = anchorElement.text();
  124. if ($.inArray(username, friendList) !== -1) {
  125. for (var i = 0; i < 5 && index + i < rows.length; i++) {
  126. var currentRow = rows.eq(index + i);
  127. currentRow.addClass('data sw_friend');
  128. }
  129. } else if ($.inArray(username, allGuildMembers) !== -1) {
  130. for (var i = 0; i < 5 && index + i < rows.length; i++) {
  131. var currentRow = rows.eq(index + i);
  132. currentRow.addClass('data sw_guild');
  133. }
  134. }
  135. }
  136. });
  137. createSummaryInfo();
  138. $(".header:contains('Item')").remove();
  139. $(".data:contains('" + itemName + "')").remove();
  140.  
  141. GM_addStyle(`
  142. .summaryinfo {
  143. display: flex;
  144. font-family: trebuchetMS;
  145. padding: 0px 25px;
  146. position: relative;
  147. height: 200px;
  148. width: 545px;
  149. margin-top: 10px;
  150. flex-direction: column;
  151. flex-wrap: wrap;
  152. align-content: space-between;
  153. justify-content: space-between;
  154. align-items: stretch;
  155. padding-bottom: 15px;
  156. align-self: center;
  157. }
  158.  
  159. #top {
  160. line-height: 25px;
  161. }
  162.  
  163. #bottom {
  164. line-height: 5px;
  165. font-size: 14px;
  166. }
  167.  
  168. #name {
  169. max-width: 250px;
  170. font-family: heffaklump;
  171. font-size: 18px;
  172. margin-bottom: 5px;
  173. letter-spacing: 0px;
  174. }
  175.  
  176. #price {
  177. font-size: 16px;
  178. margin: 0px;
  179. }
  180.  
  181. #price i {
  182. font-weight: bold;
  183. font-size: 19px;
  184. font-style: normal;
  185. }
  186.  
  187. #searches {
  188. margin-bottom: 0px;
  189. }
  190.  
  191. #qty {
  192. bottom: 0px;
  193. }
  194.  
  195. .newbanner {
  196. background-image: repeating-radial-gradient(circle at 0 0, transparent 0, #ffd700 10px), repeating-linear-gradient(rgba(199, 172, 19, 0.47), rgba(199, 172, 19, 0.47));
  197. background-color: #ffd700;
  198. font-family: heffaklump;
  199. font-weight: bold;
  200. line-height: 50px;
  201. font-size: 50px;
  202. padding-right: 20px;
  203. text-align: right;
  204. width: 595px;
  205. background-color: gold;
  206. border-radius: 20px;
  207. border: solid 5px black;
  208. }
  209. .data.sw_guild, .data.bg-alt.sw_guild {
  210. order: -2;
  211. background-color: #f3bc8c;
  212. }
  213. .data.sw_friend, .data.bg-alt.sw_friend {
  214. order: -2;
  215. background-color: rgba(92, 227, 158, .53);
  216. }
  217. .data.sw_mine {
  218. order: -2;
  219. }
  220. .data.sw_block {
  221. background-color:#bcb6b6f7 !important;
  222. opacity:30%;
  223. }
  224. .sw_block:hover {
  225. opacity:100%;
  226. }
  227. `);
  228. };