CyTube/www/channellist.html

189 lines
7.5 KiB
HTML
Raw Normal View History

2013-04-25 21:16:53 +00:00
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CyTube Channel Listing</title>
<link href="assets/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
#channeldata td, #channeldata th {
text-align: center;
vertical-align: middle;
}
.loginform {
margin: 100px auto 20px;
padding: 19px 29px 29px;
border-radius: 5px 5px 5px 5px;
border: 1px solid #dedede;
max-width: 300px;
}
</style>
</head>
<body>
<div class="container">
<form class="form-horizontal loginform" action="javascript:void(0);">
<div class="control-group">
<input id="name" type="text" placeholder="Username" class="input-block-level">
</div>
<div class="control-group">
<input id="pw" type="password" placeholder="Password" class="input-block-level">
</div>
<button id="login" class="btn btn-block">Authenticate</button>
</form>
</div>
<table id="channeldata" class="table table-striped table-bordered">
<thead>
<tr>
<th>Channel</th>
2013-05-12 15:46:19 +00:00
<th>Title</th>
2013-04-25 21:16:53 +00:00
<th>Connected</th>
<th>Playing</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script src="assets/js/jquery.js" type="text/javascript"></script>
2013-04-26 04:57:46 +00:00
<script src="assets/js/iourl.js" type="text/javascript"></script>
2013-04-25 21:16:53 +00:00
<script type="text/javascript">
var session = readCookie("sync_session") || "";
var uname = readCookie("sync_uname") || "";
2013-04-26 17:55:01 +00:00
var p = "";
if(uname && session) {
$.getJSON(IO_URL+"/api/json/login?name="+uname+"&session="+session+"&callback=?", function(data) {
if(data.success) {
$(".loginform").remove();
createCookie("sync_uname", uname, 7);
createCookie("sync_session", session, 7);
2013-04-26 17:55:01 +00:00
p = "name=" + uname + "&session=" + session;
2013-04-26 17:56:25 +00:00
refresh();
setInterval(refresh, 5000);
}
});
}
2013-04-25 21:16:53 +00:00
var q = "";
$("#login").click(function() {
uname = $("#name").val();
2013-04-25 21:16:53 +00:00
q = "name=" + $("#name").val() + "&pw=" + $("#pw").val();
$.getJSON(IO_URL+"/api/json/login?"+q+"&callback=?", function(data) {
if(data.success) {
$(".loginform").remove();
session = data.session;
createCookie("sync_uname", uname, 7);
createCookie("sync_session", session, 7);
p = "name=" + uname + "&session=" + session;
}
});
2013-04-25 21:16:53 +00:00
refresh();
setInterval(refresh, 5000);
});
function idToURL(data) {
var entry = "";
switch(data.type) {
case "yt":
entry = "http://youtube.com/watch?v="+data.id;
break;
case "vi":
entry = "http://vimeo.com/"+data.id;
break;
case "dm":
entry = "http://dailymotion.com/video/"+data.id;
break;
case "sc":
entry = data.id;
break;
case "li":
entry = "http://livestream.com/"+data.id;
break;
case "tw":
entry = "http://twitch.tv/"+data.id;
break;
case "rt":
case "jw":
entry = data.id;
break;
default:
break;
}
return entry;
}
2013-04-25 21:16:53 +00:00
function refresh() {
$.getJSON(IO_URL+"/api/json/listloaded?"+p+"&callback=?", function(data) {
2013-04-25 21:16:53 +00:00
var host = document.location + "";
host = host.substring(0, host.indexOf("/widget.html"));
if(data.error) {
alert(data.error);
return;
}
$(".loginform").remove();
$("#channeldata").find("tbody").remove();
data.sort(function(a, b) {
var x = a.usercount;
var y = b.usercount;
if(x == y) {
var c = a.name.toLowerCase();
var d = b.name.toLowerCase();
return c == d ? 0 : (c < d ? -1 : 1);
}
return y - x;
});
2013-05-11 18:53:33 +00:00
var total = 0;
2013-04-25 21:16:53 +00:00
for(var i = 0; i < data.length; i++) {
var d = data[i];
var tr = $("<tr/>").appendTo($("#channeldata"));
var name = $("<td/>").appendTo(tr);
$("<a/>").attr("href", host + "/r/" + d.name)
.text(d.name)
.appendTo(name);
2013-05-12 15:46:19 +00:00
$("<td/>").text(d.pagetitle).appendTo(tr);
2013-04-25 21:16:53 +00:00
$("<td/>").text(d.usercount || 0).appendTo(tr);
var title = $("<td/>").appendTo(tr);
if(d.media.id) {
$("<a/>").appendTo(title)
.text(d.media.title)
.attr("href", idToURL(d.media))
.attr("target", "_blank");
}
else {
title.text("-");
}
2013-05-11 18:53:33 +00:00
total += (d.usercount || 0);
2013-04-25 21:16:53 +00:00
}
2013-05-11 18:53:33 +00:00
var tr = $("<tr/>").appendTo($("#channeldata"));
$("<td/>").text("Total").appendTo(tr);
$("<td/>").text(total).appendTo(tr);
$("<td/>").appendTo(tr);
2013-05-12 15:46:19 +00:00
$("<td/>").appendTo(tr);
2013-05-11 18:53:33 +00:00
2013-04-25 21:16:53 +00:00
});
}
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(";");
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==" ") c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
2013-04-25 21:16:53 +00:00
</script>
</body>
</html>