Last active
November 26, 2023 18:15
-
-
Save CezaryDanielNowak/d477e1a4cab894b337f2634628303c06 to your computer and use it in GitHub Desktop.
This file contains 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 ZGN kalkulator | |
// @namespace ZGN | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match */seizbil/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=zgnpragapld.pl | |
// @grant none | |
// @run-at document-end | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function getTDByText(searchText) { | |
const el = Array.from(document.body.querySelectorAll('td')) | |
.filter((elm) => elm.textContent.toLowerCase().includes(searchText)); | |
return el.length ? el[0] : null; | |
} | |
function getNumValue(td) { | |
if (td) { | |
return Number.parseFloat( | |
td.nextElementSibling.innerText.match(/[0-9,]/g).map((char) => char === ',' ? '.' : char).join('') | |
); | |
} | |
} | |
let cena; | |
try { | |
var cenaTD = getTDByText('minimalna stawka za m2 pow. podst. netto'); | |
cena = getNumValue(cenaTD); | |
} catch(e) { | |
return; | |
} | |
try { | |
var powierzchniaUzytkowaTD = getTDByText('powierzchnia użytkowa'); | |
var powierzchniaUzytkowa = getNumValue(powierzchniaUzytkowaTD); | |
const uzytkowaNetto = powierzchniaUzytkowa * cena; | |
powierzchniaUzytkowaTD.nextElementSibling.innerText += ` (${uzytkowaNetto.toFixed(2)} zł NETTO, ${(uzytkowaNetto*1.23).toFixed(2)} zł BRUTTO)`; | |
} catch(e) {} | |
try { | |
var powierzchniaCalkowitaTD = getTDByText('powierzchnia całkowita'); | |
var powierzchniaCalkowita = getNumValue(powierzchniaCalkowitaTD); | |
const calkowitaNetto = powierzchniaCalkowita * cena; | |
powierzchniaCalkowitaTD.nextElementSibling.innerText += ` (${calkowitaNetto.toFixed(2)} zł NETTO, ${(calkowitaNetto*1.23).toFixed(2)} zł BRUTTO)`; | |
} catch(e) {} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment