2017-04-11 00:02:15 +05:30

2 lines
12 KiB
JavaScript

function menubuttonfunc(){0===menuswitch1?showmenu():hidemenu()}function showmenu(){loc=$("#buttonBig").offset().top,setTimeout(function(){$("#mainPage").css({overflow:"hidden"}),$("#contents").css({position:"absolute"}),menuswitch1=1},500),menuswitch2=1,$("#buttonBig").addClass("cross"),$("#contents").css({position:"fixed"}),$("#contents").fadeIn(750),$("#bg1").slideDown(500),$("#buttonBig").css({"background-color":"rgba(0,0,0,0.5)"})}function hidemenu(){setTimeout(function(){menuswitch1=0},500),menuswitch2=0,$("#buttonBig").removeClass("cross"),$("#contents").fadeOut(250),$("#contents,#bg1").slideUp(500),$("#buttonBig").css({"background-color":"transparent"}),nav("hide",null),$("#mainPage").css({overflow:"visible"}),window.scrollTo(0,loc)}function nav(a,b){if("show"==a){var c=["#help","#about","#embed"],d=["#menuHelp","#menuAbout","#menuEmbed"];b=Number(b[1]),0==articleStates[b]?($(c[b]).slideDown(1e3),$(d[b]).css({color:"black","background-color":"rgba(0,0,0,0.1)","font-weight":"900"}),articleStates[b]=1):($(c[b]).slideUp(1e3),$(d[b]).css({color:"grey","background-color":"white","font-weight":"100"}),articleStates[b]=0)}else $("#about,#help,#embed").hide(),$("#menuAbout,#menuHelp,#menuEmbed").css({color:"grey","background-color":"white","font-weight":"100"}),articleStates=[0,0,0]}function trigenter(a){13===a.keyCode&&getValue()}function linkshare(){$("#pageUrl").fadeIn(),$("#bg2").fadeIn(),$("#bg2").on("click",function(){$("#pageUrl").fadeOut(),$("#bg2").hide(),$("bg2").off("click")})}function pushViews(a,b,c){getText(a,function(a){views[b]=a.items[0].statistics.viewCount,"auto"==c&&b==2*vids-1&&upCharts()})}function extrabutton(){if(0===firstload){$("#showextra").html("LOADING...");var a=username.length>=24&&"UC"==username.substr(0,2).toUpperCase()?"id":"forUsername",b="https://www.googleapis.com/youtube/v3/channels?part=contentDetails&"+a+"="+username+"&fields=items/contentDetails/relatedPlaylists/uploads&key="+getKey();getText(b,function(b){var c="https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId="+b.items[0].contentDetails.relatedPlaylists.uploads+"&maxResults=50&fields=items/snippet/resourceId/videoId&key="+getKey();getText(c,function(b){for(var c=0;b.items[c];c++){pushViews("https://www.googleapis.com/youtube/v3/videos?part=statistics&id="+b.items[c].snippet.resourceId.videoId+"&fields=items/statistics/viewCount&key="+getKey(),c)}$.getScript("https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.js",function(){isChart=1,$("#extra").removeClass("extraCol"),$("#extra").addClass("extraExp"),$("#showextra").fadeOut(),$("#hideextra").fadeIn(),extraswitch=1;for(var b=[],c=[],d=0;d<vids;d++)b[d]=views[d],c[d]="";var e={labels:c,datasets:[{label:"Views of last "+vids+" videos",fill:!1,borderColor:"rgba(255,50,50,0.5)",pointBorderColor:"rgba(255,50,50,0.5)",pointBackgroundColor:"rgba(255,50,50,1)",data:b}]};myLineChart2=new Chart(document.getElementById("myChart2").getContext("2d"),{type:"line",data:e,gridLines:{display:!1},responsive:!0,maintainAspectRatio:!1});var f=[function(){for(var a=0,b=0;b<vids;b++)a+=Number(views[b]);return a}(),function(){for(var a=0,b=vids;b<2*vids;b++)a+=Number(views[b]);return a}()],g=[Math.floor(f[0]/vids),Math.floor(f[1]/vids)],h=["last "+vids+" videos","last to last "+vids+" videos"],i={labels:h,datasets:[{label:"Average Views",borderColor:["rgba(0,0,255,1)","rgba(0,255,0,1)"],backgroundColor:["rgba(50,50,255,0.2)","rgba(50,255,50,0.2)"],hoverBackgroundColor:["rgba(0,0,255,1)","rgba(0,255,0,1)"],data:g}]};myLineChart3=new Chart(document.getElementById("myChart3").getContext("2d"),{type:"bar",data:i,gridLines:{display:!1},responsive:!0,maintainAspectRatio:!1});var j=[f[0],f[1]],k=["last "+vids+" videos (total views)","last to last "+vids+" videos (total views)"],l={labels:k,datasets:[{label:"Total Views",borderColor:["rgba(0,0,255,1)","rgba(0,255,0,1)"],backgroundColor:["rgba(50,50,255,0.2)","rgba(50,255,50,0.2)"],hoverBackgroundColor:["rgba(0,0,255,1)","rgba(0,255,0,1)"],data:j}]};myLineChart4=new Chart(document.getElementById("myChart4").getContext("2d"),{type:"doughnut",data:l,gridLines:{display:!1},responsive:!0,maintainAspectRatio:!1}),changeText(document.getElementById("pubDate"),channeldate);var m="https://www.googleapis.com/youtube/v3/channels?part=statistics&"+a+"="+username+"&fields=items/statistics(videoCount,viewCount)&key="+getKey();getText(m,function(a){changeText(document.getElementById("totalVideos"),a.items[0].statistics.videoCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")),changeText(document.getElementById("totalViews"),a.items[0].statistics.viewCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","))})})})}),$("#extraContent").fadeTo("fast",1),$("#charts").fadeIn(500),firstload=1}else $("#showextra").html("SHOW STATS"),0===extraswitch?(isChart=1,$("#extra").removeClass("extraCol"),$("#extra").addClass("extraExp"),$("#showextra").fadeOut(),$("#hideextra").fadeIn(),$("#extraContent").fadeTo("fast",1),extraswitch=1):(myLineChart1.destroy(),$("#extra").removeClass("extraExp"),$("#extra").addClass("extraCol"),$("#showextra").fadeIn(),$("#hideextra").fadeOut(100),$("#extraContent").fadeTo(0,0),extraswitch=0,isChart=0)}function upCharts(){if(!(Number($("#vids").val())>25)){vids=Number($("#vids").val());for(var a=0,b=0,c=0;c<vids;c++)myLineChart2.data.labels[c]="",myLineChart2.data.datasets[0].data[c]=views[c],a+=Number(views[c]);for(c=vids;c<2*vids;c++)b+=Number(views[c]);myLineChart2.data.labels.splice(vids),myLineChart2.data.datasets[0].data.splice(vids),myLineChart2.data.datasets[0].label="Views of last "+vids+" videos",myLineChart3.data.labels=["last "+vids+" videos","last to last "+vids+" videos"],myLineChart3.data.datasets[0].data[0]=Math.floor(a/vids),myLineChart3.data.datasets[0].data[1]=Math.floor(b/vids),myLineChart4.data.labels=["last "+vids+" videos (total views)","last to last "+vids+" videos (total views)"],myLineChart4.data.datasets[0].data[0]=a,myLineChart4.data.datasets[0].data[1]=b,myLineChart2.update(),myLineChart3.update(),myLineChart4.update()}}window.top===window.self&&window.top.location==window.self.location&&"youcount.github.io"==window.location.hostname&&"youcount.github.io"==window.top.location.hostname||(window.top.location=window.self.location),"https:"!=window.location.protocol&&(window.location.href="https:"+window.location.href.substring(window.location.protocol.length));var emailParts=["manas.khurana20","gmail","com","&#46;","&#64;"];document.getElementById("email").innerHTML=emailParts[0]+emailParts[4]+emailParts[1]+emailParts[3]+emailParts[2],document.getElementById("email").href="mailto:"+document.getElementById("email").innerHTML,$("#buttonBig").on("click",function(){menubuttonfunc()}),$("#fb").on("click",function(){window.open("https://www.facebook.com/sharer/sharer.php?u="+encodeURIComponent(document.querySelector("#pageUrl input").getAttribute("value")),"_blank")}),$("#tw").on("click",function(){window.open("https://twitter.com/share?text="+document.getElementById("username").value+" now has "+actualCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")+" subscribers!&url="+encodeURIComponent(document.querySelector("#pageUrl input").getAttribute("value"))+"&hashtags=YouCount","_blank")}),$("#lnkdIn").on("click",function(){window.open("https://www.linkedin.com/shareArticle?mini=true&url="+encodeURIComponent(document.querySelector("#pageUrl input").getAttribute("value"))+"&title="+encodeURIComponent(channelname)+"'s%20Live%20Subscriber%20Count&source=YouCount","_blank")}),$("#tb").on("click",function(){window.open("http://www.tumblr.com/share/link?url="+encodeURIComponent(document.querySelector("#pageUrl input").getAttribute("value")),"_blank")}),$("#rdit").on("click",function(){window.open("http://www.reddit.com/submit?url="+encodeURIComponent(document.querySelector("#pageUrl input").getAttribute("value"))+"&title="+encodeURIComponent(channelname)+"'s%20Live%20Subscriber%20Count","_blank")}),$("#link").on("click",function(){linkshare()}),$("#menuHelp,#menuAbout,#menuEmbed").on("click",function(){nav("show",this.className)}),$("#input button").on("click",function(){getValue()}),$(".suggest").on("click",function(){username=this.dataset.id,rawInput=this.dataset.id;var a="https://www.googleapis.com/youtube/v3/channels?part=snippet&id="+this.dataset.id+"&fields=items/snippet&key="+getKey();getText(a,function(a){channelname=a.items[0].snippet.title,document.title=channelname+"'s YouTube Live Subscriber Count - YouCount",changeText(document.querySelector("#username"),channelname),2===isChart&&(isChart=1),live();var b=a.items[0].snippet.publishedAt.split("T")[0];if(b=b.split("-"),"01"==b[1]?b[1]="Jan":"02"==b[1]?b[1]="Feb":"03"==b[1]?b[1]="Mar":"04"==b[1]?b[1]="Apr":"05"==b[1]?b[1]="May":"06"==b[1]?b[1]="Jun":"07"==b[1]?b[1]="Jul":"08"==b[1]?b[1]="Aug":"09"==b[1]?b[1]="Sep":"10"==b[1]?b[1]="Oct":"11"==b[1]?b[1]="Nov":"12"==b[1]&&(b[1]="Dec"),changeText(document.getElementById("pubDate"),b[2]+"-"+b[1]+"-"+b[0]),document.getElementById("dp").src=a.items[0].snippet.thumbnails.default.url,1==popstatevar){var c,d;c=a.items[0].snippet.customUrl?a.items[0].snippet.customUrl.trim():channelname.trim().replace(/\s+/g,"+");var e="https://www.googleapis.com/youtube/v3/search?part=snippet&q="+encodeURIComponent(c)+"&type=channel&maxResults=1&key="+getKey();getText(e,function(a){d=a.pageInfo.totalResults<1||a.items[0].snippet.channelId.trim()!=username?username:c,history.pushState(null,null,"#!/"+d),changeText(document.getElementById("embedUrl"),'<iframe src="https://youcount.github.io/e/#!/'+d+'" height="100" width="250" frameborder="0"></iframe>'),changeText(document.querySelector("#pageUrl input"),"https://youcount.github.io/#!/"+d)})}popstatevar=1;var f="https://www.googleapis.com/youtube/v3/channels?part=statistics&id="+username+"&fields=items/statistics&key="+getKey();getText(f,function(a){changeText(document.getElementById("totalVideos"),a.items[0].statistics.videoCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")),changeText(document.getElementById("totalViews"),a.items[0].statistics.viewCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","))})})}),$("#logo").on("click",function(){rawInput=preSelect[Math.floor(Math.random()*preSelect.length)],queryName()}),$("#showextra,#hideextra").on("click",function(){extrabutton()});var shareswitch=0;$("#share").on("click",function(){0===shareswitch?($("#fb,#tw,#lnkdIn,#tb,#rdit,#link").fadeIn(200),shareswitch=3):($("#fb,#tw,#lnkdIn,#tb,#rdit,#link").fadeOut(200),setTimeout(function(){shareswitch=0},200))}),$("body").on("click",function(){0!==shareswitch&&1==--shareswitch&&($("#fb,#tw,#lnkdIn,#tb,#rdit,#link").fadeOut(200),setTimeout(function(){shareswitch=0},200))}),$("#username").focusin(function(){$("#input").css({"background-color":"rgba(255,0,0,0.4)"}),$("#input button").fadeIn(250),$("#username").select()}),$("#username").focusout(function(){$("#input").css({"background-color":"rgba(0,0,0,0.3)"}),$("#input button, #suggest").fadeOut(250)}),$("#username").on("keyup",function(){var a=document.getElementById("username").value;if(!a.trim())return void $("#suggest").hide();$("#suggest").show(),"Not Found!"!=a.trim()&&"Loading..."!=a.trim()&&getText("https://www.googleapis.com/youtube/v3/search?part=snippet&q="+encodeURIComponent(a)+"&type=channel&maxResults=5&relevanceLanguage=en&key="+getKey(),function(a){if(!(a.pageInfo.totalResults<1))for(var b=0;b<5;b++)try{document.querySelectorAll(".suggest")[b].style.display="block",document.querySelectorAll(".suggest")[b].dataset.id=a.items[b].snippet.channelId.trim(),document.querySelectorAll(".suggest div")[b].textContent=a.items[b].snippet.title,document.querySelectorAll(".suggestImg")[b].src=a.items[b].snippet.thumbnails.default.url}catch(a){document.querySelectorAll(".suggest")[b].style.display="none"}})});for(var menuswitch1=0,menuswitch2=0,loc,articleStates=[0,0,0],views=[],l=0;l<50;l++)views[l]=50-l;for(var extraswitch=0,myLineChart2,myLineChart3,vids=5,images=document.getElementsByTagName("img"),pl=0;pl<images.length;pl++)!images[pl].src&&images[pl].id&&"instruct"!=images[pl].id&&(images[pl].src="/images/"+images[pl].id+".png");document.getElementById("instruct").src="/images/instruct.png";