gist/pccomponentes-price-per-ter...

29 lines
1.0 KiB
JavaScript

// ==UserScript==
// @name PCComponentes HDD Price per TB
// @namespace http://tampermonkey.net/
// @version 0.1
// @description AltePCComponentesrnate HDD Price per TB
// @author sergio.am
// @match https://www.pccomponentes.com/discos-duros*
// @icon https://www.google.com/s2/favicons?sz=64&domain=pccomponentes.com
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
const re = /\w+\s/g;
$('head').append("<style>.pricePerTb { color:blue; padding-left: 20px; font-size: 1.25rem; }</style>");
$('div#product-grid a').each(function (idx, item) {
var price = parseFloat($(item).data('product-price'));
var name = $(item).data('product-name');
var tb = parseInt(name.match(/(\d+) ?TB/)[1]);
var pricePerTb = price / tb;
$(item).find('.product-card__price-container').append('<span class="pricePerTb">' + pricePerTb.toFixed(1) + ' €/TB</span>');
});
})();