Better SGS

Visar avstånd till Chalmers på sgs hemsida

当前为 2021-05-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Better SGS
  3. // @namespace Better SGS by C4illin
  4. // @match https://marknad.sgs.se/pgSearchResult.aspx*
  5. // @grant none
  6. // @version 1.0
  7. // @author C4illin
  8. // @run-at document-idle
  9. // @description Visar avstånd till Chalmers på sgs hemsida
  10. // ==/UserScript==
  11.  
  12.  
  13. let refresh = setInterval(() => {
  14. let hash = window.location.hash.split("&take")
  15. if (hash[1] != "=1000000") {
  16. hash[1] = "=1000000"
  17. let newlink = "https://marknad.sgs.se"+ window.location.pathname + window.location.search + hash.join("&take")
  18. window.location.replace(newlink)
  19. }
  20. let value = document.querySelector("#selected-take").value
  21. if (value != null){
  22. clearInterval(refresh)
  23.  
  24. let distance = {
  25. "Kustgatan":5,
  26. "Birger Jarl":4.5,
  27. "Brahegatan":6.3,
  28. "Ekbacka":8.2,
  29. "Fridhemsgatan":5.6,
  30. "Gibraltar":1.1,
  31. "Guldhedstornet":1.4,
  32. "Gårda Fabriker":2.9,
  33. "Husaren":2,
  34. "Högsbohöjd":5.5,
  35. "Kaverös":5.5,
  36. "Kjellmansgatan":3.4,
  37. "Kronhusgatan":2.7,
  38. "Kungsladugård":5.2,
  39. }
  40.  
  41. let table = document.querySelector("table.table.table-striped")
  42. let tableH = document.createElement("th")
  43. tableH.innerHTML = "till Chalmers"
  44. table.children[0].children[0].appendChild(tableH)
  45.  
  46. table.children[0].children[0].children[8].style.display = "none" // hide where it is from torget etc
  47.  
  48. let tr = table.children[1].children
  49.  
  50. for (let i = 0; i < tr.length; i++) {
  51. tr[i].children[8].style.display = "none"
  52. let address = tr[i].children[1].innerHTML
  53. let distelem = document.createElement("td")
  54. if (distance[address]) {
  55. distelem.innerHTML = (distance[address] + " km").replace(".",",")
  56. } else {
  57. distelem.innerHTML = ""
  58. }
  59. tr[i].appendChild(distelem)
  60. }
  61. }
  62. }, 1000)
  63.  
  64. // table tr > *:nth-child(2) {
  65. // display: none;
  66. // }