2017-08-20 13:01:58 -07:00
|
|
|
|
$(function () {
|
2017-07-22 22:20:37 -07:00
|
|
|
|
function err(msg) {
|
|
|
|
|
alert(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createFeed(data, done) {
|
|
|
|
|
if (!data.url) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
dataType: 'text',
|
2017-08-20 13:01:58 -07:00
|
|
|
|
url: '/api/create',
|
2017-07-22 22:20:37 -07:00
|
|
|
|
method: 'POST',
|
|
|
|
|
data: JSON.stringify(data),
|
|
|
|
|
contentType: 'application/json; charset=utf-8',
|
2017-09-08 15:54:40 -07:00
|
|
|
|
success: function (resp) {
|
|
|
|
|
done(JSON.parse(resp));
|
2017-07-22 22:20:37 -07:00
|
|
|
|
},
|
|
|
|
|
error: function (xhr, status, error) {
|
2017-08-20 13:01:58 -07:00
|
|
|
|
var text = '';
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
var json = JSON.parse(xhr.responseText);
|
|
|
|
|
if (json['error']) {
|
|
|
|
|
text = json['error'];
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
text = xhr.responseText;
|
2017-07-22 22:20:37 -07:00
|
|
|
|
}
|
2017-08-20 13:01:58 -07:00
|
|
|
|
|
|
|
|
|
err(text);
|
2017-07-22 22:20:37 -07:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-08 15:54:40 -07:00
|
|
|
|
function displayLink(obj) {
|
|
|
|
|
var addr = location.protocol + '//' + location.hostname + '/' + obj.id;
|
|
|
|
|
showModal(addr);
|
2017-07-22 22:20:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Tooltips
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!isMobile()) {
|
|
|
|
|
$(document).on('mouseenter', 'i', function () {
|
|
|
|
|
var title = $(this).attr('title');
|
|
|
|
|
if (!title) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(this).data('tipText', title).removeAttr('title');
|
|
|
|
|
$('<p class="tooltip"></p>').text(title).appendTo('body').fadeIn('fast');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$(document).on('mouseleave', 'i', function () {
|
|
|
|
|
var text = $(this).data('tipText');
|
|
|
|
|
$(this).attr('title', text);
|
|
|
|
|
$('.tooltip').remove();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$(document).on('mousemove', 'i', function (e) {
|
|
|
|
|
var x = e.pageX + 10;
|
|
|
|
|
var y = e.pageY + 5;
|
|
|
|
|
$('.tooltip').css({ top: y, left: x });
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Handlers
|
|
|
|
|
*/
|
|
|
|
|
|
2017-08-20 13:01:58 -07:00
|
|
|
|
function getFormat() {
|
2017-10-22 23:25:14 -07:00
|
|
|
|
return $('input[name=episode_format]:checked').val();
|
2017-08-20 13:01:58 -07:00
|
|
|
|
}
|
2017-07-22 22:20:37 -07:00
|
|
|
|
|
2017-08-20 13:01:58 -07:00
|
|
|
|
function getQuality() {
|
2017-10-22 23:25:14 -07:00
|
|
|
|
return $('input[name=episode_quality]:checked').val();
|
2017-07-22 22:20:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getPageCount() {
|
|
|
|
|
try {
|
2017-10-22 23:25:14 -07:00
|
|
|
|
var text = $('input[name=page_count]:checked').val();
|
2017-07-22 22:20:37 -07:00
|
|
|
|
return parseInt(text);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return 50;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Modal */
|
|
|
|
|
|
|
|
|
|
function closeModal() {
|
|
|
|
|
$('#modal').hide();
|
|
|
|
|
$('#url-input').val('');
|
|
|
|
|
$('.main').show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showModal(url) {
|
|
|
|
|
// Hide main block on screen
|
|
|
|
|
$('.main').hide();
|
|
|
|
|
|
|
|
|
|
// Set input URL
|
|
|
|
|
$('#output-input').val(url);
|
|
|
|
|
|
|
|
|
|
// Update 'Open' button link
|
|
|
|
|
$('#modal-open').attr('href', url);
|
|
|
|
|
|
|
|
|
|
// Show dialog itself
|
|
|
|
|
$('#modal').show();
|
|
|
|
|
|
|
|
|
|
// Select modal output text
|
|
|
|
|
$('#output-input').select();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function copyLink() {
|
|
|
|
|
$('#output-input').select();
|
|
|
|
|
if (!document.execCommand('copy')) {
|
|
|
|
|
err('Can\'t copy... Something went wrong...');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isMobile() {
|
|
|
|
|
return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function canCopy() {
|
|
|
|
|
try {
|
|
|
|
|
return document.queryCommandSupported('copy') && !isMobile();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('body').on('keydown', function (e) {
|
|
|
|
|
// ESC
|
|
|
|
|
if ($('#modal').is(':visible') && e.keyCode === 27) {
|
|
|
|
|
$('#close-modal').click();
|
|
|
|
|
}
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Attach handlers
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
$('#get-link').click(function(e) {
|
|
|
|
|
var url = $('#url-input').val();
|
2017-08-20 13:01:58 -07:00
|
|
|
|
createFeed({ url: url, format: getFormat(), quality: getQuality(), page_size: getPageCount() }, displayLink);
|
2017-07-22 22:20:37 -07:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#url-input').keyup(function (e) {
|
|
|
|
|
// 'Enter' click
|
|
|
|
|
if (e.keyCode === 13) {
|
|
|
|
|
$('#get-link').click();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#close-modal').click(closeModal);
|
|
|
|
|
$('#modal-copy').click(copyLink);
|
|
|
|
|
|
|
|
|
|
if (!canCopy()) {
|
|
|
|
|
$('#modal-copy').hide();
|
|
|
|
|
}
|
|
|
|
|
});
|