Skip to content

Instantly share code, notes, and snippets.

@0xdevalias
Last active Aug 29, 2015
Embed
What would you like to do?
// http://slurm.trakt.us/js/show/episode.20130474.js
if (document.id('check-in')) {
document.id('check-in').addEvent('click', function () {
if (!window.signedIn) {
Cookie.write('checkinEpisode', '1');
window.signInMessage = 'You need to sign in before you can check into this episode!<br /><a href="#" onclick="resetForms(); document.id(\'header-join\').fireEvent(\'click\'); return false;">Join for free</a> if you don\'t have an account already.';
document.id('header-signin').fireEvent('click');
return false;
}
document.id('check-in-close').setStyle('display', 'none');
document.id('check-in-loader').setStyle('display', 'none');
document.id('check-in-yes').setStyle('display', 'block');
document.id('check-in-success').setStyle('display', 'none');
document.id('check-in-error').setStyle('display', 'none');
document.id('overlay-bg').setStyle('display', 'block');
document.id('overlay-check-in').setStyle('display', 'block');
return false;
});
var _cookie = Cookie.read('checkinEpisode');
if (_cookie) {
Cookie.dispose('checkinEpisode');
if (window.signedIn) document.id('check-in').fireEvent('click');
}
if (document.id('check-in-yes')) {
document.id('check-in-yes').addEvent('click', function () {
document.id('check-in-loader').setStyle('display', 'block');
document.id('check-in-yes').setStyle('display', 'none');
document.id('check-in-close').setStyle('display', 'none');
document.id('check-in-error').setStyle('display', 'none');
document.id('check-in-success').setStyle('display', 'none');
new Request.JSON({
url: '/api/show/checkin',
method: 'post',
onSuccess: function (json) {
document.id('check-in-loader').setStyle('display', 'none');
if (json.status == 'success') {
document.id('check-in-success').set('html', "You're all checked in!");
document.id('check-in-success').setStyle('display', 'block');
document.id('check-in-close').setStyle('display', 'block');
(function () {
document.id('overlay-bg').fadeOut(0.8);
document.id('overlay-check-in').fadeOut(1);
}).delay(2000);
} else {
document.id('check-in-error').set('html', json.error);
document.id('check-in-error').setStyle('display', 'block');
document.id('check-in-yes').setStyle('display', 'block');
}
}
}).send(JSON.encode({
tvdb_id: document.id('meta-tvdb-id').get('value'),
title: document.id('meta-title').get('value').replace('=', ' '),
year: document.id('meta-year').get('value'),
season: document.id('meta-season').get('value'),
episode: document.id('meta-episode').get('value'),
message: document.id('check-in-message').get('value').replace('=', ' ').replace('+', ' '),
share: {
facebook: document.id('check-in-share-facebook').hasClass('active'),
twitter: document.id('check-in-share-twitter').hasClass('active'),
tumblr: document.id('check-in-share-tumblr').hasClass('active'),
path: document.id('check-in-share-path').hasClass('active'),
foursquare: document.id('check-in-share-foursquare').hasClass('active')
}
}));
return false;
});
document.id('check-in-close').addEvent('click', function () {
document.id('overlay-bg').setStyle('display', 'none');
$$('.overlay-popup').setStyle('display', 'none');
});
$$('#overlay-check-in .social img').addEvent('click', function () {
if (this.hasClass('active')) this.removeClass('active');
else this.addClass('active');
return false;
});
var message = document.id('check-in-message');
var messageCharsLeft = document.id('check-in-message-chars-left');
if (message && messageCharsLeft) {
message.addEvent('keyup', function () {
var maxlength = message.get('maxlength') || 110;
messageCharsLeft.set('html', maxlength.toInt() - message.get('value').length);
});
message.fireEvent('keyup');
}
}
if (document.id('check-in-now')) {
document.id('check-in-now').addEvent('click', function () {
this.addClass('active');
document.id('check-in-previously').removeClass('active');
document.id('check-in-seen').hide();
document.id('check-in-yes').show();
document.id('check-in-datetime-wrapper').hide();
document.id('check-in-now-wrapper').show();
});
document.id('check-in-now').fireEvent('click');
}
if (document.id('check-in-previously')) {
document.id('check-in-previously').addEvent('click', function () {
this.addClass('active');
document.id('check-in-now').removeClass('active');
document.id('check-in-seen').show();
document.id('check-in-yes').hide();
document.id('check-in-datetime-wrapper').show();
document.id('check-in-now-wrapper').hide();
});
var use24 = document.id('check-in-use24').get('value') == 1;
var maxDate = new Date(document.id('check-in-max-ts').get('value'));
var start = $("#check-in-datetime").kendoDateTimePicker({
value: maxDate,
format: use24 ? 'MMM d yyyy HH:mm' : 'MMM d yyyy h:mm tt',
timeFormat: use24 ? 'HH:mm' : 'h:mm tt',
parseFormats: ["MM/dd/yyyy", "yyyy/MM/dd"],
interval: 15,
max: maxDate,
depth: 'month'
}).data("kendoDateTimePicker");
}
if (document.id('check-in-seen')) {
document.id('check-in-seen').addEvent('click', function () {
document.id('check-in-loader').show();
$$('#check-in-seen, #check-in-close, #check-in-error, #check-in-success').hide();
new Request.JSON({
url: '/api/show/episode/seen',
method: 'post',
onSuccess: function (json) {
document.id('check-in-loader').hide();
if (json.status == 'success') {
document.id('check-in-success').set('html', "Marked as previously watched!");
document.id('check-in-success').show();
document.id('check-in-close').show();
(function () {
document.id('overlay-bg').fadeOut(0.8);
document.id('overlay-check-in').fadeOut(1);
}).delay(2000);
} else {
document.id('check-in-error').set('html', json.error);
document.id('check-in-error').show();
document.id('check-in-seen').show;
}
}
}).send(JSON.encode({
tvdb_id: document.id('meta-tvdb-id').get('value'),
title: document.id('meta-title').get('value').replace('=', ' '),
year: document.id('meta-year').get('value'),
episodes: [{
season: document.id('meta-season').get('value'),
episode: document.id('meta-episode').get('value'),
last_played: document.id('check-in-datetime').get('value')
}]
}));
return false;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment