// ==UserScript==
// @version 1.6
// @include *.fanfiction.net/s/*
// @namespace ffnet
// @name Fanfiction.net story export script.
// @author Alssn
// @description Writes all chapters of the story on one page.
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
// @changes Rewrote some code to use jquery, changed design to fit the new ff.net scheme
// @downloadURL none
// ==/UserScript==
var chapters=[];
var style = $("");
$('body').append(style);
function addButtons(){
// Adding buttons
res = document.getElementById('f_size');
// creating links
var node = $('.lc').first();
var exportMenu = $('fE');
var exportContainer = $('');
var addHeadersButton = $('Headers');
var addIndexButton = $('Index');
var addTitleButton = $('Title');
var expAllButton = $('Story');
var expRestButton = $('Rest');
var expButton=$('Text');
exportMenu.append(exportContainer);
exportContainer.append(expAllButton,expRestButton,expButton,'| ',addHeadersButton,addTitleButton,addIndexButton);
node.append(exportMenu);
expAllButton.click(exportChapters);
expRestButton.click(exportRest);
expButton.click(exportCh);
addHeadersButton.click(addHeaders);
addTitleButton.click(addTitle);
addIndexButton.click(addIndex);
$('#ffne_button').click(function(){
var cont = $('#ffne_export');
if (cont.hasClass('ffne_hidden')){cont.removeClass('ffne_hidden');}else{cont.addClass('ffne_hidden')}
});
}
//Adding buttons to page;
addButtons();
//Adding table of contents
function addIndex(){
var chapters = $('div[name="ffnee_chapter"]');
var index = $('
Table of contents
');
var toC = $('
');
index.append(toC);
for (var i=0;i'+item.attr('title')+''));
}
$('#storytext').prepend(index);
}
//adding headers, as entered by author
function addHeaders(){
var chapters = document.getElementsByName('ffnee_chapter');
for (var i=0;i';
item.insertBefore(header,item.firstChild);
}
}
function addTitle(){
var titleText = $('b.xcontrast_txt','#profile_top').first().html();
var title = $(''+titleText+'
');
var authorText = $('a.xcontrast_txt[href^="/u/"]','#profile_top').first().html();
var author = $(''+authorText+'
');
var storytext = $('#storytext');
storytext.prepend(author,title);
}
function exportCh(){
document.body.innerHTML=''+document.getElementById('storytextp').innerHTML+'
';
//Sadly, it is not possible to automatically copy text to clipboard in firefox without changing browser settings;
}
function exportRest(e){
var chap_select = document.getElementById('chap_select');
console.log('exporting rest');
exportChapters(e,chap_select.value-1);
}
function exportChapters(e,start,end){
// Main actions
// Progress indicator
var expDiv = document.getElementById('exportAllButton');
var expText = expDiv.childNodes[0];
var hr=location.href;
var chapterNumIndex=hr.search(/\/\d{1,3}\//);
//Getting number of chapters
var storyLength=getLength();
if (storyLength == 1){
expText.nodeValue = 'Oneshot';
return;
}
if (start==undefined){
start=0;
}
if (end==undefined){
end=storyLength;
}
storyLength = end-start;
var totalStoryLength = storyLength;//reference
console.log('retrieving '+totalStoryLength+' chapters');
console.log('start is: '+start+', end is: '+end);
//launching retrieving of all chapters simultaneously
for (var i=start;i