🏠 Home 

AvistaZ Bonus Point Plus+

Adds a "Shortfall" and "Time Calculation" to Exchange table, Adds BP per second, minute,...


Install this script?
  1. // ==UserScript==
  2. // @name AvistaZ Bonus Point Plus+
  3. // @namespace https://github.com/royspace/AvistaZ-Bonus-Point-Plus
  4. // @homepage https://github.com/royspace/AvistaZ-Bonus-Point-Plus
  5. // @version 0.3
  6. // @author Roy
  7. // @description Adds a "Shortfall" and "Time Calculation" to Exchange table, Adds BP per second, minute,...
  8. // @match https://avistaz.to/profile/*/bonus
  9. // @icon https://avistaz.to/images/avistaz-favicon.png
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13. (function () {
  14. 'use strict';
  15. function createCalculationTable(pointsPerHour) {
  16. var pointsPerSecond = pointsPerHour / 3600;
  17. var pointsPerMinute = pointsPerHour / 60;
  18. var pointsPerDay = pointsPerHour * 24;
  19. var pointsPerWeek = pointsPerDay * 7;
  20. var pointsPerMonth = pointsPerDay * 30;
  21. var pointsPerYear = pointsPerDay * 365;
  22. var table = document.createElement('table');
  23. table.style.borderCollapse = 'collapse';
  24. table.style.marginTop = '10px';
  25. table.style.width = '100%';
  26. var tableHeader = table.createTHead();
  27. var headerRow = tableHeader.insertRow();
  28. var headerCellLabel = headerRow.insertCell();
  29. var headerCellValue = headerRow.insertCell();
  30. headerCellLabel.innerHTML = 'Calculation';
  31. headerCellLabel.style.backgroundColor = '#001F3F';
  32. headerCellLabel.style.fontWeight = 'bold';
  33. headerCellLabel.style.padding = '10px';
  34. headerCellValue.innerHTML = 'Value';
  35. headerCellValue.style.backgroundColor = '#001F3F';
  36. headerCellValue.style.fontWeight = 'bold';
  37. headerCellValue.style.padding = '10px';
  38. var tableBody = table.createTBody();
  39. function addRow(label, value) {
  40. var row = tableBody.insertRow();
  41. var cellLabel = row.insertCell(0);
  42. var cellValue = row.insertCell(1);
  43. cellLabel.innerHTML = label;
  44. cellLabel.style.textAlign = 'left';
  45. cellLabel.style.paddingLeft = '10px';
  46. cellLabel.style.fontWeight = '400';
  47. cellValue.innerHTML = value.toFixed(2);
  48. cellValue.style.textAlign = 'right';
  49. cellValue.style.paddingRight = '10px';
  50. cellValue.style.fontWeight = '550';
  51. }
  52. addRow('Points Per Second', pointsPerSecond);
  53. addRow('Points Per Minute', pointsPerMinute);
  54. addRow('Points Per Hour', pointsPerHour);
  55. addRow('Points Per Day', pointsPerDay);
  56. addRow('Points Per Week', pointsPerWeek);
  57. addRow('Points Per Month', pointsPerMonth);
  58. addRow('Points Per Year', pointsPerYear);
  59. return table;
  60. }
  61. function addCalculationColumn() {
  62. var pointsPerHour = parseFloat(document.querySelector('td:nth-child(3) strong').textContent);
  63. const header = document.querySelector('div > div > .col-sm-8 > table > thead > tr');
  64. if (header) {
  65. const shortfallHeaderCell = document.createElement('th');
  66. shortfallHeaderCell.textContent = 'Shortfall';
  67. header.querySelector('th:nth-child(2)').after(shortfallHeaderCell);
  68. const timeCalculationHeaderCell = document.createElement('th');
  69. timeCalculationHeaderCell.textContent = 'Time Calculation';
  70. shortfallHeaderCell.after(timeCalculationHeaderCell);
  71. }
  72. const tbody = document.querySelector('div > div > .col-sm-8 > table > tbody');
  73. const trimValueElement = document.querySelector('h2');
  74. const trimValue = parseFloat(trimValueElement.textContent.replace(/[^\d.]/g, '')) || 0;
  75. function formatTime(hours) {
  76. const months = Math.floor(hours / (30 * 24));
  77. const days = Math.floor((hours % (30 * 24)) / 24);
  78. const remainingHours = Math.round(hours % 24);
  79. let r###lt = '';
  80. if (months > 0) {
  81. r###lt += `${months} month${months > 1 ? 's' : ''}, `;
  82. }
  83. if (days > 0) {
  84. r###lt += `${days} day${days > 1 ? 's' : ''}, `;
  85. }
  86. if (remainingHours > 0) {
  87. r###lt += `${remainingHours} hour${remainingHours > 1 ? 's' : ''}`;
  88. }
  89. return r###lt.trim();
  90. }
  91. if (tbody) {
  92. const rows = tbody.querySelectorAll('tr');
  93. rows.forEach((row, index) => {
  94. const pointsCell = row.querySelector('td:nth-child(2)');
  95. const pointsValue = parseInt(pointsCell.textContent.replace(/,/g, ''), 10);
  96. const shortfallValue = Math.max(pointsValue - trimValue, 0).toFixed(0);
  97. const shortfallCell = document.createElement('td');
  98. shortfallCell.textContent = shortfallValue;
  99. pointsCell.after(shortfallCell);
  100. const timeCalculationValue = shortfallValue / pointsPerHour;
  101. const timeCalculationCell = document.createElement('td');
  102. timeCalculationCell.textContent = formatTime(timeCalculationValue);
  103. shortfallCell.after(timeCalculationCell);
  104. });
  105. }
  106. }
  107. var targetElement = document.querySelector('div > div .well-sm > h3');
  108. if (targetElement) {
  109. var pointsPerHour = parseFloat(document.querySelector('td:nth-child(3) strong').textContent);
  110. var calculationTable = createCalculationTable(pointsPerHour);
  111. targetElement.parentNode.insertBefore(calculationTable, targetElement.nextSibling);
  112. }
  113. addCalculationColumn();
  114. })();