// ==UserScript==
// @name Save
// @namespace http://m...content-available-to-author-only...s.com/*
// @include http://m...content-available-to-author-only...s.com/G*******
// @version 1
// @require http://a...content-available-to-author-only...s.com/ajax/libs/jquery/2.2.2/jquery.min.js
// @grant all
// ==/UserScript==
$(document).ready(function () {
if (/^http:\/\/motherless\.com\/G[^\/]{0,7}$/.test(window.location)) {
type_url = [
];
getInfo();
makeBox();
}
});
function getInfo() {
g_id = (window.location).toString().match(/http:\/\/motherless\.com\/G([^\/]{0,7})/) [1];
g_title = $('.content-title').html();
g_img = $('.sub_menu').html().match(/.+Images .+\[ (.+) \].+/) [1];
g_vid = $('.sub_menu').html().match(/.+Videos .+\[ (.+) \].+/) [1];
}
function makeBox() {
$('body').append('<div id="box"></div>');
$('#box').css('z-index', '9999').css('position', 'fixed').css('top', '0').css('right', '0');
$('#box').css('background-color', 'rgba(255,255,255,0.9)').css('color', '#000000');
$('#box').append('<div style="font-size:20px;">' + g_title + '</div>');
$('#box').append('<div class="box_img"><a href="">Images: ' + g_img + '</a></div>');
$('#box').append('<div class="box_vid"><a href="">Videos: ' + g_vid + '</a></div>');
$('#box').append('<div class="box_img_ok"></div>');
$('#box').append('<div class="box_vid_ok"></div>');
}
$(document).on('click', '.box_img', function () {
img_list = [
];
$('#box .box_img_ok').html('Wait Images [' + 0 + '/' + g_img + ']');
getUrls('images', 1);
return false;
});
$(document).on('click', '.box_vid', function () {
vid_list = [
];
$('#box .box_vid_ok').html('Wait Videos [' + 0 + '/' + g_vid + ']');
getUrls('videos', 1);
return false;
});
function getUrls(type, page = 1) {
type_url['images'] = 'I';
type_url['videos'] = 'V';
$.ajax({
url: 'http://m...content-available-to-author-only...s.com/G' + type_url[type] + g_id + '?page=' + page,
success: function (data) {
$(data).find('a.img-container img').each(function () {
file_info = $(this).attr('src').match(/http:\/\/([a-zA-Z0-9]+)\.thumbs\.motherlessmedia\.com\/thumbs\/([A-Z0-9]+)-(zoom|small)\.(png|jpg|gif|bmp|jpeg)\?from_helper/);
if (type == 'videos') file_info[4] = 'mp4';
file_url = 'http://' + file_info[1] + '.' + type + '.motherlessmedia.com/' + type + '/' + file_info[2] + '.' + file_info[4];
switch (type) {
case 'images':
img_list.push(file_url);
$('#box .box_img_ok').html('Wait Images [' + img_list.length + '/' + g_img + ']');
break;
case 'videos':
vid_list.push(file_url);
$('#box .box_vid_ok').html('Wait Videos [' + vid_list.length + '/' + g_vid + ']');
break;
}
}); /* есть ли ссылка не следующую страницу?*/
if ($(data).find('a:contains(\'NEXT\')').html() !== undefined) {
// есть
nextPage = page + 1;
getUrls(type, nextPage);
} else {
// нет
switch (type) {
case 'images':
$('#box .box_img_ok').html('[Images OK] : Open <a id="img_links" href="">Links</a> or <a id="img_pics" href="">Pics</a>');
break;
case 'videos':
$('#box .box_vid_ok').html('[Videos OK] : Open <a id="vid_links" href="">Links</a> or <a id="vid_pics" href="">Pics</a>');
break;
}
}
}, error: function () {
alert('error');
}
});
}
$(document).on('click', '#img_links', function () {
newWin(g_title + ' (' + g_id + ')' + ' img links', img_list.join('<br/>'));
return false;
});
$(document).on('click', '#img_pics', function () {
content = '';
for (var i = 0; i < img_list.length; i++) {
content = content + '<img alt="" src="' + img_list[i] + '" />';
}
newWin(g_title + ' (' + g_id + ')' + ' Images', content);
return false;
});
$(document).on('click', '#vid_links', function () {
newWin(g_title + ' (' + g_id + ')' + ' vid links', vid_list.join('<br/>'));
return false;
});
$(document).on('click', '#vid_pics', function () {
content = '';
for (var i = 0; i < vid_list.length; i++) {
content = content + '<img alt="" src="' + vid_list[i] + '" />';
}
newWin(g_title + ' (' + g_id + ')' + ' Videos', content);
return false;
});
function newWin(title, content) {
html = '<html>';
html = html + '<head><title>' + title + '</title></head>';
html = html + '</body><code>[ПКМ + Сохранить как]</code><div style="display:none;">';
html = html + content;
html = html + '</div></body>';
html = html + '</html>';
uri = 'data:text/html;charset=utf-8,' + encodeURIComponent(html);
newWindow = window.open(uri);
}