SWCombine - Link to Rules Page for Entity from Inventory Table

Adds another link to the Options Column to take you directly to that entity's rules page, rather than having to chain to it via 'Show Stats'

目前為 2025-01-03 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name SWCombine - Link to Rules Page for Entity from Inventory Table
  3. // @namespace http://tampermonkey.net/
  4. // @version 2025-01-03
  5. // @description Adds another link to the Options Column to take you directly to that entity's rules page, rather than having to chain to it via 'Show Stats'
  6. // @author You
  7. // @match https://www.swcombine.com/members/inventory2/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=swcombine.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. function createElementFromHTML(htmlString) {
  13. var div = document.createElement('div');
  14. div.innerHTML = htmlString.trim();
  15.  
  16. // Change this to div.childNodes to support multiple top-level nodes.
  17. return div.firstChild;
  18. }
  19.  
  20. var entityTypeLookup = {};
  21. entityTypeLookup["2"] = "Ships";
  22. entityTypeLookup["3"] = "Vehicles";
  23. entityTypeLookup["5"] = "Space_Stations";
  24. entityTypeLookup["7"] = "Cities";
  25. entityTypeLookup["4"] = "Facilities";
  26. entityTypeLookup["8"] = "Planets";
  27. entityTypeLookup["12"] = "Items";
  28. entityTypeLookup["10"] = "NPCS";
  29. entityTypeLookup["13"] = "Droids";
  30. entityTypeLookup["11"] = "Creatures";
  31. entityTypeLookup["16"] = "Raw_Materials";
  32.  
  33. (function() {
  34. 'use strict';
  35.  
  36. let table = document.querySelector('.inventory_list_table');
  37.  
  38. for (let row of table.children) {
  39. if(row.querySelector('.inventory_entity_row')) {
  40. let entityType = document.location.href.split('entityType=')[1].match(/^\d*/);
  41.  
  42. let entityID = -1;
  43. if(row.querySelector('a[href*="images.swcombine"]')) {
  44. entityID = row.querySelector('a[href*="images.swcombine"]').href.split('/')[5];
  45. }
  46. if(row.querySelector('a[href*="custom.swcombine"]')) {
  47. entityID = row.querySelector('a[href*="custom.swcombine"]').href.split('/')[5];
  48. }
  49.  
  50. if(entityID != -1) {
  51. let newLink = "/rules/?" + entityTypeLookup[entityType] + "&ID=" + entityID;
  52. let newElement = createElementFromHTML("<a href='"+newLink+"'>Show Rules Page</a><br />");
  53.  
  54. let optionsCol = row.querySelector('.inventoryStatusIcons+td');
  55. optionsCol.append(newElement);
  56. }
  57. }
  58. }
  59. })();