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

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

View File

@ -0,0 +1,29 @@
// ==UserScript==
// @name Alternate HDD Price per TB
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Alternate HDD Price per TB
// @author sergio.am
// @match https://www.alternate.es/Discos-duros*
// @icon https://www.google.com/s2/favicons?sz=64&domain=alternate.es
// @grant none
// ==/UserScript==
(function() {
'use strict';
const re = /\w+\s/g;
$('head').append("<style>.pricePerTb { color:blue; padding-left: 20px; }</style>");
$('.grid-container.listing a.card').each(function (idx, item) {
var price = parseFloat($(item).find('span.price').text().replace('€', ''));
var name = $(item).find('div.product-name').text();
var cap = $(item).find('ul.product-info li:first-of-type').text();
var tb = parseInt(cap.match(/Capacidad: (\d+) TB/)[1]);
var pricePerTb = price / tb;
$(item).find('span.price').append('<span class="pricePerTb">' + pricePerTb.toFixed(1) + ' €/TB</span>');
});
})();