// ==UserScript== // @name sct_add_buffer.js // @namespace http://example.org // @description adds information about your current buffer(sct-version) // @include http://www.scenetorrents.org/* // @include http://scenetorrents.org/* // @include https://scenetorrents.org/* // @include https://www.scenetorrents.org/* // ==/UserScript== (function(){ if(location.hostname.indexOf('scenetorrents.org') == -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 = numbers; break; } return gigabytes; } function _t(e) { try{ var downloadNode = getNodes('//table//td[@class="layout"]//span[text()="Downloaded:"]').snapshotItem(0); if(!downloadNode){ alert('ikke funnet');return;} var dl = downloadNode.nextSibling; if(dl.nodeType == 3) { dl = dl.nextSibling; } var uploadNode = getNodes('//table//td[@class="layout"]//span[text()="Uploaded:"]').snapshotItem(0); if(!uploadNode){ return;} var ul = uploadNode.nextSibling; if(ul.nodeType == 3) { ul = ul.nextSibling; } var uploaded = getGigaBytes(ul.textContent); var downloaded = getGigaBytes(dl.textContent); var container = document.createElement('span'); var labelContainer = document.createElement('span'); labelContainer.style.color='purple'; labelContainer.appendChild(document.createTextNode(' Buffer: ')); container.appendChild(labelContainer); if(downloaded >= uploaded) { container.appendChild(document.createTextNode('---')); } else { var buffer = Math.round((uploaded-downloaded)*100)/100;//always in GB, two decimals container.appendChild(document.createTextNode( buffer+ ' GB')); } container.appendChild(document.createTextNode(' ')); //insert before activeTorrentsNode dl.parentNode.insertBefore(container, dl.nextSibling); }catch(e) { alert('feil: ' + e) } } if(window.opera) { window.addEventListener('DOMContentLoaded', _t, false); } else { window.addEventListener('load', _t, false); } })();