Better SGS

Visar avstånd till Chalmers på sgs hemsida

目前為 2021-05-26 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Better SGS
// @namespace   Better SGS by C4illin
// @match       https://marknad.sgs.se/pgSearchResult.aspx*
// @grant       none
// @version     1.1
// @author      C4illin
// @run-at      document-idle
// @description Visar avstånd till Chalmers på sgs hemsida
// ==/UserScript==


let refresh = setInterval(() => {
  let hash = window.location.hash.split("&take")
  if (hash[1] != "=1000000") {
    hash[1] = "=1000000"
    let newlink = "https://marknad.sgs.se"+ window.location.pathname + window.location.search + hash.join("&take")
    window.location.replace(newlink)
  }
  let value = document.querySelector("#selected-take").value
  if (value != null){
    clearInterval(refresh)

    let distance = {
      "Kustgatan":5,
      "Birger Jarl":4.5,
      "Brahegatan":6.3,
      "Ekbacka":8.2,
      "Fridhemsgatan":5.6,
      "Gibraltar":1.1,
      "Guldhedstornet":1.4,
      "Gårda Fabriker":2.9,
      "Husaren":2,
      "Högsbohöjd":5.5,
      "Kaverös":5.5,
      "Kjellmansgatan":3.4,
      "Kronhusgatan":2.7,
      "Kungsladugård":5.2,
      "Helmotsrogatan":2.2,
      "Dr Forselius Backe":2,
      "Centrala Hisingen":6.5,
      "Nya Varvet":7.2,
      "Ostkupan":3.0,
      "Pennygången":5.0,
      "Plejaden":6.9,
      "Postgatan":2.8,
      "Rosendal":6,
      "Selma":9.1,
      "Rotary":1,
      "Tredje Långgatan":2.6,
      "Norra Ågatan":3.6,
      "Östra Kålltorp":5.6
    }

    let table = document.querySelector("table.table.table-striped")
    let tableH = document.createElement("th")
    tableH.innerHTML = "till Chalmers"
    table.children[0].children[0].appendChild(tableH)

    table.children[0].children[0].children[8].style.display = "none" // hide where it is from torget etc

    let tr = table.children[1].children

    for (let i = 0; i < tr.length; i++) {
      tr[i].children[8].style.display = "none"
      let address = tr[i].children[1].innerHTML
      let distelem = document.createElement("td")
      if (distance[address]) {
        distelem.innerHTML = (distance[address] + " km").replace(".",",")
      } else {
        distelem.innerHTML = ""
      }
      tr[i].appendChild(distelem)
    }
  }
}, 1000)

// table tr > *:nth-child(2) {
//   display: none;
// }