[GC] - Virtupets.net Quest Calculator

Calculate cost of quests using Virtupets API without having to check each item and do mental math. Staff approved script via ticket.

  1. // ==UserScript==
  2. // @name [GC] - Virtupets.net Quest Calculator
  3. // @namespace https://greasyfork.org/en/users/1225524-kaitlin
  4. // @grant GM.getValue
  5. // @grant GM.setValue
  6. // @match https://www.grundos.cafe/winter/snowfaerie/*
  7. // @match https://www.grundos.cafe/island/kitchen/*
  8. // @match https://www.grundos.cafe/halloween/esophagor/*
  9. // @match https://www.grundos.cafe/halloween/witchtower/*
  10. // @version 1.1.1
  11. // @license MIT
  12. // @description Calculate cost of quests using Virtupets API without having to check each item and do mental math. Staff approved script via ticket.
  13. // @author Cupkait
  14. // @require https://update.greasyfork.org/scripts/512407/1463866/GC%20-%20Virtupets%20API%20library.js
  15. // @icon https://i.imgur.com/4Hm2e6z.png
  16. // ==/UserScript==
  17.  
  18.  
  19. const path = window.location.pathname;
  20.  
  21. async function fetchQuestData(questDiv) {
  22. const questList = document.querySelectorAll('.quest_text').length > 0
  23. ? document.querySelectorAll('.quest_text')
  24. : document.querySelectorAll('.quest-item').length > 0
  25. ? document.querySelectorAll('.quest-item')
  26. : document.querySelectorAll('.centered-item');
  27.  
  28. const questArray = Array.from(questList).map(item => item.querySelector('strong').textContent);
  29.  
  30. try {
  31. const response = await bulkShopWizardPrices(questArray);
  32. const data = await response.json();
  33.  
  34. const tableHTML = createTableHTML(data);
  35. questDiv.innerHTML = tableHTML;
  36. } catch (error) {
  37. console.error('Error:', error);
  38. questDiv.innerHTML = `<p>Error fetching quest data. Please try again later.</p>`;
  39. }
  40. }
  41.  
  42. function createTableHTML(data) {
  43. let tableHTML = '<table><tr><th colspan="3" style="background-color: #4abdb8; font-size: 16px;"><strong>Virtupets.net Quest Calculator</strong></th></tr><tr><th>Item Name</th><th>Price</th><th>Date Priced</th></tr>';
  44. let totalPrice = 0;
  45.  
  46. data.forEach(item => {
  47. const date = new Date(item.time);
  48. const formattedDate = `${date.getMonth() + 1}/${date.getDate()}/${date.getFullYear()}`;
  49. totalPrice += item.price;
  50.  
  51. tableHTML += `<tr><td>${item.name}</td><td>${item.price.toLocaleString()} NP</td><td>${formattedDate}</td></tr>`;
  52. });
  53.  
  54. tableHTML += `<tr><td><strong>Total Estimated Cost: ${totalPrice.toLocaleString()} NP</strong></td><td></td></tr>`;
  55. tableHTML += '</table><span class="disclaimer">Prices always subject to change. To update an outdated price, download <a href="https://greasyfork.org/en/scripts/490596-gc-virtupets-data-collector">this script</a> before searching it on the Shop Wizard. Report errors or suggestions to @Cupkait!</span>';
  56. return tableHTML;
  57. }
  58.  
  59. function appendQuestDiv(anchor) {
  60. const questDiv = document.createElement('div');
  61. questDiv.classList.add('quest-div');
  62. anchor.append(questDiv);
  63. return questDiv;
  64. }
  65.  
  66. if (path.includes('/accept/')) {
  67. const anchor = document.querySelector('.itemList').previousElementSibling;
  68. const questDiv = appendQuestDiv(anchor);
  69. fetchQuestData(questDiv);
  70.  
  71. } else if (path.includes('/complete/') && document.querySelector('#page_content .flex-column').textContent.includes("Deadline")) {
  72. const anchor = document.querySelector('#quest_grid').previousElementSibling;
  73. const questDiv = appendQuestDiv(anchor);
  74. fetchQuestData(questDiv);
  75.  
  76. } else if (path.includes('/complete/')) {
  77. // do nothing, all done!
  78.  
  79. } else if (path.includes('/snowfaerie/')) {
  80. const anchor = document.querySelector('#taelia_grid').previousElementSibling;
  81. const questDiv = appendQuestDiv(anchor);
  82. fetchQuestData(questDiv);
  83.  
  84. } else {
  85. const anchor = document.querySelector('.itemList').previousElementSibling;
  86. const questDiv = appendQuestDiv(anchor);
  87. fetchQuestData(questDiv);
  88. }
  89.  
  90. const questStyle = document.createElement('style');
  91. questStyle.innerHTML = `
  92. .quest-div {
  93. display: grid;
  94. border: 2px solid black;
  95. margin-top: 20px;
  96. margin-left: 30px;
  97. margin-right: 30px;
  98. }
  99.  
  100. .quest-div td {
  101. padding: 5px;
  102. }
  103.  
  104. .disclaimer {
  105. font-style:italic;
  106. font-size:10px;
  107. margin-top:-5px;
  108. margin-bottom:2px;
  109. padding-left:10%;
  110. padding-right:10%;
  111. }
  112. `;
  113.  
  114. document.body.append(questStyle);