Paid for things

New pips!

  1. // ==UserScript==
  2. // @name Paid for things
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.4
  5. // @description New pips!
  6. // @author tharglet
  7. // @match https://myfigurecollection.net/?*mode=view&*tab=collection&*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=myfigurecollection.net
  9. // @grant GM_addStyle
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // ==/UserScript==
  13.  
  14. //Polyfill for GM_addStyle for Greasemonkey...
  15. if(typeof GM_addStyle == 'undefined') {
  16. GM_addStyle = (aCss) => {
  17. 'use strict';
  18. let head = document.getElementsByTagName('head')[0];
  19. if (head) {
  20. let style = document.createElement('style');
  21. style.setAttribute('type', 'text/css');
  22. style.textContent = aCss;
  23. head.appendChild(style);
  24. return style;
  25. }
  26. return null;
  27. };
  28. }
  29.  
  30. GM_addStyle(`
  31. .item-custompip {
  32. display: block;
  33. position: absolute;
  34. right: 1px;
  35. bottom: 1px;
  36. height: 16px;
  37. padding: 1px 2px 2px 3px;
  38. line-height: 16px;
  39. color: white;
  40. }
  41.  
  42. .item-is-paid {
  43. background-color: green;
  44. }
  45.  
  46. .item-is-shipped {
  47. background-color: gold;
  48. }
  49.  
  50. .item-is-stored {
  51. background-color: orangered;
  52. }
  53.  
  54. .icon-dollar:before {
  55. font-family: serif !important;
  56. content: "$";
  57. font-weight: bolder !important;
  58. }
  59.  
  60. .icon-plane:before {
  61. font-family: serif !important;
  62. content: "🛩️";
  63. font-weight: bolder !important;
  64. }
  65.  
  66. .icon-stored:before {
  67. font-family: serif !important;
  68. content: "🏭";
  69. font-weight: bolder !important;
  70. }
  71. `);
  72.  
  73. (async function() {
  74. 'use strict';
  75.  
  76. const appendPip = (itemClassName, pipClassName, itemElement) => {
  77. const shippedPipContainer = document.createElement('span');
  78. shippedPipContainer.classList.add('item-custompip', itemClassName);
  79. const shippedPip = document.createElement('span');
  80. shippedPip.classList.add('tiny-icon-only', pipClassName);
  81. shippedPipContainer.appendChild(shippedPip);
  82. itemElement.appendChild(shippedPipContainer);
  83. }
  84.  
  85. const isUsersPreorderPage = () => {
  86. const urlParams = new URLSearchParams(window.location.search);
  87. const status = urlParams.get("status");
  88. if(status == 1) {
  89. let loggedInUser = document.querySelector(".user-menu .handle");
  90. if(loggedInUser) {
  91. let userLink = loggedInUser.getAttribute("href");
  92. if(userLink === "/session/signup") {
  93. return false;
  94. } else {
  95. let userParam;
  96. const windowLocation = window.location.href;
  97. if(windowLocation.startsWith("https://myfigurecollection.net/profile/")) {
  98. userParam = windowLocation.match(/https:\/\/myfigurecollection\.net\/profile\/([^\/]*)/)[1];
  99. } else {
  100. const urlParams = new URLSearchParams(window.location.search);
  101. userParam = urlParams.get("username");
  102. }
  103. return userParam === userLink.substring("9");
  104. }
  105. } else {
  106. return false;
  107. }
  108. } else {
  109. return false;
  110. }
  111. };
  112. if(isUsersPreorderPage()) {
  113. const paidItems = [];
  114. const storedItems = [];
  115. const shippedItems = [];
  116. const parser = new DOMParser();
  117.  
  118. // Paid
  119. await fetch('/?mode=collection&page=1&tab=ordered&current=keywords&output=sheet&isPaid=1&_tb=manager').then((response) => {
  120. return response.text();
  121. }).then((html) => {
  122. const doc = parser.parseFromString(html, 'text/html');
  123. const items = doc.querySelectorAll('.row.tbx-checkable-row .cell:nth-child(2) a');
  124. if(items) {
  125. items.forEach((item) => {
  126. paidItems.push(item.getAttribute('href'));
  127. });
  128. }
  129. }).catch(function (err) {
  130. console.warn('Something went wrong.', err);
  131. });
  132.  
  133. // Stored
  134. await fetch('?mode=collection&page=1&tab=ordered&output=sheet&_tb=manager').then((response) => {
  135. return response.text();
  136. }).then((html) => {
  137. const doc = parser.parseFromString(html, 'text/html');
  138. const isStoredCells = doc.querySelectorAll('.row.tbx-checkable-row .cell:nth-child(9)');
  139. if(isStoredCells) {
  140. isStoredCells.forEach((isStoredItem) => {
  141. if(isStoredItem.textContent.includes('Stored')) {
  142. const itemLink = isStoredItem.parentElement.querySelector('.cell:nth-child(2) a');
  143. storedItems.push(itemLink.getAttribute('href'));
  144. }
  145. });
  146. }
  147. }).catch(function (err) {
  148. console.warn('Something went wrong.', err);
  149. });
  150.  
  151. // Shipped
  152. await fetch('/?mode=collection&page=1&tab=ordered&current=keywords&output=sheet&isShipped=1&_tb=manager').then((response) => {
  153. return response.text();
  154. }).then((html) => {
  155. const doc = parser.parseFromString(html, 'text/html');
  156. const items = doc.querySelectorAll('.row.tbx-checkable-row .cell:nth-child(2) a');
  157. if(items) {
  158. items.forEach((item) => {
  159. shippedItems.push(item.getAttribute('href'));
  160. });
  161. }
  162. }).catch(function (err) {
  163. console.warn('Something went wrong.', err);
  164. });
  165. const itemIcons = document.querySelectorAll('.item-icon a');
  166. itemIcons.forEach((item) => {
  167. if(shippedItems.includes(item.getAttribute('href'))) {
  168. appendPip('item-is-shipped', 'icon-plane', item);
  169. } else if(storedItems.includes(item.getAttribute('href'))) {
  170. appendPip('item-is-stored', 'icon-stored', item);
  171. } else if(paidItems.includes(item.getAttribute('href'))) {
  172. appendPip('item-is-paid', 'icon-dollar', item);
  173. }
  174. });
  175. }
  176. })();