From ef910e63c4d879e3ca7f310bfe8b16762a00281b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20=C3=81lvarez?= Date: Mon, 27 Feb 2023 14:30:14 +0000 Subject: [PATCH] Add 'alternate-price-per-tera.js' --- alternate-price-per-tera.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 alternate-price-per-tera.js diff --git a/alternate-price-per-tera.js b/alternate-price-per-tera.js new file mode 100644 index 0000000..ba6ac39 --- /dev/null +++ b/alternate-price-per-tera.js @@ -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(""); + + $('.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('' + pricePerTb.toFixed(1) + ' €/TB'); + }); +})(); \ No newline at end of file