// ==UserScript== // @name quackulator.js // @namespace http://example.org // @description tells you your new ratio if you download a torrent without seeding // @include http://www.norbits.net/details.php?id=* // @include http://norbits.net/details.php?id=* // @include https://www.norbits.net/details.php?id=* // @include https://norbits.net/details.php?id=* // ==/UserScript== (function(){ if(location.hostname.indexOf('norbits.net') == -1 || location.pathname.indexOf('/details.php') == -1) { return false; } function getNodes(expression, startElement) { startElement = startElement || document; var nodes = document.evaluate( expression, startElement, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null ); return nodes; } function trim(str) { return str.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); } function getGigaBytes(text){ var gigabytes, numbers, suffix; text = trim(text); if(text == 'Inf.' || text == '---') { return 0; } var _tmp = text.split(' '); numbers = Number(_tmp[0]); suffix = _tmp[1]; //alert('suffix er: "' + suffix + "'") switch(suffix){ case 'GB': gigabytes = numbers; break; case 'TB': gigabytes = numbers*1024; break; case 'MB': gigabytes = numbers*0.0009765625; break; case 'kB': //no point in doing calculations with that low numbers gigabytes = 0; break; default: gigabytes = 0; break; } return gigabytes; } function _t(e) { try { var tableRow = getNodes('//tr//td[@class="rowhead" and' + ' contains(text(), "St") and contains(text(), "rrelse")]/..').snapshotItem(0); if(!tableRow) { return; } //Størrelse5.48 GB (5,887,848,401 bytes) var sizeNode = getNodes('.//td[2]', tableRow).snapshotItem(0); if(!sizeNode) { return; } var activeTorrentsNode = getNodes('//font[text()="Akt:"]').snapshotItem(0); if(!activeTorrentsNode){ return;} var uploadNode = getNodes('//font[text()="Opp:"]').snapshotItem(0); if(!uploadNode){ return;} var uploaded = getGigaBytes(uploadNode.nextSibling.textContent);//always in GB var downloadNode = getNodes('//font[text()="Ned:"]').snapshotItem(0); if(!downloadNode){ return;} var downloaded = getGigaBytes(downloadNode.nextSibling.textContent);//always in GB //Størrelse5.48 GB (5,887,848,401 bytes) var size = getGigaBytes(sizeNode.textContent); var newDownload = Number(downloaded)+ Number(size); var newRatio = ''; if(uploaded !=0) { newRatio = (uploaded/newDownload).toFixed(2); } else { newRatio = '---'; } var arow = document.createElement('tr'); var cell1 = document.createElement('td'); cell1.className = 'rowhead'; cell1.appendChild(document.createTextNode('Quackulator')); arow.appendChild(cell1); var cell2 = document.createElement('td'); cell2.vAlign='top'; cell2.align = 'left'; cell2.appendChild(document.createTextNode(newRatio + '<-- ny ratio hvis du laster ned denne uten å seede noe')); arow.appendChild(cell2); tableRow.parentNode.insertBefore(arow, tableRow.nextSibling); } catch(e) { alert('feil: ' + e) } } if(window.opera) { window.addEventListener('DOMContentLoaded', _t, false); } else { window.addEventListener('load', _t, false); } })();