Last active
December 3, 2023 17:41
-
-
Save abjugard/def0a515b21a71f12ff539cc8227a1c3 to your computer and use it in GitHub Desktop.
booli.se - KVM-priser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name booli.se - KVM-priser | |
// @namespace Violentmonkey Scripts | |
// @match https://www.booli.se/sok/slutpriser | |
// @grant none | |
// @version 1.1 | |
// @author Adrian Bjugård | |
// @icon https://www.google.com/s2/favicons?domain=booli.se | |
// @grant none | |
// @updateURL https://gist.githubusercontent.com/abjugard/def0a515b21a71f12ff539cc8227a1c3/raw/booli-kvmpricing.user.js | |
// @downloadURL https://gist.githubusercontent.com/abjugard/def0a515b21a71f12ff539cc8227a1c3/raw/booli-kvmpricing.user.js | |
// ==/UserScript== | |
const setKvmPrices = () => { | |
document.querySelectorAll('.object-card__content').forEach(card => { | |
const propsList = card.querySelector('ul'); | |
if (propsList.textContent.indexOf('kr/m²') >= 0) { | |
return; | |
} | |
const priceEl = card.querySelector('span.heading-3.box-content'); | |
const priceStr = priceEl.textContent.replaceAll(' ', ''); | |
const price = Number(priceStr.slice(0, -2)); | |
const sizeEl = propsList.querySelector(':first-child'); | |
const size = Number(sizeEl.textContent.slice(0,-3)); | |
const kvmPrice = price / size; | |
const nFormat = new Intl.NumberFormat(); | |
const kvmPriceEl = sizeEl.cloneNode(true); | |
kvmPriceEl.textContent = `${nFormat.format(kvmPrice.toFixed())} kr/m²`; | |
propsList.appendChild(kvmPriceEl); | |
}); | |
} | |
(function() { | |
'use strict'; | |
setInterval(setKvmPrices, 100); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment