Inara - Commodities Search-Presets

Saving/Loading of search-presets for commodities

  1. // ==UserScript==
  2. // @name Inara - Commodities Search-Presets
  3. // @name:de Inara - Waren Such-Voreinstellungen
  4. // @namespace https://gf.qytechs.cn/users/928242
  5. // @version 1.0.0
  6. // @description Saving/Loading of search-presets for commodities
  7. // @description:de Speichern/Laden von Such-Presets für Waren
  8. // @author Kamikaze (https://github.com/Kamiikaze)
  9. // @supportURL https://github.com/Kamiikaze/Tampermonkey/issues
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=inara.cz
  11. // @match https://inara.cz/elite/commodities/*
  12. // @grant none
  13. // @license MIT
  14. // ==/UserScript==
  15.  
  16. const showPresetDetails = true
  17.  
  18. // Mapping of all commodities. You can change the displayed values if needed
  19. const fullMapping = {
  20. "pi1": {
  21. "label": "Buy/Sell",
  22. "values": [
  23. {"value": "1", "text": "Buy"},
  24. {"value": "2", "text": "Sell"}
  25. ]
  26. },
  27. "pa1": {
  28. "label": "Commodity",
  29. "values": [
  30. {"value": "61", "text": "Advanced Catalysers"},
  31. {"value": "166", "text": "Advanced Medicines"},
  32. {"value": "1", "text": "Agri-Medicines"},
  33. {"value": "10268", "text": "Agronomic Treatment"},
  34. {"value": "89", "text": "AI Relics"},
  35. {"value": "10249", "text": "Alexandrite"},
  36. {"value": "15", "text": "Algae"},
  37. {"value": "37", "text": "Aluminium"},
  38. {"value": "121", "text": "Ancient Artefact"},
  39. {"value": "10240", "text": "Ancient Key"},
  40. {"value": "16", "text": "Animal Meat"},
  41. {"value": "62", "text": "Animal Monitors"},
  42. {"value": "10270", "text": "Anomaly Particles"},
  43. {"value": "10167", "text": "Antimatter Containment Unit"},
  44. {"value": "10209", "text": "Antique Jewellery"},
  45. {"value": "91", "text": "Antiquities"},
  46. {"value": "63", "text": "Aquaponic Systems"},
  47. {"value": "182", "text": "Articulation Motors"},
  48. {"value": "169", "text": "Assault Plans"},
  49. {"value": "87", "text": "Atmospheric Processors"},
  50. {"value": "65", "text": "Auto-Fabricators"},
  51. {"value": "33", "text": "Basic Medicines"},
  52. {"value": "88", "text": "Battle Weapons"},
  53. {"value": "51", "text": "Bauxite"},
  54. {"value": "10", "text": "Beer"},
  55. {"value": "10247", "text": "Benitoite"},
  56. {"value": "52", "text": "Bertrandite"},
  57. {"value": "38", "text": "Beryllium"},
  58. {"value": "66", "text": "Bioreducing Lichen"},
  59. {"value": "76", "text": "Biowaste"},
  60. {"value": "106", "text": "Bismuth"},
  61. {"value": "122", "text": "Black Box"},
  62. {"value": "10456", "text": "Bone Fragments"},
  63. {"value": "95", "text": "Bootleg Liquor"},
  64. {"value": "148", "text": "Bromellite"},
  65. {"value": "102", "text": "Building Fabricators"},
  66. {"value": "10439", "text": "Caustic Tissue Sample"},
  67. {"value": "100", "text": "Ceramic Composites"},
  68. {"value": "32", "text": "Chemical Waste"},
  69. {"value": "7", "text": "Clothing"},
  70. {"value": "140", "text": "CMM Composite"},
  71. {"value": "39", "text": "Cobalt"},
  72. {"value": "17", "text": "Coffee"},
  73. {"value": "55", "text": "Coltan"},
  74. {"value": "34", "text": "Combat Stabilisers"},
  75. {"value": "170", "text": "Commercial Samples"},
  76. {"value": "67", "text": "Computer Components"},
  77. {"value": "165", "text": "Conductive Fabrics"},
  78. {"value": "8", "text": "Consumer Technology"},
  79. {"value": "40", "text": "Copper"},
  80. {"value": "10451", "text": "Coral Sap"},
  81. {"value": "29", "text": "Crop Harvesters"},
  82. {"value": "110", "text": "Cryolite"},
  83. {"value": "10459", "text": "Cyst Specimen"},
  84. {"value": "10215", "text": "Damaged Escape Pod"},
  85. {"value": "10166", "text": "Data Core"},
  86. {"value": "171", "text": "Diplomatic Bag"},
  87. {"value": "9", "text": "Domestic Appliances"},
  88. {"value": "10210", "text": "Earth Relics"},
  89. {"value": "158", "text": "Emergency Power Cells"},
  90. {"value": "172", "text": "Encrypted Correspondence"},
  91. {"value": "173", "text": "Encrypted Data Storage"},
  92. {"value": "149", "text": "Energy Grid Assembly"},
  93. {"value": "99", "text": "Evacuation Shelter"},
  94. {"value": "159", "text": "Exhaust Manifold"},
  95. {"value": "123", "text": "Experimental Chemicals"},
  96. {"value": "3", "text": "Explosives"},
  97. {"value": "18", "text": "Fish"},
  98. {"value": "19", "text": "Food Cartridges"},
  99. {"value": "10221", "text": "Fossil Remnants"},
  100. {"value": "20", "text": "Fruit and Vegetables"},
  101. {"value": "56", "text": "Gallite"},
  102. {"value": "41", "text": "Gallium"},
  103. {"value": "10211", "text": "Gene Bank"},
  104. {"value": "103", "text": "Geological Equipment"},
  105. {"value": "174", "text": "Geological Samples"},
  106. {"value": "42", "text": "Gold"},
  107. {"value": "111", "text": "Goslarite"},
  108. {"value": "21", "text": "Grain"},
  109. {"value": "10248", "text": "Grandidierite"},
  110. {"value": "10153", "text": "Guardian Casket"},
  111. {"value": "10154", "text": "Guardian Orb"},
  112. {"value": "10155", "text": "Guardian Relic"},
  113. {"value": "10156", "text": "Guardian Tablet"},
  114. {"value": "10157", "text": "Guardian Totem"},
  115. {"value": "10158", "text": "Guardian Urn"},
  116. {"value": "68", "text": "H.E. Suits"},
  117. {"value": "10486", "text": "Haematite"},
  118. {"value": "124", "text": "Hafnium 178"},
  119. {"value": "155", "text": "Hardware Diagnostic Sensor"},
  120. {"value": "151", "text": "Heatsink Interlink"},
  121. {"value": "150", "text": "HN Shock Mount"},
  122. {"value": "175", "text": "Hostages"},
  123. {"value": "4", "text": "Hydrogen Fuel"},
  124. {"value": "138", "text": "Hydrogen Peroxide"},
  125. {"value": "49", "text": "Imperial Slaves"},
  126. {"value": "10452", "text": "Impure Spire Mineral"},
  127. {"value": "57", "text": "Indite"},
  128. {"value": "43", "text": "Indium"},
  129. {"value": "141", "text": "Insulating Membrane"},
  130. {"value": "160", "text": "Ion Distributor"},
  131. {"value": "168", "text": "Jadeite"},
  132. {"value": "71", "text": "Land Enrichment Systems"},
  133. {"value": "118", "text": "Landmines"},
  134. {"value": "107", "text": "Lanthanum"},
  135. {"value": "125", "text": "Large Survey Data Cache"},
  136. {"value": "73", "text": "Leather"},
  137. {"value": "58", "text": "Lepidolite"},
  138. {"value": "137", "text": "Liquid oxygen"},
  139. {"value": "11", "text": "Liquor"},
  140. {"value": "44", "text": "Lithium"},
  141. {"value": "147", "text": "Lithium Hydroxide"},
  142. {"value": "144", "text": "Low Temperature Diamonds"},
  143. {"value": "152", "text": "Magnetic Emitter Coil"},
  144. {"value": "86", "text": "Marine Equipment"},
  145. {"value": "154", "text": "Medical Diagnostic Equipment"},
  146. {"value": "101", "text": "Meta-Alloys"},
  147. {"value": "145", "text": "Methane Clathrate"},
  148. {"value": "146", "text": "Methanol Monohydrate Crystals"},
  149. {"value": "185", "text": "Micro-weave Cooling Hoses"},
  150. {"value": "85", "text": "Microbial Furnaces"},
  151. {"value": "156", "text": "Micro Controllers"},
  152. {"value": "157", "text": "Military Grade Fabrics"},
  153. {"value": "126", "text": "Military Intelligence"},
  154. {"value": "127", "text": "Military Plans"},
  155. {"value": "31", "text": "Mineral Extractors"},
  156. {"value": "5", "text": "Mineral Oil"},
  157. {"value": "181", "text": "Modular Terminals"},
  158. {"value": "116", "text": "Moissanite"},
  159. {"value": "10256", "text": "Mollusc Brain Tissue"},
  160. {"value": "10255", "text": "Mollusc Fluid"},
  161. {"value": "10252", "text": "Mollusc Membrane"},
  162. {"value": "10253", "text": "Mollusc Mycelium"},
  163. {"value": "10254", "text": "Mollusc Soft Tissue"},
  164. {"value": "10251", "text": "Mollusc Spores"},
  165. {"value": "10245", "text": "Monazite"},
  166. {"value": "119", "text": "Muon Imager"},
  167. {"value": "10246", "text": "Musgravite"},
  168. {"value": "10219", "text": "Mysterious Idol"},
  169. {"value": "167", "text": "Nanobreakers"},
  170. {"value": "12", "text": "Narcotics"},
  171. {"value": "74", "text": "Natural Fabrics"},
  172. {"value": "183", "text": "Neofabric Insulation"},
  173. {"value": "96", "text": "Nerve Agents"},
  174. {"value": "78", "text": "Non-Lethal Weapons"},
  175. {"value": "129", "text": "Occupied Escape Pod"},
  176. {"value": "10435", "text": "Onionhead Gamma Strain"},
  177. {"value": "10458", "text": "Organ Sample"},
  178. {"value": "72", "text": "Osmium"},
  179. {"value": "84", "text": "Painite"},
  180. {"value": "45", "text": "Palladium"},
  181. {"value": "35", "text": "Performance Enhancers"},
  182. {"value": "10159", "text": "Personal Effects"},
  183. {"value": "79", "text": "Personal Weapons"},
  184. {"value": "6", "text": "Pesticides"},
  185. {"value": "10259", "text": "Pod Core Tissue"},
  186. {"value": "10257", "text": "Pod Dead Tissue"},
  187. {"value": "10262", "text": "Pod Mesoglea"},
  188. {"value": "10260", "text": "Pod Outer Tissue"},
  189. {"value": "10261", "text": "Pod Shell Tissue"},
  190. {"value": "10258", "text": "Pod Surface Tissue"},
  191. {"value": "10263", "text": "Pod Tissue"},
  192. {"value": "177", "text": "Political Prisoners"},
  193. {"value": "26", "text": "Polymers"},
  194. {"value": "153", "text": "Power Converter"},
  195. {"value": "83", "text": "Power Generators"},
  196. {"value": "161", "text": "Power Transfer Bus"},
  197. {"value": "143", "text": "Praseodymium"},
  198. {"value": "10165", "text": "Precious Gems"},
  199. {"value": "36", "text": "Progenitor Cells"},
  200. {"value": "10220", "text": "Prohibited Research Materials"},
  201. {"value": "10449", "text": "Protective Membrane Scrap"},
  202. {"value": "130", "text": "Prototype Tech"},
  203. {"value": "112", "text": "Pyrophyllite"},
  204. {"value": "162", "text": "Radiation Baffle"},
  205. {"value": "131", "text": "Rare Artwork"},
  206. {"value": "80", "text": "Reactive Armour"},
  207. {"value": "132", "text": "Rebel Transmissions"},
  208. {"value": "163", "text": "Reinforced Mounting Plate"},
  209. {"value": "69", "text": "Resonating Separators"},
  210. {"value": "10243", "text": "Rhodplumsite"},
  211. {"value": "70", "text": "Robotics"},
  212. {"value": "10264", "text": "Rockforth Fertiliser"},
  213. {"value": "59", "text": "Rutile"},
  214. {"value": "142", "text": "Samarium"},
  215. {"value": "90", "text": "SAP 8 Core Container"},
  216. {"value": "178", "text": "Scientific Research"},
  217. {"value": "179", "text": "Scientific Samples"},
  218. {"value": "77", "text": "Scrap"},
  219. {"value": "10453", "text": "Semi-Refined Spire Mineral"},
  220. {"value": "28", "text": "Semiconductors"},
  221. {"value": "10244", "text": "Serendibite"},
  222. {"value": "46", "text": "Silver"},
  223. {"value": "104", "text": "Skimmer Components"},
  224. {"value": "53", "text": "Slaves"},
  225. {"value": "10208", "text": "Small Survey Data Cache"},
  226. {"value": "10164", "text": "Space Pioneer Relics"},
  227. {"value": "10487", "text": "Steel"},
  228. {"value": "117", "text": "Structural Regulators"},
  229. {"value": "27", "text": "Superconductors"},
  230. {"value": "97", "text": "Surface Stabilisers"},
  231. {"value": "164", "text": "Survival Equipment"},
  232. {"value": "75", "text": "Synthetic Fabrics"},
  233. {"value": "23", "text": "Synthetic Meat"},
  234. {"value": "98", "text": "Synthetic Reagents"},
  235. {"value": "120", "text": "Taaffeite"},
  236. {"value": "180", "text": "Tactical Data"},
  237. {"value": "47", "text": "Tantalum"},
  238. {"value": "22", "text": "Tea"},
  239. {"value": "133", "text": "Technical Blueprints"},
  240. {"value": "184", "text": "Telemetry Suite"},
  241. {"value": "108", "text": "Thallium"},
  242. {"value": "10236", "text": "Thargoid Basilisk Tissue Sample"},
  243. {"value": "10450", "text": "Thargoid Bio-storage Capsule"},
  244. {"value": "10160", "text": "Thargoid Biological Matter"},
  245. {"value": "10234", "text": "Thargoid Cyclops Tissue Sample"},
  246. {"value": "10441", "text": "Thargoid Glaive Tissue Sample"},
  247. {"value": "10235", "text": "Thargoid Heart"},
  248. {"value": "10239", "text": "Thargoid Hydra Tissue Sample"},
  249. {"value": "10161", "text": "Thargoid Link"},
  250. {"value": "10237", "text": "Thargoid Medusa Tissue Sample"},
  251. {"value": "10438", "text": "Thargoid Orthrus Tissue Sample"},
  252. {"value": "186", "text": "Thargoid Probe"},
  253. {"value": "10162", "text": "Thargoid Resin"},
  254. {"value": "10238", "text": "Thargoid Scout Tissue Sample"},
  255. {"value": "10448", "text": "Thargoid Scythe Tissue Sample"},
  256. {"value": "10226", "text": "Thargoid Sensor"},
  257. {"value": "10163", "text": "Thargoid Technology Samples"},
  258. {"value": "105", "text": "Thermal Cooling Units"},
  259. {"value": "109", "text": "Thorium"},
  260. {"value": "10212", "text": "Time Capsule"},
  261. {"value": "10442", "text": "Titan Deep Tissue Sample"},
  262. {"value": "10457", "text": "Titan Drive Component"},
  263. {"value": "48", "text": "Titanium"},
  264. {"value": "10445", "text": "Titan Maw Deep Tissue Sample"},
  265. {"value": "10446", "text": "Titan Maw Partial Tissue Sample"},
  266. {"value": "10447", "text": "Titan Maw Tissue Sample"},
  267. {"value": "10444", "text": "Titan Partial Tissue Sample"},
  268. {"value": "10443", "text": "Titan Tissue Sample"},
  269. {"value": "13", "text": "Tobacco"},
  270. {"value": "54", "text": "Toxic Waste"},
  271. {"value": "134", "text": "Trade Data"},
  272. {"value": "135", "text": "Trinkets of Hidden Fortune"},
  273. {"value": "10269", "text": "Tritium"},
  274. {"value": "10437", "text": "Unclassified Relic"},
  275. {"value": "10440", "text": "Unoccupied Escape Pod"},
  276. {"value": "176", "text": "Unstable Data Core"},
  277. {"value": "60", "text": "Uraninite"},
  278. {"value": "50", "text": "Uranium"},
  279. {"value": "10250", "text": "Void Opal"},
  280. {"value": "139", "text": "Water"},
  281. {"value": "82", "text": "Water Purifiers"},
  282. {"value": "14", "text": "Wine"},
  283. {"value": "10207", "text": "Wreckage Components"},
  284. {"value": "81", "text": "Platinum"}
  285. ]
  286. },
  287. "ps1": {"label": "Near"},
  288. "pi10": {
  289. "label": "Order",
  290. "values": [
  291. {"value": "1", "text": "Best price"},
  292. {"value": "2", "text": "Best supply/demand"},
  293. {"value": "4", "text": "Last update"},
  294. {"value": "3", "text": "Distance"}
  295. ]
  296. },
  297. "pi11": {
  298. "label": "Max. System dist.",
  299. "values": [
  300. {"value": "0", "text": "Any"},
  301. {"value": "50", "text": "~ 50 Ly"},
  302. {"value": "100", "text": "~ 100 Ly"},
  303. {"value": "250", "text": "~ 250 Ly"},
  304. {"value": "500", "text": "~ 500 Ly"},
  305. {"value": "1000", "text": "~ 1k Ly"},
  306. {"value": "5000", "text": "~ 5k Ly"}
  307. ]
  308. },
  309. "pi3": {
  310. "label": "Landing pad",
  311. "values": [
  312. {"value": "1", "text": "S"},
  313. {"value": "2", "text": "M"},
  314. {"value": "3", "text": "L"}
  315. ]
  316. },
  317. "pi9": {
  318. "label": "Max. Station dist.",
  319. "values": [
  320. {"value": "0", "text": "Any"},
  321. {"value": "100", "text": "100 Ls"},
  322. {"value": "500", "text": "500 Ls"},
  323. {"value": "1000", "text": "1k Ls"},
  324. {"value": "2000", "text": "2k Ls"},
  325. {"value": "5000", "text": "5k Ls"},
  326. {"value": "10000", "text": "10k Ls"},
  327. {"value": "15000", "text": "15k Ls"},
  328. {"value": "20000", "text": "20k Ls"},
  329. {"value": "25000", "text": "25k Ls"},
  330. {"value": "50000", "text": "50k Ls"},
  331. {"value": "100000", "text": "100k Ls"}
  332. ]
  333. },
  334. "pi4": {
  335. "label": "Surface",
  336. "values": [
  337. {"value": "2", "text": "Yes"},
  338. {"value": "1", "text": "No"},
  339. {"value": "0", "text": "Yes (Ody)"}
  340. ]
  341. },
  342. "pi14": {
  343. "label": "Power",
  344. "values": [
  345. {"value": "-1", "text": "None"},
  346. {"value": "0", "text": "Any"},
  347. {"value": "1", "text": "Denton Patreus"},
  348. {"value": "2", "text": "Aisling Duval"},
  349. {"value": "3", "text": "Edmund Mahon"},
  350. {"value": "4", "text": "Arissa Lavigny-Duval"},
  351. {"value": "5", "text": "Felicia Winters"},
  352. {"value": "7", "text": "Li Yong-Rui"},
  353. {"value": "8", "text": "Zemina Torval"},
  354. {"value": "9", "text": "Pranav Antal"},
  355. {"value": "10", "text": "Archon Delaine"},
  356. {"value": "11", "text": "Yuri Grom"},
  357. {"value": "12", "text": "Jerome Archer"},
  358. {"value": "13", "text": "Nakato Kaine"}
  359. ]
  360. },
  361. "pi5": {
  362. "label": "Price age",
  363. "values": [
  364. {"value": "0", "text": "Any"},
  365. {"value": "1", "text": "1 h"},
  366. {"value": "8", "text": "8 h"},
  367. {"value": "16", "text": "16 h"},
  368. {"value": "24", "text": "1 d"},
  369. {"value": "48", "text": "2 d"},
  370. {"value": "72", "text": "3 d"},
  371. {"value": "168", "text": "7 d"},
  372. {"value": "336", "text": "14 d"},
  373. {"value": "720", "text": "30 d"},
  374. {"value": "4320", "text": "180 d"}
  375. ]
  376. },
  377. "pi12": {
  378. "label": "Price condition",
  379. "values": [
  380. {"value": "-1", "text": "Only anarchy black markets"},
  381. {"value": "0", "text": "No"},
  382. {"value": "5", "text": "± 5%"},
  383. {"value": "10", "text": "± 10%"},
  384. {"value": "25", "text": "± 25%"},
  385. {"value": "50", "text": "± 50%"}
  386. ]
  387. },
  388. "pi7": {
  389. "label": "Min. supply/demand",
  390. "values": [
  391. {"value": "0", "text": "Any"},
  392. {"value": "100", "text": "100"},
  393. {"value": "500", "text": "500"},
  394. {"value": "1000", "text": "1k"},
  395. {"value": "2500", "text": "2,5k"},
  396. {"value": "5000", "text": "5k"},
  397. {"value": "10000", "text": "10k"},
  398. {"value": "50000", "text": "50k"}
  399. ]
  400. },
  401. "pi8": {
  402. "label": "Fleet Carriers",
  403. "values": [
  404. {"value": "0", "text": "Yes"},
  405. {"value": "1", "text": "No"},
  406. {"value": "2", "text": "Yes (updated)"}
  407. ]
  408. },
  409. "pi13": {
  410. "label": "Stronghold Carriers",
  411. "values": [
  412. {"value": "0", "text": "Yes"},
  413. {"value": "1", "text": "No"},
  414. {"value": "2", "text": "Yes (Power)"}
  415. ]
  416. }
  417. };
  418.  
  419. // Template of the preset details.
  420. /* It supports "discord-like"-formatting for bold, italic, underlined and strikethrough.
  421. ** Following fields are available:
  422. Commodity: {pa1}
  423. Near star system: {ps1}
  424. Order by: {pi10}
  425. Max. star system distance: {pi11}
  426. Buy/Sell: {pi1}
  427. Min. landing pad: {pi3}
  428. Max. station distance: {pi9}
  429. Use surface stations: {pi4}
  430. Power: {pi14}
  431. Max. price age: {pi5}
  432. Price condition: {pi12}
  433. Min. supply/demand: {pi7}
  434. Include fleet carriers: {pi8}
  435. Include Stronghold carriers: {pi13}`
  436. **/
  437. const DETAILS_TEMPLATE =
  438. `**{pi1}:** {pa1}
  439.  
  440. **__Near: {ps1}__**
  441. **Pad:** {pi3} | **Surface:** {pi4} | **Price Age:** {pi5}
  442. **Min. Supply/Demand:** {pi7}
  443.  
  444. **Max. Distance** - **Star:** {pi11} | **Station:** {pi9}
  445. **FC:** {pi8} | **SC:** {pi13}
  446.  
  447. **Power:** {pi14}
  448. `;
  449.  
  450.  
  451.  
  452. /*** DO NOT CHANGE BELOW ***/
  453.  
  454.  
  455.  
  456. (function() {
  457. 'use strict';
  458.  
  459. const STORAGE_KEY = 'inara_search_presets';
  460.  
  461. let editMode = false
  462.  
  463. // Übersetzt den Parameterwert anhand des Mappings
  464. function translateParamValues(pKey, pValue) {
  465. if (fullMapping[pKey] && fullMapping[pKey].values) {
  466. const found = fullMapping[pKey].values.find(entry => entry.value === pValue);
  467. if (found) {
  468. return found.text
  469. } else {
  470. console.log("No mapping found", pKey, pValue)
  471. }
  472. }
  473. return pValue;
  474. }
  475.  
  476. // Modified: getTranslatedParams – für den Parameter "pi1" wird nur der rohe Wert übernommen.
  477. function getTranslatedParams(paramsStr) {
  478. const searchParams = new URLSearchParams(paramsStr);
  479. const obj = {};
  480. for (let [key, value] of searchParams.entries()) {
  481. const cleanKey = key.replace(/\[\]$/, '');
  482. const displayValue = translateParamValues(cleanKey, value)
  483.  
  484. if (cleanKey === "pa1") {
  485. // Mehrfach vorkommende Werte als Array speichern
  486. if (!obj[cleanKey]) {
  487. obj[cleanKey] = displayValue;
  488. } else {
  489. obj[cleanKey] += `, ${displayValue}`;
  490. }
  491. } else {
  492. obj[cleanKey] = displayValue;
  493. }
  494. }
  495. return obj;
  496. }
  497.  
  498. function applyFormatting(text) {
  499. // Reihenfolge ist wichtig: zuerst kombinierte Formatierungen, dann einzelne
  500. const rules = [
  501. { regex: /__\*\*\*(.*?)\*\*\*__/g, replacement: '<u><strong><em>$1</em></strong></u>' },
  502. { regex: /__\*\*(.*?)\*\*__/g, replacement: '<u><strong>$1</strong></u>' },
  503. { regex: /__\*(.*?)\*__/g, replacement: '<u><em>$1</em></u>' },
  504. { regex: /\*\*\*(.*?)\*\*\*/g, replacement: '<strong><em>$1</em></strong>' },
  505. { regex: /~~(.*?)~~/g, replacement: '<del>$1</del>' },
  506. { regex: /__(.*?)__/g, replacement: '<u>$1</u>' },
  507. { regex: /\*\*(.*?)\*\*/g, replacement: '<strong>$1</strong>' },
  508. { regex: /\*(.*?)\*/g, replacement: '<em>$1</em>' }
  509. ];
  510.  
  511. return rules.reduce((acc, rule) => acc.replace(rule.regex, rule.replacement), text);
  512. }
  513.  
  514. // Ersetzt Platzhalter im Template durch die entsprechenden Werte aus obj
  515. function applyTemplate(template, obj) {
  516. return template.replace(/{([^}]+)}/g, (match, key) => obj[key] || "");
  517. }
  518.  
  519. function getTemplate(paramsStr) {
  520. // Process params
  521. let template = convertParams(paramsStr)
  522. // Process formatting
  523. template = applyFormatting(template)
  524.  
  525. return template
  526. }
  527.  
  528. // Wandelt URL-Parameter in ein lesbares Format um – nutzt das definierte Template
  529. function convertParams(paramsStr) {
  530. const translatedParams = getTranslatedParams(paramsStr);
  531. return applyTemplate(DETAILS_TEMPLATE, translatedParams);
  532. }
  533.  
  534. // Lade vorhandene Presets aus localStorage
  535. function loadPresets() {
  536. const data = localStorage.getItem(STORAGE_KEY);
  537. console.debug("Loaded presets:", JSON.parse(data))
  538. return data ? JSON.parse(data) : [];
  539. }
  540.  
  541. // Speichere Presets in localStorage
  542. function savePresets(presets) {
  543. localStorage.setItem(STORAGE_KEY, JSON.stringify(presets));
  544. console.debug("Saved presets:", presets)
  545. }
  546.  
  547. // Toggling editing mode
  548. function toggleEditMode() {
  549. editMode = !editMode
  550.  
  551. const editables = document.querySelectorAll(".edit-only")
  552. for ( let i = 0; i < editables.length; i++ ) {
  553. editables[i].style.display = editMode ? "block" : "none";
  554. }
  555. }
  556.  
  557. // Rendere die Liste der Presets in einem Container
  558. function renderPresetList() {
  559. const maincontent = document.querySelector('.maincontent.block0');
  560. const form = maincontent.querySelector(".mainblockaction");
  561. let container = document.getElementById('preset-container');
  562.  
  563. if (!container) {
  564. container = document.createElement('div');
  565. container.id = 'preset-container';
  566. container.style.background = '#2a2a2a';
  567. container.style.padding = '10px';
  568. container.style.fontSize = '14px';
  569. container.style.lineHeight = '1.4';
  570. container.style.borderRadius = '4px';
  571. container.style.marginTop = '10px';
  572. // Füge den Container vor dem Formular ein
  573. maincontent.insertBefore(container, form);
  574. }
  575.  
  576. // Container leeren und Header hinzufügen
  577. container.innerHTML = '';
  578. const headerDiv = document.createElement('div');
  579. headerDiv.style.display = 'flex';
  580. headerDiv.style.justifyContent = 'space-between';
  581. headerDiv.style.alignItems = 'center';
  582. headerDiv.style.marginBottom = '10px';
  583.  
  584. const title = document.createElement('h3');
  585. title.textContent = 'Search Presets';
  586. headerDiv.appendChild(title);
  587.  
  588. // Container für die Buttons (erste Zeile)
  589. const presetCRUDrow = document.createElement('div');
  590. presetCRUDrow.style.display = 'flex';
  591. presetCRUDrow.style.gap = '5px';
  592.  
  593. const editBtn = document.createElement('button');
  594. editBtn.textContent = 'Edit';
  595. editBtn.style.fontSize = '12px';
  596. editBtn.style.width = '70px';
  597. editBtn.style.background = "#4d5d66";
  598. editBtn.addEventListener('click', toggleEditMode);
  599. presetCRUDrow.appendChild(editBtn);
  600.  
  601. const saveBtn = document.createElement('button');
  602. saveBtn.textContent = 'Save Preset';
  603. saveBtn.style.fontSize = '12px';
  604. saveBtn.stylewidth = '200px';
  605. saveBtn.addEventListener('click', addPreset);
  606. presetCRUDrow.appendChild(saveBtn);
  607.  
  608. headerDiv.appendChild(presetCRUDrow);
  609. container.appendChild(headerDiv);
  610.  
  611. // Add horizontal divider
  612. const line = document.createElement("hr")
  613. container.appendChild(line);
  614.  
  615. // Container für die Presets als Flexbox
  616. const listDiv = document.createElement('div');
  617. listDiv.style.display = 'flex';
  618. listDiv.style.flexWrap = 'wrap';
  619. listDiv.style.justifyContent = 'space-evenly';
  620. listDiv.style.gap = '5px';
  621. listDiv.style.maxHeight = '230px';
  622. listDiv.style.overflowY = 'auto';
  623. container.appendChild(listDiv);
  624.  
  625. const presets = loadPresets();
  626. if (presets.length === 0) {
  627. const noPreset = document.createElement('em');
  628. noPreset.textContent = 'No presets found';
  629. listDiv.appendChild(noPreset);
  630. } else {
  631. presets.forEach((preset, index) => {
  632. const presetDiv = document.createElement('div');
  633. // Preset-Div als Spalte, damit Details darunter angezeigt werden
  634. presetDiv.style.display = 'flex';
  635. presetDiv.style.flexDirection = 'column';
  636. presetDiv.style.background = '#353331';
  637. presetDiv.style.borderRadius = '4px';
  638. presetDiv.style.padding = '3px 5px';
  639. presetDiv.style.minWidth = '150px';
  640. presetDiv.style.maxWidth = '250px';
  641. presetDiv.style.width = '33%';
  642.  
  643. // Container für die Buttons (erste Zeile)
  644. const buttonRow = document.createElement('div');
  645. buttonRow.style.display = 'flex';
  646. buttonRow.style.alignItems = 'center';
  647.  
  648. const indexInput = document.createElement('input');
  649. indexInput.type = "number"
  650. indexInput.value = index
  651. indexInput.style.width = "25px";
  652. indexInput.style.padding = "0";
  653. indexInput.style.margin = "0 3px 0 0";
  654. indexInput.style.background = "none";
  655. indexInput.style.color = "#fff";
  656. indexInput.style.textAlign = "center";
  657. indexInput.style.outline = "none";
  658. indexInput.style.textDecoration = "underline";
  659. indexInput.classList.add("edit-only");
  660. indexInput.style.display = "none"
  661. buttonRow.appendChild(indexInput);
  662.  
  663. const loadBtn = document.createElement('button');
  664. loadBtn.textContent = preset.name;
  665. loadBtn.style.fontSize = '12px';
  666. loadBtn.style.lineHeight = '15px';
  667. loadBtn.addEventListener('click', () => {
  668. window.location.search = preset.params;
  669. });
  670. buttonRow.appendChild(loadBtn);
  671.  
  672. const delBtn = document.createElement('button');
  673. delBtn.textContent = '✕';
  674. delBtn.style.fontSize = '10px';
  675. delBtn.style.padding = '2px 5px';
  676. delBtn.style.maxWidth = '25px';
  677. delBtn.style.marginLeft = '3px';
  678. delBtn.classList.add("edit-only");
  679. delBtn.style.display = "none"
  680. delBtn.addEventListener('click', () => {
  681. if (confirm(`Delete Preset: "${preset.name}" ?`)) {
  682. presets.splice(index, 1);
  683. savePresets(presets);
  684. renderPresetList();
  685. }
  686. });
  687. buttonRow.appendChild(delBtn);
  688.  
  689. presetDiv.appendChild(buttonRow);
  690.  
  691. // Details-Div (zweite Zeile) mit dem benutzerdefinierten Template
  692. if (showPresetDetails) {
  693. const detailsDiv = document.createElement('div');
  694. detailsDiv.style.fontSize = '12px';
  695. detailsDiv.style.marginTop = '5px';
  696. detailsDiv.style.whiteSpace = 'pre-wrap';
  697. detailsDiv.style.wordBreak = 'break-all';
  698. detailsDiv.innerHTML = getTemplate(preset.params);
  699. presetDiv.appendChild(detailsDiv);
  700. }
  701.  
  702. listDiv.appendChild(presetDiv);
  703. });
  704. }
  705. }
  706.  
  707. // Funktion, um ein neues Preset zu speichern
  708. function addPreset() {
  709. const presetName = prompt('Name of this preset:');
  710. if (!presetName) return;
  711. const currentParams = window.location.search;
  712. const presets = loadPresets();
  713. presets.push({
  714. name: presetName,
  715. params: currentParams
  716. });
  717. savePresets(presets);
  718. renderPresetList();
  719. }
  720.  
  721. // Initialisierung
  722. function init() {
  723. renderPresetList();
  724. }
  725.  
  726. window.addEventListener('load', init);
  727. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址