Literotica Downloader

Single page HTML download for Literotica with improved readability

La data de 21-03-2021. Vezi ultima versiune.

// ==UserScript==
// @name        Literotica Downloader
// @description Single page HTML download for Literotica with improved readability
// @namespace   literotica_downloader
// @include     https://www.literotica.com/stories/memberpage.php*
// @require     https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @version     2.5
// @author      Improved by a random redditor and @nylonmachete, originally by Patrick Kolodziejczyk
// ==/UserScript==
$(document).ready(function () {
  
    var bodyStyle=' style="background-color:#333333; color: #EEEEEE; font-family: Helvetica,Arial,sans-serif; width: 50%; margin: 0 auto; line-height: 1.5em; font-size:2.2em; padding: 50px 0 50px 0;" ';
    var chapterStyle=' style="line-height: 1.4em;" ';
  // Creating style for a download icon
  	var iconDonwload = ' style=\'background-image: url("https://marcoceppi.github.io/bootstrap-glyphicons/img/glyphicons-halflings.png");     background-position: -120px -24px;cursor: pointer;cursor: hand;    background-repeat: no-repeat;    display: inline-block;    height: 14px;    line-height: 14px;    vertical-align: text-bottom;    width: 14px;}\'';
  // Function used to return content as a file for the user.
  function saveTextAsFile(textToWrite, fileNameToSaveAs)
  {
    var textFileAsBlob = new Blob([textToWrite], {
      type: 'text/javascript'
    });
    var downloadLink = document.createElement('a');
    downloadLink.download = fileNameToSaveAs;
    downloadLink.innerHTML = 'Download File';
  // Firefox requires the link to be added to the DOM
  // before it can be clicked.
  downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
  //downloadLink.onclick = destroyClickedElement;
  downloadLink.style.display = 'none';
  document.body.appendChild(downloadLink);
    downloadLink.click();
  }
  // Function parsing all pages to get the storie based
  function getContentOfStoie(baseURL) {
    console.log("Fetching "+baseURL);
    var remote;
    $.ajax({
      url: baseURL,
      type: 'GET',
      async: false,
	  crossDomain: true,
      success: function (data) {
        if ($(data).find('a.l_bJ.l_bL').size()>0) {
          console.log($(data).find('a.l_bJ.l_bL').size());
          remote = $(data).find('.panel.article.aa_eQ .aa_ht').html() + getContentOfStoie($(data).find('a.l_bJ.l_bL')[0].href);
        } else {
          remote = $(data).find('.panel.article.aa_eQ .aa_ht').html();
        }
      }
    });
    return remote;
  }
  function getABookForSerieDiv(myDiv) {
    var title = $.trim(myDiv.text().split(':') [0]);
    var author = $('.contactheader').text();
    alert("Starting building file for "+title +" of "+author+".\nPlease wait...");
    var book = '<html>\n<head>\n<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">\n';
    book += '<title>' + title + '</title>';
    book += '<meta content="' + author + '" name="author">';
    book += '</head>\n<body '+ bodyStyle +' >';
    function addChapter(element, index, array) {
      if ($(this).find('a').size() > 0) {
        var description = $($(this).find('td') [1]).text();
        book += '<h1 class=\'chapter\'' + chapterStyle + '>' + description + '</h1>';
        var link = $($(this).find('a') [0]);
        book += getContentOfStoie(link.attr('href'));
      }
    }
    myDiv.nextUntil('.ser-ttl,.root-story').each(addChapter);
    saveTextAsFile(book, title + '.html');
  }
 function getABookForStoryDiv(myDiv) {
   console.log(myDiv.html());
    var title = $.trim($($(myDiv)).text().split('(')[0]);
    var author = $('.contactheader').text();
    var book = '<html>\n<head>\n<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">\n';
    book += '<title>' + title + '</title>';
    book += '<meta content="' + author + '" name="author">';
    book += '</head>\n<body '+ bodyStyle + '>';
      if ($(myDiv).find('a').size() > 0) {
        var description = $($(myDiv).find('td') [1]).text();
        book += '<h1 class=\'chapter\'' + chapterStyle + '>' + description + '</h1>';
        var link = $($(myDiv).find('a') [0]);
        book += getContentOfStoie(link.attr('href'));
      }

    saveTextAsFile(book, title + '.html');
  }
  $('.ser-ttl td:nth-child(1)').prepend('<span '+iconDonwload+'></span>');
   $('.ser-ttl td:nth-child(1) span').click(function()  {
  getABookForSerieDiv($(this).parent().parent());
});
  var idIcon =Math.floor(Math.random() * 100);
  $('.root-story td:nth-child(1), .sl td:nth-child(1)').prepend('<span '+iconDonwload+' id="'+idIcon+'"></span>');
$('.root-story td:nth-child(1), .sl td:nth-child(1) span').click(function()  {
  getABookForStoryDiv($(this).parent());
});
});