Skip to content

Instantly share code, notes, and snippets.

@tiagocpontesp
Created July 11, 2012 10:59
Show Gist options
  • Save tiagocpontesp/3089686 to your computer and use it in GitHub Desktop.
Save tiagocpontesp/3089686 to your computer and use it in GitHub Desktop.
$(document).ready(function(){
if(!$.cookie) {
/*jshint eqnull:true */
/*!
* jQuery Cookie Plugin v1.1
* https://github.com/carhartl/jquery-cookie
*
* Copyright 2011, Klaus Hartl
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://www.opensource.org/licenses/mit-license.php
* http://www.opensource.org/licenses/GPL-2.0
*/
(function(a,b){function d(a){return a}function e(a){return decodeURIComponent(a.replace(c," "))}var c=/\+/g;a.cookie=function(c,f,g){if(arguments.length>1&&(!/Object/.test(Object.prototype.toString.call(f))||f==null)){g=a.extend({},a.cookie.defaults,g);if(f==null){g.expires=-1}if(typeof g.expires==="number"){var h=g.expires,i=g.expires=new Date;i.setDate(i.getDate()+h)}f=String(f);return b.cookie=[encodeURIComponent(c),"=",g.raw?f:encodeURIComponent(f),g.expires?"; expires="+g.expires.toUTCString():"",g.path?"; path="+g.path:"",g.domain?"; domain="+g.domain:"",g.secure?"; secure":""].join("")}g=f||a.cookie.defaults||{};var j=g.raw?d:e;var k=b.cookie.split("; ");for(var l=0,m;m=k[l]&&k[l].split("=");l++){if(j(m.shift())===c){return j(m.join("="))}}return null};a.cookie.defaults={}})(jQuery,document);
}
var
DEBUG = false,
MINUTES = 60,
SKIPS = 5,
expiration_date = new Date();
expiration_date.setTime(expiration_date.getTime() + ( MINUTES * 60 * 1000));
$('.next , .prev').click(function(){
if($.cookie("skips_remaining")===null) {
$.cookie("skips_remaining", SKIPS, { expires: expiration_date , path: window.location.pathname });
if(DEBUG)console.log('LIMITED_SKIPS: '+(expiration_date.getTime()/1000)+'more secs within period of time');
if(DEBUG)setTimeout(function(){console.log('LIMITED_SKIPS: time period expired');},MINUTES*60*1000);
}
else {
var
isMywayPlayerFree = player.permits('skip',false) && !player.permits('jump',false),
isFado = window.location.href.indexOf('fado')!==-1,
isWidget = window.location.href.indexOf('widget')!==-1;
if(isMywayPlayerFree || isFado || isWidget) {
if(DEBUG)console.log('LIMITED_SKIPS: is elligible');
if(+$.cookie("skips_remaining")===1) {
if(player.models && player.models.auth && player.models && player.models.auth.canNextAndPrev) {
player.models.auth.canNextAndPrev = false;
}
else {
player.permits = function (a,b){b==null&&(b=!0);if(player.god)return!0;switch(a){case"skip":return false;case"seek":return!1;case"announcements":return!0;case"jump":return!1;case"fullyPlaySearchedAlbumsAndSongs":return!0;case"download":return!1}};
}
if(DEBUG)console.log('LIMITED_SKIPS: limit reached - skips disabled');
}
else {
if(player.models && player.models.auth && player.models && player.models.auth.canNextAndPrev) {
player.models.auth.canNextAndPrev = true;
}
else {
player.permits = function (a,b){b==null&&(b=!0);if(player.god)return!0;switch(a){case"skip":return true;case"seek":return!1;case"announcements":return!0;case"jump":return!1;case"fullyPlaySearchedAlbumsAndSongs":return!0;case"download":return!1}};
}
var skips_remaining = +$.cookie("skips_remaining")-1;
$.cookie("skips_remaining", null);
$.cookie("skips_remaining", skips_remaining, { expires: expiration_date , path: window.location.pathname });
if(DEBUG)console.log('LIMITED_SKIPS: '+skips_remaining+'skips remaining');
}
}
else {
if(DEBUG)console.log('LIMITED_SKIPS: isn\'t elligible');
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment