Sadpanda Save/Export All Favorites

Load all favorites to the page and save it or just copy the textbox contents.

اعتبارا من 22-09-2016. شاهد أحدث إصدار.

// ==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.
// @include     https://exhentai.org/favorites.php*
// @include     http://g.e-hentai.org/favorites.php*
// @version     1.1.0
// @grant       none
// @require     http://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.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(gtr) {
	var thetext = "";
	if ($(gtr).find('a').length != 2){
		thetext = $(gtr).find('a')[0] + " - " + $(gtr).find('a')[0].text;
	} else {
		thetext = $(gtr).find('a')[1] + " - " + $(gtr).find('a')[1].text;
	}
	$('#exportFav').append(thetext + '\n');
}

function getThisPage() {
	var gtr0len = $.find(".gtr0").length;
	var gtr1len = $.find(".gtr1").length;
	var thisgtr0;
	if (gtr1len == 0) {
		thisgtr0 = $.find(".gtr0")[0];
		getText(thisgtr0);
	} else {
		for (var j=0;j<gtr1len;j++) {
			thisgtr0 = $.find(".gtr0")[j];
			getText(thisgtr0);
			var thisgtr1 = $.find(".gtr1")[j];
			getText(thisgtr1);
		}
		if (gtr0len - gtr1len != 0) {
			thisgtr0 = $.find(".gtr0")[gtr0len-1];
			getText(thisgtr0);
		}
	}
}

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;
	}
	
    getThisPage();
	getPage();
    getPageNumber();
	if (pageNumber > 1) {
		$('#exportStatus').append("Loading all pages will take " + 3*(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("Just wait for page " + pageNumber + " to load." + '\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) + "..." +  '\n');
				if ((counter+1) == pageNumber) {
					$('#exportStatus').append("Loading complete." + '\n' + "Copy paste above text or Ctrl+S to save the complete page." + '\n');
				}
				$('#exportStatus').scrollTop($('#exportStatus')[0].scrollHeight);
				$.get(PageUrl + counter, function(sss) {
					var gtr0len = $(sss).find(".gtr0").length;
					var gtr1len = $(sss).find(".gtr1").length;
					var thisgtr0;
					var thetext;
					if (gtr1len == 0) {
						thisgtr0 = $(sss).find(".gtr0")[0];
						if (inserttoTable) {
							$(".itg").find("tbody").append(thisgtr0);
						}
						getText(thisgtr0);
					} else {
						for (var j=0;j<gtr1len;j++) {
							thisgtr0 = $(sss).find(".gtr0")[j];
							if (inserttoTable) {
								$(".itg").find("tbody").append(thisgtr0);
							}
							getText(thisgtr0);
							var thisgtr1 = $(sss).find(".gtr1")[j];
							if (inserttoTable) {
								$(".itg").find("tbody").append(thisgtr1);
							}
							getText(thisgtr1);
						}
						if (gtr0len - gtr1len != 0) {
							thisgtr0 = $(sss).find(".gtr0")[gtr0len-1];
							if (inserttoTable) {
								$(".itg").find("tbody").append(thisgtr0);
							}
							getText(thisgtr0);
						}
					}
				});

			}, 2000 + 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);
});