Add 'pccomponentes-price-per-tera.js'

This commit is contained in:
Sergio Álvarez 2023-02-27 14:30:43 +00:00
parent ef910e63c4
commit fc2b8ad145
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
// ==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>');
});
})();