⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 btg.js

📁 LINUX下
💻 JS
📖 第 1 页 / 共 4 页
字号:
function createTorrentControls(s, d){	/* Start/Stop button */	if(s.status == ts_checking || s.status == ts_connecting || s.status == ts_downloading || s.status == ts_seeding)	{		// Add a stop button		var b = createButton('Stop');		b.contextID = s.contextID;		b.onclick = function(){contextStop(this.contextID);}		d.appendChild(b);	}	else if(s.status == ts_stopped || s.status == ts_finished)	{		// Add a start button		var b = createButton('Start');		b.contextID = s.contextID;		b.onclick = function(){contextStart(this.contextID);}		d.appendChild(b);	}	/* Abort/Clean button */	if(s.status == ts_checking || s.status == ts_connecting || s.status == ts_downloading || s.status == ts_stopped)	{		// Add a abort button		var b = createButton('Abort');		b.contextID = s.contextID;		b.onclick = function(){contextAbort(this.contextID);}		d.appendChild(b);	}	else if(s.status == ts_seeding || s.status == ts_finished)	{		// Add a abort button		var b = createButton('Abort');		b.contextID = s.contextID;		b.onclick = function(){contextAbort(this.contextID);}		d.appendChild(b);		// Add a clean button		b = createButton('Clean');		b.contextID = s.contextID;		b.onclick = function(){contextClean(this.contextID);}		d.appendChild(b);	}}/** * Create a table for details. * @return A HTMLTableElement. */function createTorrentDetails(){	var tbl = document.createElement('table');	tbl.className='extrainfo';	/* First row , Torrent filename, filesize and seeders */	var r = tbl.insertRow(-1);	r.className='extra_uneven_row';	var c = r.insertCell(-1);	c.className = 'extrainfo_type';	c.innerHTML = "Status:";	c = r.insertCell(-1);	c.className = 'extrainfo_value';	c.colSpan = 5;   /* */   r = tbl.insertRow(-1);	r.className='extra_even_row';   var c = r.insertCell(-1);	c.className = 'extrainfo_type';	c.innerHTML = "";   c = r.insertCell(-1);	c.className = 'extrainfo_value';	c.colSpan = 5;	c.innerHTML = "";   /* */	r = tbl.insertRow(-1);	r.className='extra_uneven_row';	c = r.insertCell(-1);	c.className = 'extrainfo_type';	c.innerHTML='Torrent Filename:';	c = r.insertCell(-1);	c.className = 'extrainfo_value';	c = r.insertCell(-1);	c.className = 'extrainfo_type extrainfo_divider';	c.innerHTML='Filesize:';	c = r.insertCell(-1);	c.className = 'extrainfo_value';	c = r.insertCell(-1);	c.className = 'extrainfo_type extrainfo_divider';	c.innerHTML='Seeders:';	c = r.insertCell(-1);	c.className = 'extrainfo_value';	/* Second row , Uploaded, Upload speed, Leechers */	r = tbl.insertRow(-1);	r.className='extra_even_row';	c = r.insertCell(-1);	c.className = 'extrainfo_type';	c.innerHTML='Upload Speed:';	c = r.insertCell(-1);	c.className = 'extrainfo_value';	c = r.insertCell(-1);	c.className = 'extrainfo_type extrainfo_divider';	c.innerHTML='Uploaded:';	c = r.insertCell(-1);	c.className = 'extrainfo_value';	c = r.insertCell(-1);	c.className = 'extrainfo_type extrainfo_divider';	c.innerHTML='Leechers:';	c = r.insertCell(-1);	c.className = 'extrainfo_value';	/* Third row , Downloaded, download speed, total progress */	r = tbl.insertRow(-1);	r.className='extra_uneven_row';	c = r.insertCell(-1);	c.className = 'extrainfo_type';	c.innerHTML='Download Speed:';	c = r.insertCell(-1);	c.className = 'extrainfo_value';	c = r.insertCell(-1);	c.className = 'extrainfo_type extrainfo_divider';	c.innerHTML='Downloaded:';	c = r.insertCell(-1);	c.className = 'extrainfo_value';	c = r.insertCell(-1);	c.className = 'extrainfo_type extrainfo_divider';	c.innerHTML='Total progress:';	c = r.insertCell(-1);	c.className = 'extrainfo_value';	return tbl;}/** * Create a table for extended controls. * @return A HTMLTableElement. */function createTorrentExtendedControls(contextID){	var ctrl = document.createElement("table");	ctrl.className='extendedcontrol';	var cr = ctrl.insertRow(-1);	var cc = cr.insertCell(-1);	cc.innerHTML = "Upload Limit (KB/s):";	cc = cr.insertCell(-1);	var ct = document.createElement('input');	ct.className='textinput';	ct.id = "txtUploadLimit_"+contextID;	ct.type="text";	cc.appendChild(ct);	cc = cr.insertCell(-1);	cc.innerHTML = "Seed Limit (%):"	cc = cr.insertCell(-1);	ct = document.createElement('input');	ct.className='textinput';	ct.id = "txtSeedLimit_"+contextID;	ct.type="text";	cc.appendChild(ct);	cc = cr.insertCell(-1);	cr = ctrl.insertRow(-1);	cc = cr.insertCell(-1);	cc.innerHTML = "Download Limit (KB/s):";	cc = cr.insertCell(-1);	ct = document.createElement('input');	ct.className='textinput';	ct.id = "txtDownloadLimit_"+contextID;	ct.type="text";	cc.appendChild(ct);	cc = cr.insertCell(-1);	cc.innerHTML = "Seed Timeout (minutes):";	cc = cr.insertCell(-1);	ct = document.createElement('input');	ct.className='textinput';	ct.id = "txtSeedTimeout_"+contextID;	ct.type="text";	cc.appendChild(ct);	cc = cr.insertCell(-1);	ct = createButton('Save');	ct.contextID = contextID;	ct.onclick = function(){saveContextLimit(this.contextID);};	cc.appendChild(ct);	return ctrl;}/** * Update a details table created by createTorrentDetailsTable(). * @param t The HTMLTableElement to be updated. * @param s The Status object containing the information to put in the table. */function updateTorrentDetails(t, s){	var f = s.filename;	if(f.length > 60)		f = f.substr(0,60) + '...';	t.rows[0].cells[1].innerHTML = s.statusMessage;   /* Amount of time this torrent has been downloading or seeding. */   /* TODO: convert to days:hours:minutes. */   if (s.status == ts_downloading)	{		t.rows[1].cells[0].innerHTML = "Download time";		t.rows[1].cells[1].innerHTML = s.activitycounter + " minutes";	}   else if (s.status == ts_seeding)	{		t.rows[1].cells[0].innerHTML = "Seed time";		t.rows[1].cells[1].innerHTML = s.activitycounter + " minutes";	}   else	{		t.rows[1].cells[0].innerHTML = "";		t.rows[1].cells[1].innerHTML = "";	}	t.rows[2].cells[1].innerHTML = f;	t.rows[2].cells[1].title = s.filename;	t.rows[2].cells[3].innerHTML = humanizeSize(s.filesize,2);	t.rows[2].cells[5].innerHTML = s.seeders;	t.rows[3].cells[1].innerHTML = humanizeSpeed(s.uploadrate,1);	t.rows[3].cells[3].innerHTML = humanizeSize(s.uploadtotal,2);	t.rows[3].cells[5].innerHTML = s.leechers;	t.rows[4].cells[1].innerHTML = humanizeSpeed(s.downloadrate ,1);	t.rows[4].cells[3].innerHTML = humanizeSize(s.downloadtotal ,2);	t.rows[4].cells[5].innerHTML = RoundToNdp(s.done,1)+'%';}/************************************************** * Status object. * This object represents a context (torrent) with  * some data about it. **************************************************/ts_undefined = 0;	ts_queued = 1;	ts_checking	= 2;ts_connecting = 3;ts_downloading = 4;ts_seeding = 5;	ts_stopped = 6;ts_finished = 7;function Status(dom){	this.contextID = -1;	this.filename = "";	this.status = 0;	this.statustext = "";	this.downloadTotal = 0;	this.uploadTotal = 0;	this.failedBytes = 0;	this.downloadRate = 0;	this.uploadRate = 0;	this.done = 0;	this.filesize = 0;	this.leechers = 0;	this.seeders = 0;	this.timeleft = "";	this.trackerstatus = "";	this.trackerstatustext = "";	this.trackerstatusmessage = "";	this.activitycounter = 0;	if(dom)	{		<!-- Defaults set, try to parse dom -->		this.contextID = parseInt(getFirstChildValue(dom, 'id'))		this.filename = getFirstChildValue(dom, 'filename')		this.status = parseInt(getFirstChildValue(dom, 'status'))		this.statustext = parseInt(getFirstChildValue(dom, 'statustext'))		this.downloadtotal = parseInt(getFirstChildValue(dom, 'downloadtotal'))		this.uploadtotal = parseInt(getFirstChildValue(dom, 'uploadtotal'))		this.failedbytes = parseInt(getFirstChildValue(dom, 'failedbytes'))		this.uploadrate = parseInt(getFirstChildValue(dom, 'uploadrate'))		this.downloadrate = parseInt(getFirstChildValue(dom, 'downloadrate'))		this.done = parseInt(getFirstChildValue(dom, 'done'))		this.filesize = parseInt(getFirstChildValue(dom, 'filesize'))		this.leechers = parseInt(getFirstChildValue(dom, 'leechers'))		this.seeders = parseInt(getFirstChildValue(dom, 'seeders'))		this.timeleft = getFirstChildValue(dom, 'timeleft')		this.trackerstatus = getFirstChildValue(dom, 'trackerstatus')		this.trackerstatustext = getFirstChildValue(dom, 'trackerstatustext')		this.trackerstatusmessage = getFirstChildValue(dom, 'trackerstatusmessage')		this.activitycounter = parseInt(getFirstChildValue(dom, 'activitycounter'))		/* Recalculate done */		if(this.status == ts_seeding || this.status == ts_finished)		{			if(this.downloadtotal < this.filesize)				// User has probably added this torrent with data currently available (readded it), use filesize instead of downloadtotal..				this.done = 100 * (this.uploadtotal / this.filesize)			else				this.done = 100 * (this.uploadtotal / this.downloadtotal)		}	}	this.toString = function()	{		<!-- Printable representation -->		ret = "Status object: ";		ret+= "context id: "+ this.contextID + "\n";		ret+= "filename: "+ this.filename + "\n";		ret+= "status: "+ this.status + "\n";		ret+= "dn_total: "+ this.downloadTotal + "\n";		ret+= "ul_total: "+ this.uploadTotal + "\n";		ret+= "failed_bytes: "+ this.failedBytes + "\n";		ret+= "dn_rate: "+ this.downloadRate + "\n";		ret+= "ul_rate: "+ this.uploadRate + "\n";		ret+= "done: "+ this.done + "\n";		ret+= "filesize: "+ this.filesize + "\n";		ret+= "leechers: "+ this.leechers+ "\n";		ret+= "seeders: "+ this.seeders + "\n";		ret+= "timeleft: "+ this.timeleft+ "\n";		ret+= "trackerstatus: "+ this.trackerstatus+ "\n";		ret+= "trackerstatustext: "+ this.trackerstatustext+ "\n";		ret+= "trackerstatusmessage: "+ this.trackerstatusmessage+ "\n";		ret+= "activitycounter: "+ this.activitycounter+ "\n";		return ret;	}		<!-- Test if this status object represents the same context as another status object s -->	this.compare = function(s)	{		if(!(s instanceof Status))			return false;		if(s.contextID != this.contextID)	return false;		if(s.filename != this.filename)	return false;		return true;	}	<!-- Test if the other Status object passed in s is newer than this (updated data) -->	this.isOld = function(s)	{		if(this.status != s.status)	return true;		if(this.dn_total != s.dn_total)	return true;		if(this.ul_total != s.ul_total)	return true;		if(this.failed_bytes != s.failed_bytes)	return true;		if(this.dn_rate != s.dn_rate)	return true;		if(this.ul_rate != s.ul_rate)	return true;		if(this.done != s.done)	return true;		if(this.filesize != s.filesize)	return true;		if(this.leechers != s.leechers)	return true;		if(this.seeders != s.seeders)	return true;		if(this.timeleft != s.timeleft)	return true;		if(this.trackerstatus != s.trackerstatus)	return true;		if(this.trackerstatustext != s.trackerstatustext)	return true;		if(this.trackerstatusmessage != s.trackerstatusmessage)	return true;      if(this.activitycounter != s.activitycounter) return true;		return false;	}}function Peer(dom){	this.ip = "0.0.0.0";	this.seeder = false;	if(dom)	{		<!-- Defaults set, try to parse dom -->		this.ip = getFirstChildValue(dom, 'ip')		this.seeder = parseBool(getFirstChildValue(dom, 'seeder'))	}	this.toString = function()	{		<!-- Printable representation -->		ret = "Peer object: ";		ret+= "IP: "+ this.ip+ "\n";		ret+= "seeder: "+ this.seeder + "\n";		return ret;	}		<!-- Test if this status object represents the same context as another status object s -->	this.compare = function(s)	{		if(s.ip != this.ip)	return false;		return true;	}}function Limit(dom){	this.contextID = -1;	this.uploadLimit = 0;	this.downloadLimit = 0;	this.seedLimit = 0;	this.seedTimeout = 0;	if(dom)	{		<!-- Defaults set, try to parse dom -->		this.contextID = parseInt(getFirstChildValue(dom, 'id'))		this.uploadLimit = parseInt(getFirstChildValue(dom, 'uploadLimit'))		this.downloadLimit = parseInt(getFirstChildValue(dom, 'downloadLimit'))		this.seedLimit = parseInt(getFirstChildValue(dom, 'seedLimit'))		this.seedTimeout = parseInt(getFirstChildValue(dom, 'seedTimeout'))	}	this.toString = function()	{		<!-- Printable representation -->		ret = "Limit object: ";		ret+= "context id: "+ this.contextID + "\n";		ret+= "uploadLimit: "+ this.uploadLimit+ "\n";		ret+= "downloadLimit: "+ this.downloadLimit+ "\n";		ret+= "seedLimit "+ this.seedLimit+ "\n";		ret+= "seedTimeout: "+ this.seedTimeout;		return ret;	}		<!-- Test if this limit object represents the same context as another liimt object l -->	this.compare = function(l)	{		if(!(l instanceof Limit))			return false;		if(l.contextID != this.contextID)	return false;		return true;	}	<!-- Test if the other Limit object passed in l is newer than this (updated data) -->	this.isOld = function(l)	{		if(this.uploadLimit != l.uploadLimit)	return true;		if(this.downloadLimit != l.downloadLimit)	return true;		if(this.seedLimit != l.seedLimit)	return true;		if(this.seedTimeout != l.seedTimeout)	return true;		return false;	}}-->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -