[GC | Library] - Highlight and sort 15 NP stocks

Automatically identifies cheapest buyable stocks for easily selecting a stock to purchase.

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/487476/1328526/%5BGC%20%7C%20Library%5D%20-%20Highlight%20and%20sort%2015%20NP%20stocks.js

  1. function highlightRows() {
  2. var table = document.querySelector('table[border="1"]');
  3.  
  4. if (!table) {
  5. console.log("Table not found on this page.");
  6. return;
  7. }
  8.  
  9. var rows = Array.from(table.querySelectorAll('tr'));
  10.  
  11. // Display buyable stocks
  12. var curr15Rows = [];
  13.  
  14. rows.forEach(function(row) {
  15. var cells = row.querySelectorAll('td');
  16. if (cells.length >= 6) {
  17. var currCell = cells[5];
  18. if (currCell.textContent.trim() === "15") {
  19. curr15Rows.push(row);
  20. }
  21. }
  22. });
  23.  
  24. if (curr15Rows.length === 0) {
  25. // Display a message if there are no buyable stocks
  26. var messageDiv = document.createElement('div');
  27. messageDiv.textContent = "😭 There are no buyable stocks at this time.";
  28. messageDiv.style.fontSize = '24px';
  29. messageDiv.style.textAlign = 'center';
  30. table.parentNode.insertBefore(messageDiv, table);
  31. } else {
  32. curr15Rows.forEach(function(row) {
  33. row.parentNode.removeChild(row);
  34. table.insertBefore(row, table.firstChild);
  35.  
  36. var cells = row.querySelectorAll('td');
  37. cells.forEach(function(cell) {
  38. cell.style.backgroundColor = 'yellow';
  39. });
  40. });
  41. }
  42. }