Skip to content

Instantly share code, notes, and snippets.

@Cougar
Created August 18, 2023 16:49
Show Gist options
  • Save Cougar/0d501b59c72e7a656c89cdc71c9bf5b6 to your computer and use it in GitHub Desktop.
Save Cougar/0d501b59c72e7a656c89cdc71c9bf5b6 to your computer and use it in GitHub Desktop.
Violentmonkey script to add m² price to plywood pricelist
// ==UserScript==
// @name Show m2 price - vineerimaailm.ee
// @namespace Violentmonkey Scripts
// @match https://vineerimaailm.ee/outlet
// @grant none
// @version 1.0
// @author Cougar
// @description 8/18/2023, 4:34:14 PM
// ==/UserScript==
window.updateTable = function() {
if (document.getElementById("m2price")) {
return;
}
var table = $("#resHTML").find("table");
$('<col style="width: 160px;">').insertAfter($(table.find("colgroup > col:eq(7)")));
$('<th id="m2price"><strong>HIND (EUR/m²)</strong></th>').insertAfter($(table.find("thead > tr > th:eq(7)")));
$(table).find("tbody > tr").each(function(i) {
var processElement = $(this);
var t = $(this).find(".thick").html();
var l = $(this).find(".length").html();
var w = $(this).find(".width").html();
var p = $(this).find(".price").html().trim().slice(0,-1).replace(',', '.');
var m2 = (p / (l * w / 1000000));
var m2t = (m2 / t) * 6;
$('<td class="m2price">' + m2.toFixed(2).replace('.', ',') + '€ (' + m2t.toFixed(2).replace('.', ',') + ')</td>').insertAfter($(this).find(".price"));
})
}
$(document).ready(function() {
$('<h1><button type="button" class="btn" onclick="updateTable()">Näita m² hind</button></h1>').insertBefore("#resHTML");
updateTable();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment