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.

Versione datata 08/04/2018. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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?://exhentai.org/favorites.php.*/
// @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     1.3.4
// @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 = 2000;           //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;

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=";
    }
}

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() {        //tr starts with 2, ends with tr.length-2
    var trlen = $("tr").length;
    var thistr;
    for (var j=2;j<=trlen-2;j++) {
        thistr = $("tr")[j];
        getText(thistr);
    }
}

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;
    }

    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 (document.getElementsByName("favform")[0].children[0].children[0].innerHTML.indexOf("Show Thumbnails") == -1) {
        $('#exportFav').append("Sadpanda Save/Export All Favorites only works in list mode (Does not work on thumbnail mode)" + '\n');
        $('#exportStatus').append("Sadpanda Save/Export All Favorites only works in list mode (Does not work on thumbnail mode)" + '\n');
        return;
    }

    getThisPage();
    getPage();
    getPageNumber();
    if (pageNumber > 1) {
        $('#exportStatus').append("Loading all pages will take " + Math.ceil(pageTimer/1000)*(pageNumber-1) + " seconds." + '\n');
        if (pageNumber > 30) {
            $('#exportStatus').append("You got 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 paste above text or Ctrl+S to save the complete page." + '\n');
                    setTimeout(function () {
                        $('#exportStatus').append("Debug: " + ($('#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);
                    }
                });

            }, 1000 + i*pageTimer);
        }
    }

}

$(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);
});