diff --git a/gulpfile.js b/gulpfile.js
index 1b89c2e6..ef1fa4dd 100755
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -4,7 +4,7 @@ var gulp = require('gulp'),
concat = require('gulp-concat');
gulp.task('js', function () {
- gulp.src(['static/js/*.js', '!static/js/nochan*', '!static/js/remotecontroller.js'])
+ gulp.src(['static/js/*.js', '!static/js/embed*', '!static/js/nochan*', '!static/js/remotecontroller.js'])
.pipe(uglify({
mangle: true,
compress: true,
@@ -14,6 +14,17 @@ gulp.task('js', function () {
.pipe(gulp.dest('static/dist'));
});
+gulp.task('embed', function () {
+ gulp.src(['static/js/youtube.js', 'static/js/helpers.js', 'static/js/playercontrols.js', 'static/js/list.js', 'static/js/embed.js', '!static/js/nochan*', '!static/js/remotecontroller.js'])
+ /*.pipe(uglify({
+ mangle: true,
+ compress: true,
+ enclose: true
+ }))*/
+ .pipe(concat('embed.min.js'))
+ .pipe(gulp.dest('static/dist'));
+});
+
gulp.task('nochan', function () {
gulp.src(['static/js/nochan.js'])
.pipe(uglify({
@@ -38,6 +49,7 @@ gulp.task('remotecontroller', function () {
gulp.task('default', function(){
gulp.watch('static/js/*.js', ['js']);
+ gulp.watch('static/js/*.js', ['embed']);
gulp.watch('static/js/nochan.js', ['nochan']);
gulp.watch('static/js/remotecontroller.js', ['remotecontroller']);
});
\ No newline at end of file
diff --git a/index.php b/index.php
index 235ec1e2..c83de923 100755
--- a/index.php
+++ b/index.php
@@ -152,6 +152,16 @@
Also, whenever you're logged in, you'll have two tabs in the top of the playlist thats called "Playlist" and "Suggested". The playlist obviously shows the playlist. But the suggested tab, shows 5 songs that YouTube recommends based on the current song. There might also be user recommended songs. To add any of these, just click them as you'd click a song to vote.
+
diff --git a/static/css/embed.css b/static/css/embed.css
new file mode 100644
index 00000000..bae22837
--- /dev/null
+++ b/static/css/embed.css
@@ -0,0 +1,235 @@
+.card-image{
+ height: 100px;
+ width: 100px;
+ background-position: center;
+ background-size: 180%;
+}
+
+.card{
+ cursor:pointer;
+ background-color: grey !important;
+}
+
+
+#list-song-html {
+ display:none;
+}
+
+#song-title{
+ display:none;
+}
+
+.list-image, .list-suggested-image{
+ width: 34%;
+ height: 66px;
+ float: left;
+}
+
+.list-image:after {
+ font-family: "Material-Design-Icons";
+ speak: none;
+ font-style: normal;
+ font-weight: normal;
+ font-variant: normal;
+ text-transform: none;
+ text-rendering: auto;
+ -webkit-font-smoothing: antialiased;
+ content: "\e686";/*"\e800";*/
+ color:white;
+ font-size:65px;
+ position:absolute;
+ width:100%; height:100%;
+ top:0; left:0;
+ background:rgba(0,0,0,0.8);
+ opacity:0;
+ transition: all .1s ease;
+}
+
+.list-suggested-image:after {
+ font-family: "Material-Design-Icons";
+ speak: none;
+ font-style: normal;
+ font-weight: normal;
+ font-variant: normal;
+ text-transform: none;
+ text-rendering: auto;
+ -webkit-font-smoothing: antialiased;
+ content: "\e625";/*"\e800";*/
+ color:white;
+ font-size:65px;
+ position:absolute;
+ width:100%; height:100%;
+ top:0; left:0;
+ background:rgba(0,0,0,0.8);
+ opacity:0;
+ transition: all .1s ease;
+}
+
+.vote-container:hover .list-image:after, .add-suggested:hover .list-suggested-image:after {
+ opacity:1;
+}
+
+
+
+.vote-span{
+ opacity: 0.7;
+ padding: 0 0 0 10px;
+ color:white !important;
+}
+
+.list-song{
+ background-color: rgba(255, 255, 255, 0.04);
+ color:white;
+ font:12px Arial,sans-serif;
+ -webkit-transition:height .3s;
+ -moz-transition:height .3s;
+ -o-transition:height .3s;
+ transition:height .3s;
+ height:66px;
+}
+.list-song .card-content{padding:0;}
+.list-title{
+ font-size:13px !important;
+ display:block;
+ color:white;font-size:1em;
+ text-align:left;
+ padding: 0 10px 0 10px;
+ line-height: 2.6rem;
+}
+.card-image{cursor:pointer}
+.card{
+ margin:5px 0 5px 0 !important;
+}
+.card:hover{
+ box-shadow: 0 5px 5px 0 rgba(0,0,0,0.16), 0 5px 10px 0 rgba(0,0,0,0.12);
+}
+
+#playlist{
+ background-color:grey;
+ height:332px;
+}
+
+.progress{background-color:rgba(0,0,0,0) !important;}
+
+.indeterminate {
+ background-color:white !important;
+}
+
+#controls
+{
+ opacity:0;
+ height:32px;
+ background-color:grey;
+ width:300px;
+ color:white;
+ margin-top:0px;
+}
+
+#playpause, #duration, #volume-button
+{
+ float:left;
+ color:white;
+}
+
+#playpause, #volume-button
+{
+ margin-left:10px;
+}
+
+#playpause:hover, #volume-button:hover, #fullscreen:hover
+{
+ color:rgba(255,255,255,0.5);
+}
+
+#fullscreen
+{
+ float:right;
+ color:white;
+ margin-right:15px;
+}
+
+#duration, #viewers
+{
+ margin-top:5px;
+ font-family:"Roboto", sans-serif;
+ font-weight:300;
+ margin-left:15px;
+}
+
+#viewers{
+ float: right;
+}
+
+#play, #pause, #volume-button, #fullscreen
+{
+ font-size:20px;
+ cursor:pointer;
+}
+
+#volume {
+ cursor:pointer;
+ float:left;
+ position: relative;
+ left: 10px;
+ margin: 13px auto;
+ height:5px;
+ width: 75px;
+ /*background-color:rgba(0, 0, 0, 0.5);*/
+ background:rgba(0, 0, 0, 0.5) 50% 50% repeat-x;
+ border: none;
+ outline: none;
+ /*border-radius: 2px;*/
+}
+
+#volume .ui-slider-range-min {
+ height:5px;
+ width: 75px;
+ position: absolute;
+ background-color:rgba(255, 255, 255, 0.8);
+ border: none;
+ outline: none;
+ /*border-radius: 2px;*/
+}
+
+#volume .ui-slider-handle {
+ height:15px;
+ width:5px;
+ background:#fff 50% 50% repeat-x;
+ position: absolute;
+ cursor: pointer;
+ outline: none;
+ border: none;
+ display: none;
+ margin-left:-2.5px;
+ margin-top:0px;
+}
+
+.ui-slider-handle
+{
+ margin-top:-5px;
+}
+
+.play
+{
+ background-size: auto;
+ width: 55px;
+ height: 27px;
+}
+
+.pause
+{
+ background-size: auto;
+ width: 55px;
+ height: 27px;
+}
+
+.hide
+{
+ display:none !important;
+}
+
+#bar
+{
+ height:100%;
+ background-color:rgba(0,0,0,0.5);
+}
\ No newline at end of file
diff --git a/static/css/style.css b/static/css/style.css
index 8d2cc104..ea3f1b7b 100755
--- a/static/css/style.css
+++ b/static/css/style.css
@@ -10,6 +10,10 @@
.snow{-webkit-filter:brightness(100%);-moz-filter:brightness(100%);-o-filter:brightness(100%);filter:brightness(100%);width:5px; height:5px; background-color:white;z-index:1000000;pointer-events:none;position:absolute;border:1px solid white;border-radius:100px;}
+#embed-button{
+ display:none;
+}
+
/* GLOBAL STYLES */
#playbar{
diff --git a/static/dist/embed.min.js b/static/dist/embed.min.js
new file mode 100644
index 00000000..e3e429af
--- /dev/null
+++ b/static/dist/embed.min.js
@@ -0,0 +1,982 @@
+var Youtube = {
+
+ loaded: true,
+ before_load: "",
+ after_load: "",
+ ytplayer: "",
+ stopInterval: false,
+
+ setup_youtube_listener: function(channel)
+ {
+ socket.on("np", function(obj)
+ {
+ Youtube.loaded = false;
+
+ if(obj[0].length == 0){
+
+ document.getElementById('song-title').innerHTML = "Empty channel. Add some songs!";
+ $("#player_overlay").height($("#player").height());
+
+ if(!/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) $("#player_overlay").toggleClass("hide");
+ try{
+ Youtube.ytplayer.stopVideo();
+ }catch(e){}
+ //List.importOldList(channel.toLowerCase());
+ }
+ else{
+ //console.log("gotten new song");
+ if(previous_video_id == undefined)
+ previous_video_id = obj[0][0]["id"];
+ else if(previous_video_id != video_id)
+ previous_video_id = video_id;
+
+ video_id = obj[0][0]["id"];
+ conf = obj[1][0];
+ time = obj[2];
+ seekTo = time - conf["startTime"];
+ song_title = obj[0][0]["title"];
+
+ $("#player_overlay").addClass("hide");
+
+ try{
+ Suggestions.fetchYoutubeSuggests(video_id);
+ }catch(e){}
+ Youtube.getTitle(song_title, viewers);
+ Youtube.setBGimage(video_id);
+ //if(player_ready && !window.mobilecheck())
+ if(player_ready && !/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream)
+ {
+
+ try{
+ if(Youtube.ytplayer.getVideoUrl().split('v=')[1] != video_id)
+ {
+ Youtube.ytplayer.loadVideoById(video_id);
+ Youtube.notifyUser(video_id, song_title);
+ Youtube.ytplayer.seekTo(seekTo);
+ if(paused)
+ Youtube.ytplayer.pauseVideo();
+ }
+
+ if(!paused){
+ Youtube.ytplayer.playVideo();
+ Youtube.durationSetter();
+ }
+ if(Youtube.ytplayer.getDuration() > seekTo || Youtube.ytplayer.getDuration() == 0)
+ Youtube.ytplayer.seekTo(seekTo);
+ Youtube.after_load = video_id;
+ setTimeout(function(){Youtube.loaded = true;},500);
+ }catch(e){Youtube.durationSetter();}
+ }
+ else
+ Youtube.getTitle(song_title, viewers);
+ }
+ });
+
+ socket.on("viewers", function(view)
+ {
+ viewers = view;
+
+ if(song_title !== undefined)
+ Youtube.getTitle(song_title, viewers);
+ });
+ },
+
+ onPlayerStateChange: function(newState) {
+ switch(newState.data)
+ {
+ case -1:
+ break;
+ case 0:
+ playing = false;
+ paused = false;
+
+ socket.emit("end", video_id);
+ break;
+ case 1:
+ playing = true;
+ if(beginning && window.mobilecheck()){
+ Youtube.ytplayer.pauseVideo();
+ beginning = false;
+ }
+ if(document.getElementById("play").className.split(" ").length == 1)
+ $("#play").toggleClass("hide");
+ if(document.getElementById("pause").className.split(" ").length == 2)
+ $("#pause").toggleClass("hide");
+ if(paused)
+ {
+ socket.emit('pos');
+ paused = false;
+ }
+ break;
+ case 2:
+ paused = true;
+
+ if(document.getElementById("pause").className.split(" ").length == 1)
+ $("#pause").toggleClass("hide");
+ if(document.getElementById("play").className.split(" ").length == 2)
+ $("#play").toggleClass("hide");
+ break;
+ case 3:
+ break;
+ }
+ },
+
+ getTitle: function(titt, v)
+ {
+ var outPutWord = v > 1 ? "viewers" : "viewer";
+ var title = decodeURIComponent(titt);
+ var elem = document.getElementById('song-title');
+ var viewers = document.getElementById('viewers');
+
+ document.title = title + " • Zöff / "+chan;
+ elem.innerHTML = title;
+ viewers.innerHTML = v + " " + outPutWord;
+ elem.title = title + " • " + v + " " + outPutWord;
+
+ },
+
+ errorHandler: function(newState)
+ {
+ if(newState.data == 5 || newState.data == 100
+ || newState.data == 101 || newState.data == 150)
+ {
+ /*if(Youtube.count == 2){
+ Youtube.count = 0;*/
+ /*console.log("Before: " + Youtube.before_load);
+ console.log("Now: " + video_id);
+ console.log("After: " + Youtube.after_load);
+ console.log(Youtube.before_load == Youtube.ytplayer.getVideoUrl);*/
+ curr_playing = Youtube.ytplayer.getVideoUrl().replace("https://www.youtube.com/watch?v=", "");
+
+
+ socket.emit("skip", {error: newState.data, id: video_id, pass: adminpass});
+ //console.log(video_id, Youtube.ytplayer.getVideoUrl(), Youtube.ytplayer.getPlayerState());
+
+ /*}else{
+ setTimeout(function(){
+ Youtube.ytplayer.loadVideoById(video_id);
+ Youtube.count ++;
+ }, Math.floor((Math.random() * 100) + 1));
+ }*/
+ }else if(video_id !== undefined)
+ Youtube.ytplayer.loadVideoById(video_id);
+ },
+
+ onPlayerReady: function(event) {
+ $("#channel-load").css("display", "none");
+ try{
+ beginning = true;
+ player_ready = true;
+ if(!/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream)
+ {
+ $("#player").css("opacity", "1");
+ $("#controls").css("opacity", "1");
+ $(".playlist").css("opacity", "1");
+ window.ytplayer = Youtube.ytplayer;
+ Youtube.ytplayer.loadVideoById(video_id);
+ Youtube.ytplayer.playVideo();
+ Youtube.durationSetter();
+ Youtube.ytplayer.seekTo(seekTo);
+ }
+ Youtube.readyLooks();
+ Playercontrols.initYoutubeControls(Youtube.ytplayer);
+ Playercontrols.initSlider();
+ Youtube.ytplayer.setVolume(Crypt.get_volume());
+ }catch(e){}
+ },
+
+ readyLooks: function()
+ {
+ Youtube.setBGimage(video_id);
+ },
+
+ setBGimage: function(id){
+
+ if(id !== undefined && !embed)
+ {
+ var img = new Image();
+ img.onload = function ()
+ {
+
+ var colorThief = new ColorThief();
+ var color = colorThief.getColor(img);
+
+ document.getElementsByTagName("body")[0].style.backgroundColor = Helper.rgbToHsl(color);
+ $("meta[name=theme-color]").attr("content", Helper.rgbToHex(color[0], color[1], color[2]));
+ };
+
+ img.crossOrigin = 'Anonymous';
+ img.src = 'https://zoff.no:8080/https://img.youtube.com/vi/'+id+'/mqdefault.jpg';
+ }
+ },
+
+ set_width: function(val){
+ $(".video-container").width(val);
+ },
+
+ notifyUser: function(id, title) {
+ title = title.replace(/\\\'/g, "'").replace(/"/g,"'").replace(/&/g,"&");
+ if (Notification.permission === "granted" && document.hidden) {
+ var notification = new Notification("Now Playing", {body: title, icon: "http://i.ytimg.com/vi/"+id+"/mqdefault.jpg", iconUrl: "http://i.ytimg.com/vi/"+id+"/mqdefault.jpg"});
+ notification.onclick = function(x) { window.focus(); this.cancel(); };
+ setTimeout(function(){
+ notification.close();
+ },5000);
+ }
+ },
+
+ setup_all_listeners: function()
+ {
+ socket.on("get_list", function(){
+ socket.emit('list', chan.toLowerCase());
+ });
+ Youtube.setup_youtube_listener(chan);
+ Admin.admin_listener();
+ Chat.setup_chat_listener(chan);
+ Chat.allchat_listener();
+ List.channel_listener();
+ List.skipping_listener();
+ },
+
+ onYouTubeIframeAPIReady: function() {
+ Youtube.ytplayer = new YT.Player('player', {
+ videoId: "asd",
+ playerVars: { rel:"0", wmode:"transparent", controls: "0" , iv_load_policy: "3", theme:"light", color:"white"},
+ events: {
+ 'onReady': Youtube.onPlayerReady,
+ 'onStateChange': Youtube.onPlayerStateChange,
+ 'onError': Youtube.errorHandler
+ }
+ });
+ //Youtube.durationSetter();
+ },
+
+ durationSetter: function()
+ {
+ try{
+ duration = Youtube.ytplayer.getDuration();
+ }catch(e){duration = 0};
+ if(duration != undefined){
+ try{
+ dMinutes = Math.floor(duration / 60);
+ dSeconds = duration - dMinutes * 60;
+ currDurr = Youtube.ytplayer.getCurrentTime();
+ if(currDurr > duration)
+ currDurr = duration;
+ minutes = Math.floor(currDurr / 60);
+ seconds = currDurr - minutes * 60;
+ document.getElementById("duration").innerHTML = Helper.pad(minutes)+":"+Helper.pad(seconds)+"
/ "+Helper.pad(dMinutes)+":"+Helper.pad(dSeconds);
+ per = (100 / duration) * currDurr;
+ if(per >= 100)
+ per = 100;
+ else if(duration == 0)
+ per = 0;
+ $("#bar").width(per+"%");
+ }catch(e){
+
+ }
+ }
+ if(!Youtube.stopInterval) setTimeout(Youtube.durationSetter, 1000);
+ },
+
+ loadPlayer: function() {
+ if($("script[src='https://www.youtube.com/iframe_api']")["length"] == 1){
+ Youtube.onYouTubeIframeAPIReady();
+ }else{
+ tag = document.createElement('script');
+ tag.src = "https://www.youtube.com/iframe_api";
+ firstScriptTag = document.getElementsByTagName('script')[0];
+ firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
+ }
+ }
+
+}
+window.mobilecheck = function() {
+ var check = false;
+ (function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4)))check = true;})(navigator.userAgent||navigator.vendor||window.opera);
+ return check;
+};
+
+var Helper = {
+ rnd: function(arr)
+ {
+ return arr[Math.floor(Math.random() * arr.length)];
+ },
+
+ predicate: function() {
+ var fields = [],
+ n_fields = arguments.length,
+ field, name, cmp;
+
+ var default_cmp = function (a, b) {
+ if (a === b) return 0;
+ return a < b ? -1 : 1;
+ },
+ getCmpFunc = function (primer, reverse) {
+ var dfc = default_cmp,
+ // closer in scope
+ cmp = default_cmp;
+ if (primer) {
+ cmp = function (a, b) {
+ return dfc(primer(a), primer(b));
+ };
+ }
+ if (reverse) {
+ return function (a, b) {
+ return -1 * cmp(a, b);
+ };
+ }
+ return cmp;
+ };
+
+ // preprocess sorting options
+ for (var i = 0; i < n_fields; i++) {
+ field = arguments[i];
+ if (typeof field === 'string') {
+ name = field;
+ cmp = default_cmp;
+ } else {
+ name = field.name;
+ cmp = getCmpFunc(field.primer, field.reverse);
+ }
+ fields.push({
+ name: name,
+ cmp: cmp
+ });
+ }
+
+ // final comparison function
+ return function (A, B) {
+ var name, result;
+ for (var i = 0; i < n_fields; i++) {
+ result = 0;
+ field = fields[i];
+ name = field.name;
+
+ result = field.cmp(A[name], B[name]);
+ if (result !== 0) break;
+ }
+ return result;
+ };
+ },
+
+ hashCode: function(str) { // java String#hashCode
+ var hash = 0;
+ for (var i = 0; i < str.length; i++) {
+ hash = str.charCodeAt(i) + ((hash << 5) - hash);
+ }
+ return hash;
+ },
+
+ intToARGB: function(i){
+ return ((i>>24)&0xFF).toString(16) +
+ ((i>>16)&0xFF).toString(16) +
+ ((i>>8)&0xFF).toString(16) +
+ (i&0xFF).toString(16);
+ },
+
+ pad: function(n)
+ {
+ return n < 10 ? "0"+Math.floor(n) : Math.floor(n);
+ },
+
+
+ contains: function(a, obj) {
+ var i = a.length;
+ while (i--) {
+ if (a[i] === obj) {
+ return true;
+ }
+ }
+ return false;
+ },
+
+ sample: function() {
+ if (Date.now() - lastSample >= SAMPLE_RATE * 2) {
+ socket.removeAllListeners()
+ socket.disconnect();
+ socket.connect();
+ Youtube.setup_all_listeners();
+ }
+ lastSample = Date.now();
+ setTimeout(Helper.sample, SAMPLE_RATE);
+ },
+
+ loadjsfile: function(filename)
+ {
+ if (filesadded.indexOf("["+filename+"]")==-1){
+ var fileref=document.createElement('script');
+ fileref.setAttribute("type","text/javascript");
+ fileref.setAttribute("src", filename);
+ document.getElementsByTagName("head")[0].appendChild(fileref);
+ filesadded+="["+filename+"]";
+ }
+ },
+
+ msieversion: function() {
+
+ var ua = window.navigator.userAgent;
+ var msie = ua.indexOf("MSIE ");
+
+ if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer, return version number
+ return true;
+ else // If another browser, return 0
+ return false;
+ },
+
+ getRandomInt: function(min, max) {
+ return Math.floor(Math.random() * (max - min)) + min;
+ },
+
+ rgbToHsl: function(arr){
+ r = arr[0], g = arr[1], b = arr[2];
+ r /= 255, g /= 255, b /= 255;
+ var max = Math.max(r, g, b), min = Math.min(r, g, b);
+ var h, s, l = (max + min) / 2;
+
+ if(max == min){
+ h = s = 0; // achromatic
+ }else{
+ var d = max - min;
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
+ switch(max){
+ case r: h = (g - b) / d + (g < b ? 6 : 0); break;
+ case g: h = (b - r) / d + 2; break;
+ case b: h = (r - g) / d + 4; break;
+ }
+ h /= 6;
+ }
+
+ if(l>0.5)l=0.5; //make sure it isnt too light
+
+ return "hsl("+Math.floor(h*360)+", "+Math.floor(s*100)+"%, "+Math.floor(l*100)+"%)";
+ },
+
+ componentToHex: function(c) {
+ var hex = c.toString(16);
+ return hex.length == 1 ? "0" + hex : hex;
+ },
+
+ rgbToHex: function(r, g, b) {
+ return "#" + Helper.componentToHex(r) + Helper.componentToHex(g) + Helper.componentToHex(b);
+ }
+
+}
+
+Element.prototype.remove = function() {
+ this.parentElement.removeChild(this);
+}
+
+NodeList.prototype.remove = HTMLCollection.prototype.remove = function() {
+ for(var i = 0, len = this.length; i < len; i++) {
+ if(this[i] && this[i].parentElement) {
+ this[i].parentElement.removeChild(this[i]);
+ }
+ }
+}
+
+
+String.prototype.startsWith = function(searchString, position) {
+ position = position || 0;
+ return this.indexOf(searchString, position) === position;
+}
+var Playercontrols = {
+
+ stopInterval: false,
+
+ initYoutubeControls: function()
+ {
+ if(window.mobilecheck() && !/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream){
+ $("#controls").appendTo("#playbar");
+ }
+ Playercontrols.initControls();
+ },
+
+ initControls: function()
+ {
+ document.getElementById("volume-button").addEventListener("click", Playercontrols.mute_video);
+ document.getElementById("playpause").addEventListener("click", Playercontrols.play_pause);
+ document.getElementById("fullscreen").addEventListener("click", Playercontrols.fullscreen);
+
+ },
+
+ initSlider: function()
+ {
+ try{
+ vol = (Crypt.get_volume());
+ }catch(e){}
+ $("#volume").slider({
+ min: 0,
+ max: 100,
+ value: vol,
+ range: "min",
+ animate: true,
+ slide: function(event, ui) {
+
+ Playercontrols.setVolume(ui.value);
+ //localStorage.setItem("volume", ui.value);
+ try{Crypt.set_volume(ui.value);}catch(e){}
+ }
+ });
+ Playercontrols.choose_button(vol, false);
+ //$("#volume").slider("value", ytplayer.getVolume());
+ },
+
+ fullscreen: function()
+ {
+ var playerElement = document.getElementById("player");
+ var requestFullScreen = playerElement.requestFullScreen || playerElement.mozRequestFullScreen || playerElement.webkitRequestFullScreen;
+ if (requestFullScreen) {
+ requestFullScreen.bind(playerElement)();
+ }
+ },
+
+ play_pause: function()
+ {
+
+ if(Youtube.ytplayer.getPlayerState() == 1)
+ {
+ Youtube.ytplayer.pauseVideo();
+ if(window.mobilecheck() && !/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream)
+ document.getElementById("player").style.display = "none";
+ }else if(Youtube.ytplayer.getPlayerState() == 2 || Youtube.ytplayer.getPlayerState() == 0)
+ {
+ Youtube.ytplayer.playVideo();
+ if(window.mobilecheck() && !/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream)
+ document.getElementById("player").style.display = "block";
+ }
+ },
+
+ settings: function()
+ {
+ $("#qS").toggleClass("hide");
+ },
+
+ changeQuality: function(wantedQ)
+ {
+ if(Youtube.ytplayer.getPlaybackQuality != wantedQ)
+ {
+ Youtube.ytplayer.setPlaybackQuality(wantedQ);
+ Youtube.ytplayer.getPlaybackQuality();
+ }
+ $("#qS").toggleClass("hide");
+ },
+
+ mute_video: function()
+ {
+ if(!Youtube.ytplayer.isMuted())
+ {
+ Playercontrols.choose_button(0, true);
+ Youtube.ytplayer.mute();
+ }else
+ {
+ Youtube.ytplayer.unMute();
+ Playercontrols.choose_button(Youtube.ytplayer.getVolume(), false);
+ }
+ },
+
+ setVolume: function(vol)
+ {
+ Youtube.ytplayer.setVolume(vol);
+ Playercontrols.choose_button(vol, false);
+ if(Youtube.ytplayer.isMuted())
+ Youtube.ytplayer.unMute();
+ },
+
+ choose_button: function(vol, mute)
+ {
+ if(!mute){
+ if(vol >= 0 && vol <= 33){
+ if(document.getElementById("v-full").className.split(" ").length == 1)
+ $("#v-full").toggleClass("hide");
+ if(document.getElementById("v-medium").className.split(" ").length == 1)
+ $("#v-medium").toggleClass("hide");
+ if(document.getElementById("v-low").className.split(" ").length == 2)
+ $("#v-low").toggleClass("hide");
+ if(document.getElementById("v-mute").className.split(" ").length == 1)
+ $("#v-mute").toggleClass("hide");
+ }else if(vol >= 34 && vol <= 66){
+ if(document.getElementById("v-full").className.split(" ").length == 1)
+ $("#v-full").toggleClass("hide");
+ if(document.getElementById("v-medium").className.split(" ").length == 2)
+ $("#v-medium").toggleClass("hide");
+ if(document.getElementById("v-low").className.split(" ").length == 1)
+ $("#v-low").toggleClass("hide");
+ if(document.getElementById("v-mute").className.split(" ").length == 1)
+ $("#v-mute").toggleClass("hide");
+ }else if(vol >= 67 && vol <= 100){
+ if(document.getElementById("v-full").className.split(" ").length == 2)
+ $("#v-full").toggleClass("hide");
+ if(document.getElementById("v-medium").className.split(" ").length == 1)
+ $("#v-medium").toggleClass("hide");
+ if(document.getElementById("v-low").className.split(" ").length == 1)
+ $("#v-low").toggleClass("hide");
+ if(document.getElementById("v-mute").className.split(" ").length == 1)
+ $("#v-mute").toggleClass("hide");
+ }
+ }else
+ {
+ if(document.getElementById("v-full").className.split(" ").length == 1)
+ $("#v-full").toggleClass("hide");
+ if(document.getElementById("v-medium").className.split(" ").length == 1)
+ $("#v-medium").toggleClass("hide");
+ if(document.getElementById("v-low").className.split(" ").length == 1)
+ $("#v-low").toggleClass("hide");
+ if(document.getElementById("v-mute").className.split(" ").length == 2)
+ $("#v-mute").toggleClass("hide");
+ }
+ },
+
+ playPause: function()
+ {
+ state = Youtube.ytplayer.getPlayerState();
+ button = document.getElementById("playpause");
+ if(state == 1)
+ {
+ Youtube.ytplayer.pauseVideo();
+ }else if(state == 2)
+ {
+ Youtube.ytplayer.playVideo();
+ }
+ },
+
+ volumeOptions: function()
+ {
+ if(Youtube.ytplayer.isMuted())
+ {
+ Youtube.ytplayer.unMute();
+ vol = Youtube.ytplayer.getVolume();
+ $("#volume").slider("value", Youtube.ytplayer.getVolume());
+ }
+ else
+ {
+ Youtube.ytplayer.mute();
+ $("#volume").slider("value", 0);
+ }
+ },
+
+ hoverMute: function(foo)
+ {
+ vol = Youtube.ytplayer.getVolume();
+
+ }
+
+}
+var List = {
+
+ channel_listener: function()
+ {
+ socket.on("channel", function(msg){
+ List.channel_function(msg);
+ });
+ },
+
+ channel_function: function(msg)
+ {
+
+ switch(msg[0])
+ {
+ case "list":
+ List.populate_list(msg[1]);
+ break;
+ case "added":
+ List.added_song(msg[1]);
+ break;
+ case "deleted":
+ List.deleted_song(msg[1]);
+ break;
+ case "vote":
+ List.voted_song(msg[1], msg[2]);
+ break;
+ case "song_change":
+ List.song_change(msg[1]);
+ break;
+ }
+ },
+
+ populate_list: function(msg)
+ {
+
+ full_playlist = msg;
+
+ List.sortList();
+ $("#wrapper").empty();
+
+ $.each(full_playlist, function(j, current_song){
+ if(!current_song.now_playing){ //check that the song isnt playing
+ $("#wrapper").append(List.generateSong(current_song, false, lazy_load, true));
+ }
+ });
+
+
+ if(lazy_load){
+ if(window.mobilecheck()) $(".list-image").lazyload({});
+ else $(".list-image").lazyload({container: $("#wrapper")}).removeClass("lazy");
+ }
+ $("#settings").css("visibility", "visible");
+ $("#settings").css("opacity", "1");
+ $("#wrapper").css("opacity", "1");
+
+ },
+
+ added_song: function(added){
+ full_playlist.push(added);
+ List.sortList();
+ $("#suggested-"+added.id).remove();
+ List.insertAtIndex(added, true);
+ },
+
+ deleted_song: function(deleted){
+
+ var index = List.getIndexOfSong(deleted);
+ var to_delete = $("#wrapper").children()[index];
+ try{
+ to_delete.style.height = 0;
+
+ setTimeout(function()
+ {
+ $("#"+deleted).remove();
+ full_playlist.splice(List.getIndexOfSong(deleted), 1);
+ }, 305);
+
+ document.getElementById('wrapper').scrollTop += 1;
+ document.getElementById('wrapper').scrollTop += -1;
+ }catch(err){
+ full_playlist.splice(List.getIndexOfSong(deleted), 1);
+ $("#wrapper").children()[$("#wrapper").children().length-1].remove();
+ }
+ $("#suggested-"+deleted).remove();
+ Suggestions.checkUserEmpty();
+ },
+
+ voted_song: function(voted, time){
+ var index_of_song = List.getIndexOfSong(voted);
+ var song_voted_on = full_playlist[index_of_song];
+
+ full_playlist[index_of_song].votes += 1;
+ full_playlist[index_of_song].added = time;
+
+ List.sortList();
+ $("#"+voted).remove();
+ List.insertAtIndex(song_voted_on, false);
+ },
+
+ song_change: function(time){
+ var length = full_playlist.length-1;
+
+ full_playlist[0].now_playing = true;
+ full_playlist[0].votes = 0;
+ full_playlist[0].guids = [];
+ full_playlist[0].added = time;
+ full_playlist[length].now_playing = false;
+
+ full_playlist.push(full_playlist.shift());
+ $("#wrapper").children()[0].remove();
+
+ List.insertAtIndex(full_playlist[length-1], false);
+ document.getElementById('wrapper').scrollTop += 1;
+ document.getElementById('wrapper').scrollTop += -1;
+ },
+
+ vote: function(id, vote){
+ socket.emit('vote', [chan, id, vote, adminpass]);
+ return true;
+ },
+
+ skip: function(){
+ socket.emit('skip', {pass: adminpass, id:video_id});
+ return true;
+ },
+
+ importOldList: function(chan){
+ var ids="";
+ var num=0;
+
+ playlist_url = "lists/"+chan+".json";
+
+ list = $.parseJSON($.ajax({
+ type: "GET",
+ url: playlist_url,
+ async: false
+ }).responseText);
+
+ $.each(list.songs, function(i,data)
+ {
+ ids+=data.id+",";
+
+ if(num>45){
+ Search.addVideos(ids);
+
+ ids = "";
+ num = 0;
+ }
+ num++;
+ });
+
+ Search.addVideos(ids);
+ document.getElementById("search").value = "";
+ },
+
+ sortList: function()
+ {
+ full_playlist.sort(Helper.predicate({
+ name: 'votes',
+ reverse: true
+ }, 'added'));
+ },
+
+ show: function(){
+ if(!window.mobilecheck())
+ {
+ if(showToggle){
+ showToggle=false;
+ $("#toptitle").empty();
+ $("#chan").addClass("bigChan");
+ //$("#chan").html("zoff.no/"+encodeURI(chan));
+ $("#chan").html("zoff.no/"+chan.toLowerCase());
+ }else{
+ showToggle=true;
+ $("#toptitle").html("Zöff");
+ $("#chan").removeClass("bigChan");
+ $("#chan").html(chan);
+ }
+ }
+ },
+
+ insertAtIndex: function(song_info, transition) {
+ i = List.getIndexOfSong(song_info.id);
+
+ if(i === 0)
+ $("#wrapper").prepend(List.generateSong(song_info, transition, false, true, false));
+ else
+ $("#wrapper > div:nth-child(" + (i) + ")").after(List.generateSong(song_info, transition, false, true, false));
+
+ if(transition)
+ {
+ setTimeout(function(){
+ var added = $("#wrapper").children()[i];
+ $(added).css("height", 66);
+ },5);
+ }
+ },
+
+ generateSong: function(song_info, transition, lazy, list, user)
+ {
+ var video_id = song_info.id;
+ var video_title = song_info.title;
+ var video_votes = song_info.votes;
+ var video_thumb = "background-image:url('//img.youtube.com/vi/"+video_id+"/mqdefault.jpg');";
+ var song = $("
"+list_html+"
");
+ var image_attr = "style";
+
+ var attr;
+ var del_attr;
+
+ if(transition) song.find("#list-song").css("height", 0);
+ if(!w_p) song.find(".card-action").removeClass("hide");
+ if(video_votes == 1)song.find(".vote-text").text("vote");
+ if(lazy){
+ video_thumb = "//img.youtube.com/vi/"+video_id+"/mqdefault.jpg";
+ image_attr = "data-original";
+ }
+
+ if(list){
+ song.find(".list-votes").text(video_votes);
+ song.find("#list-song").attr("id", video_id);
+
+ attr = ".vote-container";
+ del_attr = "del";
+ }else if(!list){
+
+ song.find(".vote-text").text(song_info.duration);
+
+ attr = ".add-suggested";
+ if(user)
+ del_attr = "del_user_suggested";
+ else
+ del_attr = "del_suggested";
+
+ song.find(".vote-container").attr("class", "clickable add-suggested");
+ song.find(".add-suggested").attr("title", "Add song!");
+ song.find("#del").attr("id", del_attr);
+ song.find(attr).attr("data-video-title", video_title);
+ song.find(attr).attr("data-video-length", song_info.length);
+ song.find("#list-song").attr("id", "suggested-" + video_id);
+ song.find(".list-image").attr("class", song.find(".list-image").attr("class").replace("list-image", "list-suggested-image"));
+
+ }
+
+ song.find(".list-title").text(video_title);
+ song.find(".list-title").attr("title", video_title);
+ //song.find(".vote-container").attr("onclick", "vote('"+video_id+"','pos')");
+ song.find(attr).attr("data-video-id", video_id);
+ song.find(".list-image").attr(image_attr,video_thumb);
+ song.find(".list-suggested-image").attr(image_attr,video_thumb);
+ song.find("#"+del_attr).attr("data-video-id", video_id);
+ //song.find("#del").attr("onclick", "vote('"+video_id+"', 'del')");
+
+ return song.html();
+ },
+
+ getIndexOfSong: function(id)
+ {
+ indexes = $.map(full_playlist, function(obj, index) {
+ if(obj.id == id) {
+ return index;
+ }
+ });
+ return indexes[0];
+ }
+}
+
+var song_title = "";
+var paused = false;
+var player_ready = false;
+var list_html = $("#list-song-html").html();
+var w_p = true;
+var lazy_load = false;
+var embed = true;
+var vol = 100;
+var adminpass = "";
+
+var seekTo;
+var socket;
+var video_id;
+var previous_video_id;
+var chan = ($("#zoffchannel").html()).toLowerCase();
+
+var connection_options = {
+ 'sync disconnect on unload':true,
+ 'secure': true,
+ 'force new connection': true
+};
+
+$(document).ready(function(){
+ console.log("loadshit");
+
+ $("head").append('
');
+ $("head").append('
');
+
+ if(window.location.hostname != "zoff.no") add = "https://zoff.no";
+ else add = "localhost";
+ socket = io.connect(''+add+':8880', connection_options);
+
+ socket.on("get_list", function(){
+ setTimeout(function(){socket.emit('list', chan.toLowerCase())},1000);
+ });
+
+ Youtube.setup_youtube_listener(chan);
+ List.channel_listener();
+
+
+ window.onYouTubeIframeAPIReady = Youtube.onYouTubeIframeAPIReady;
+
+ Youtube.loadPlayer();
+
+ Playercontrols.initSlider();
+});
+
+$(document).on( "click", ".vote-container", function(e){
+ var id = $(this).attr("data-video-id");
+ List.vote(id, "pos");
+});
\ No newline at end of file
diff --git a/static/dist/main.min.js b/static/dist/main.min.js
old mode 100644
new mode 100755
index 5372d0bc..75e2af17
--- a/static/dist/main.min.js
+++ b/static/dist/main.min.js
@@ -1,2 +1,2 @@
-!function(){function e(){T=$("#chan").html(),"zoff.no"==window.location.hostname?add="https://zoff.no":add="localhost",C=io.connect(""+add+":8880",Z),C.on("get_list",function(){setTimeout(function(){C.emit("list",T.toLowerCase())},1e3)}),C.on("suggested",function(e){var t=!0;void 0==e.id&&(t=!1),setTimeout(function(){te.catchUserSuggests(e,t)},1e3)}),setTimeout(function(){oe.stopInterval=!1,localStorage.list_update&&"13.06.15"==localStorage.list_update||(localStorage.setItem("list_update","13.06.15"),window.location.reload(!0)),oe.setup_youtube_listener(T),o.admin_listener(),I.channel_listener(),I.skipping_listener(),$("ul.tabs").tabs(),$("#settings").sideNav({menuWidth:300,edge:"right",closeOnClick:!1}),$(".collapsible").collapsible({accordion:!0}),$(".video-container").resizable({start:function(e,t){$("iframe").css("pointer-events","none")},stop:function(e,t){$("iframe").css("pointer-events","auto"),a.set_width($(this).width())},handles:"e",minWidth:350}),/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream?(document.getElementById("search").blur(),oe.readyLooks()):(n.setup_chat_listener(T),n.allchat_listener(),S.host_listener(),window.onYouTubeIframeAPIReady=oe.onYouTubeIframeAPIReady,oe.loadPlayer(),$("#chat-btn").sideNav({menuWidth:272,edge:"left",closeOnClick:!1}),$(".drag-target")[1].remove(),i.msieversion()||Notification.requestPermission(),navigator.userAgent.toLowerCase().indexOf("firefox")>-1&&$(".main").height(window.innerHeight-64),git_info=$.ajax({type:"GET",url:"https://api.github.com/repos/zoff-music/zoff/commits",async:!1}).responseText,git_info=$.parseJSON(git_info),$("#latest-commit").html("Latest Commit:
"+git_info[0].commit.author.date.substring(0,10)+": "+git_info[0].committer.login+"
"+git_info[0].sha.substring(0,10)+" : "+git_info[0].commit.message+"
150||(e.value.startsWith("/name ")?C.emit("namechange",e.value.substring(6)):"#all_chat"==$(".tab a.active").attr("href")?C.emit("all,chat",e.value):C.emit("chat",e.value),e.value="")},allchat_listener:function(){C.on("chat.all",function(e){0!=$("#chat-bar").position().left?P||($("#favicon").attr("href","static/images/highlogo.png"),P=!0,A=!0,d=setInterval(n.chat_blink,2e3)):document.hidden&&($("#favicon").attr("href","static/images/highlogo.png"),A=!0);var t=i.intToARGB(i.hashCode(e[0])).substring(0,6);$("#chatall").append("