Sadpanda Save/Export All Favorites

Load all favorites to the page and save it or just copy the textbox contents. Works on exhentai and e-hentai.

08.04.2018 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name        Sadpanda Save/Export All Favorites
// @namespace   SaddestPanda
// @description Load all favorites to the page and save it or just copy the textbox contents. Works on exhentai and e-hentai.
// @include     /^https?://e.*hentai.org/favorites.php.*/
// @homepage    https://sleazyfork.org/en/scripts/23406-sadpanda-save-export-all-favorites
// @supportURL  https://sleazyfork.org/en/scripts/23406-sadpanda-save-export-all-favorites/feedback
// @version     2.0.1
// @grant       none
// @require     https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @require     https://cdn.rawgit.com/mathiasbynens/he/670991a4141d01dc015de5194d400d01c863208f/he.js
// ==/UserScript==

//Top text box inspiration and its code from http://userscripts-mirror.org/scripts/show/173553. But this one won't have an import feature like that one.

var pageTimer = 1500;           //Waiting timer for each page. Making it too short will break things.
var inserttoTable = 1;          //Disable inserting to table. Set this to 0 if your browser crashes. You can still use the textbox to save them.

var pageNumber = '';
var PageUrl = "favorites.php?page=";
var counter = 0;
var showExport = 0;
var displayMode = document.getElementsByName("favform")[0].children[0].children[0].innerHTML.indexOf("Show Thumbnails"); //displayMode == -1 -> Thumbnail mode

//Common
function destroyBox() {
    $('.uselessbr').each(function() {$(this).remove();});
    $('#exportFav').remove();
    $('#exportStatus').remove();
}

function getPageNumber() {
    var newlength = $(".ptt")[0].rows[0].cells.length;
    var finalcell = $(".ptt")[0].rows[0].cells[newlength-2];
    pageNumber = finalcell.textContent;
}

function getPage() {
    if (window.location.search != "") {
        PageUrl = "favorites.php" + window.location.search + "&page=";
    }
}

$(document).ready(function(){
    $('#nb').append($('<img>').attr('src','https://exhentai.org/img/mr.gif').attr('alt', ' '));
    $('#nb').append(' ');
    $('#nb').append($('<a/>').attr('href','#').attr('id','exportFavorites').text('Load All Favorites'));
    $('#exportFavorites').click(exportFavorites);
});

function addRemoveButton() {
    $('#exportFav').after("<div>");
    $('#exportFav').next().append($('<input/>').attr('type','button').attr('value','Remove titles from list').attr('id','removeTitles').attr('style','margin-top:5px;min-height:18px;'));
    $('#removeTitles').click(removeTitles);
}

function removeTitles() {
    $('#exportFav')[0].textContent = $('#exportFav')[0].textContent.replace(/( - .*)/g,"");
}

function exportFavorites() {
    if (showExport === 0) {
        showExport = 1;
        $('#nb').append('<br class="uselessbr"/><br class="uselessbr"/>');
        $('#nb').append('<h2 class="uselessbr">Text List of Favorites');
        $('#nb').append('<textarea id="exportFav" name="Text1" cols="80" rows="7" ... />');
        $('#nb').append('<h3 class="uselessbr">Status');
        $('#nb').append('<textarea id="exportStatus" name="Text2" cols="80" rows="5" ... />');
        $('#nb').append('<br class="uselessbr"/>');
    } else {
        destroyBox();
        showExport = 0;
        return;
    }

    if (window.location.search.indexOf("page=") != -1) {
        $('#exportFav').append("GO TO THE FIRST PAGE AND TRY AGAIN" + '\n');
        $('#exportStatus').append("GO TO THE FIRST PAGE AND TRY AGAIN" + '\n');
        return;
    }

    if (displayMode == -1) {
        getThisPageThumbnail();
        getPage();
        getPageNumber();
        if (pageNumber > 1) {
            $('#exportStatus').append("Loading all pages will take " + (Math.ceil(pageTimer/100)*(pageNumber-1))/10 + " seconds." + '\n');
            if (pageNumber > 20) {
                $('#exportStatus').append("You have quite a lot of pages. If your browser crashes disable [inserttoTable] within the script." + '\n');
            }
            //$('#exportStatus').append("NOTICE - If your browser completely freezes, try using the newest Firefox/Chrome with tampermonkey/violentmonkey or help me fix it." + '\n');
            for (var i = 1; i < pageNumber; i++) {
                //console.log("Queued page: " + i);
                setTimeout(function () {
                    counter++;
                    //console.log("Current page: " + counter);
                    $('#exportStatus').append("Loading Page " + (counter+1) + " of " + pageNumber + "..." +  '\n');
                    if ((counter+1) == pageNumber) {
                        $('#exportStatus').append("Loading complete." + '\n' + "Copy above text, Ctrl+S to save the page or use an extension like Save Page WE." + '\n');
                        addRemoveButton();
                        setTimeout(function () {
                            $('#exportStatus').append("Confirmation: " + ($('#exportFav')[0].value.split("\n").length-1) + " favorites in above text area, " + ($(".id1").length) + " favorites in below table." + '\n');
                        }, 1000);
                    }
                    $('#exportStatus').scrollTop($('#exportStatus')[0].scrollHeight);
                    $.get(PageUrl + counter, function(sss) {
                        var trlen = $(sss).find(".id1").length;
                        var thistr;
                        for (var j=0;j<=trlen-1;j++) {
                            thistr = $(sss).find(".id1")[j];
                            if (inserttoTable) {
                                $(".itg")[0].append(thistr);
                            }
                            getTextThumbnail(thistr);
                        }
                    });

                }, 200 + i*pageTimer);
            }
        } else {
            $('#exportStatus').append("Loading complete." + '\n' + "Copy above text, Ctrl+S to save the page or use an extension like Save Page WE." + '\n');
            $('#exportStatus').append("Confirmation: " + ($('#exportFav')[0].value.split("\n").length-1) + " favorites in above text area, " + ($(".id1").length) + " favorites in below table." + '\n');
            addRemoveButton();
        }
    } else {
        getThisPage();
        getPage();
        getPageNumber();
        if (pageNumber > 1) {
            $('#exportStatus').append("Loading all pages will take " + (Math.ceil(pageTimer/100)*(pageNumber-1))/10 + " seconds." + '\n');
            if (pageNumber > 20) {
                $('#exportStatus').append("You have quite a lot of pages. If your browser crashes disable [inserttoTable] within the script." + '\n');
            }
            //$('#exportStatus').append("NOTICE - If your browser completely freezes, try using the newest Firefox/Chrome with tampermonkey/violentmonkey or help me fix it." + '\n');
            for (var i = 1; i < pageNumber; i++) {
                //console.log("Queued page: " + i);
                setTimeout(function () {
                    counter++;
                    //console.log("Current page: " + counter);
                    $('#exportStatus').append("Loading Page " + (counter+1) + " of " + pageNumber + "..." +  '\n');
                    if ((counter+1) == pageNumber) {
                        $('#exportStatus').append("Loading complete." + '\n' + "Copy above text, Ctrl+S to save the page or use an extension like Save Page WE." + '\n');
                        addRemoveButton();
                        setTimeout(function () {
                            $('#exportStatus').append("Confirmation: " + ($('#exportFav')[0].value.split("\n").length-1) + " favorites in above text area, " + ($("tr").length-3) + " favorites in below table." + '\n');
                        }, 1000);
                    }
                    $('#exportStatus').scrollTop($('#exportStatus')[0].scrollHeight);
                    $.get(PageUrl + counter, function(sss) {
                        var trlen = $(sss).find("tr").length;
                        var thistr;
                        for (var j=2;j<=trlen-2;j++) {
                            thistr = $(sss).find("tr")[j];
                            if (inserttoTable) {
                                $("tbody")[1].append(thistr);
                            }
                            getText(thistr);
                        }
                    });

                }, 200 + i*pageTimer);
            }
        } else {
            $('#exportStatus').append("Loading complete." + '\n' + "Copy above text, Ctrl+S to save the page or use an extension like Save Page WE." + '\n');
            $('#exportStatus').append("Confirmation: " + ($('#exportFav')[0].value.split("\n").length-1) + " favorites in above text area, " + ($("tr").length-3) + " favorites in below table." + '\n');
            addRemoveButton();
        }
    }
}

//List view mode only
function getText(tr) {
    var thetext = "";
    thetext = he.encode(tr.getElementsByClassName("it5")[0].children[0].href + " - " + tr.getElementsByClassName("it5")[0].children[0].text);
    $('#exportFav').append(thetext + '\n');
}

function getThisPage() {
    var trlen = $("tr").length;
    var thistr;
    for (var j=2;j<=trlen-2;j++) {
        thistr = $("tr")[j];
        getText(thistr);
    }
}

//Thumbnail view mode only
function getTextThumbnail(tr) {
    var thetext = "";
    thetext = he.encode(tr.getElementsByClassName("id2")[0].children[0].href + " - " + tr.getElementsByClassName("id2")[0].children[0].text);
    $('#exportFav').append(thetext + '\n');
}

function getThisPageThumbnail() {        //tr starts with 2, ends with tr.length-2
    var trlen = $(".id1").length;
    var thistr;
    for (var j=0;j<=trlen-1;j++) {
        thistr = $(".id1")[j];
        getTextThumbnail(thistr);
    }
}