Soldato
- Joined
- 29 Aug 2010
- Posts
- 8,321
- Location
- Cornwall
Ive got an idea for you if you fancy making another:
A script to calculate the £/GB of SSD's
So it can look at the price and the description ***GB and £**.** and calculate the £*.**/GB
![]()
This code should do it, it's not my best work though:
Code:
var table = document.getElementById("productList");
for (var i = 0; i < table.rows.length; i++) {
var size = table.rows[i].cells.item(1).innerHTML.match(/\d+(GB|TB)/);
if (size != null) {
var ssdSize = size[0];
var price = parseFloat(table.rows[i].cells.item(4).innerHTML.match(/<span class=\"price\">£\d+\.\d+/)[0].replace(/<span class=\"price\">£/, '').replace(/,/g, '').replace(/[\(\)]/, ''));
var sizeInGB = parseFloat(ssdSize.replace("GB", "").replace("TB", "000"));
var pricePerGB = price/sizeInGB;
table.rows[i].cells.item(4).innerHTML = table.rows[i].cells.item(4).innerHTML.concat("<span style=\"font-size: 16pt; color: red\">" + '£' + pricePerGB.toFixed(2) + '/GB' + "</span>");
}
}
For a bookmarklet thingy you could use:
Code:
javascript:(function(){var%20table%20=%20document.getElementById("productList");%20for%20(var%20i%20=%200;%20i%20<%20table.rows.length;%20i++)%20{%20%20%20var%20size%20=%20table.rows[i].cells.item(1).innerHTML.match(/\d+(GB|TB)/);%20%20%20if%20(size%20!=%20null)%20{%20%20%20%20%20var%20ssdSize%20=%20size[0];%20%20%20%20%20var%20price%20=%20parseFloat(table.rows[i].cells.item(4).innerHTML.match(/<span%20class=\"price\">%C2%A3\d+\.\d+/)[0].replace(/<span%20class=\"price\">%C2%A3/,%20'').replace(/,/g,%20'').replace(/[\(\)]/,%20''));%20%20%20%20%20var%20sizeInGB%20=%20parseFloat(ssdSize.replace("GB",%20"").replace("TB",%20"000"));%20%20%20%20%20var%20pricePerGB%20=%20price/sizeInGB;%20%20%20%20%20table.rows[i].cells.item(4).innerHTML%20=%20table.rows[i].cells.item(4).innerHTML.concat("<span%20style=\"font-size:%2016pt;%20color:%20red\">"%20+%20'%C2%A3'%20+%20pricePerGB.toFixed(2)%20+%20'/GB'%20+%20"</span>");%20%20%20}%20}})();
EDIT: If it wasn't obvious you really need to be on the SSD or HDD page for this to work
Last edited: