[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.

目前为 2024-10-13 提交的版本。查看 最新版本

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