');
$div.load('https://www.fanfiction.net/s/' + document.location.pathname.substr(3, 8).replace("/", "") + '/' + i + ' #storytext', function () {
// now $(this)[0].innerHTML contains #storytext
$("#storytextp").append($(this)[0].innerHTML);
});
}
document.getElementById('topSuprSecret').outerHTML = '';
}, 100); // end of timeout
});
//
// EBOOKS!!!!!!!!!!!!!!!!!
//
$('#content_wrapper_inner > span:nth-child(7)').append('
');
document.getElementById('getEbook').addEventListener('click', function () {
document.getElementById('storytextp').innerHTML = "
";
$.ajaxSetup({
async: false
});
getBookLegacy()
// getBookWithLinks()
function getBookLegacy() {
let data = {
ebookMethod: "legacy",
title: document.querySelector("#profile_top > b").innerHTML,
author: [document.querySelector("#profile_top > a").innerHTML],
description: document.querySelector("#profile_top > div").innerHTML,
publisher: "fanfiction.net",
contents: [],
bookID: document.location.pathname.substr(3, 8).replace("/", "")
};
setTimeout(async function () { //timeout to let it get us a progress bar ish thing
let downloaded = 0
for (let i = 1; i < document.getElementById('chap_select').options.length + 1; i++) {
// chapter is variable used by fanfiction, it counts what chapter you are at starting at 1.
// my own call to get chapter has +1 because it fetches a list starting at 0 instead.
await sleep(0.1)
console.log("Downloading " + document.location.pathname.substr(3, 8).replace("/", "") + " chapter " + i);
var $div = $('
');
$div.load('https://www.fanfiction.net/s/' + document.location.pathname.substr(3, 8).replace("/", "") + '/' + i + ' #storytext', function () {
// now $(this)[0].innerHTML contains #storytext
data.contents.push({
title: document.getElementById('chap_select').options[i - 1].innerHTML,
data: $(this)[0].innerHTML,
});
downloaded++
document.querySelector("#topSuprSecret").innerHTML = `
Downloaded ${downloaded}/${document.getElementById('chap_select').options.length}
`
});
}
// Send request to server for ebook creation
document.querySelector("#topSuprSecret").innerHTML = `
Scrape complete, creating ebook...
`
GM_xmlhttpRequest({
method: "POST",
url: config.ebookServer + "/epubify",
data: JSON.stringify(data),
headers: {
"Content-Type": "application/json"
},
onload: function (response) {
let downloadURL = config.ebookServer + "/" + document.location.pathname.substr(3, 8).replace("/", "") + ".epub"
console.log(response.responseText + " book is done");
if (response.responseText == "success") {
// location.href = downloadURL;
} else {
console.log(response)
alert("Could not contact ebook server. Please alert author.");
}
document.getElementById('topSuprSecret').outerHTML = '';
document.getElementById('storytextp').innerHTML = `
`;
}
});
}, 100); // end of timeout
}
function getBookWithLinks() {
let data = {
ebookMethod: "links",
title: document.querySelector("#profile_top > b").innerHTML,
author: [document.querySelector("#profile_top > a").innerHTML],
description: document.querySelector("#profile_top > div").innerHTML,
publisher: "fanfiction.net",
contents: [],
bookID: document.location.pathname.substr(3, 8).replace("/", "")
};
setTimeout(function () {
if (document.getElementById('chap_select')) {
for (let i = 1; i < document.getElementById('chap_select').options.length + 1; i++) {
data.contents[data.contents.length] = {
url: 'https://www.fanfiction.net/s/' + document.location.pathname.substr(3, 8).replace("/", "") + '/' + i,
dataSelector: "#storytextp",
title: document.getElementById('chap_select').options[i - 1].innerHTML,
};
}
} else {
data.contents[data.contents.length] = {
url: 'https://www.fanfiction.net/s/' + document.location.pathname.substr(3, 8).replace("/", "") + '/1',
dataSelector: "#storytextp",
title: "Oneshot",
};
}
document.querySelector("#topSuprSecret").innerHTML = "
Converting to epub...
";
console.log(data);
GM_xmlhttpRequest({
method: "POST",
url: config.ebookServer + "/epubify",
data: JSON.stringify(data),
headers: {
"Content-Type": "application/json"
},
onload: function (response) {
console.log(response.responseText + " book is done");
if (response.responseText == "success") {
// location.href = config.ebookServer + "/" + document.location.pathname.substr(3, 8).replace("/", "") + ".epub";
} else {
alert("Could not contact ebook server. Please alert author.");
}
document.getElementById('topSuprSecret').outerHTML = '';
}
});
}, 100); // end of timeout
}
});
}
var sleep = async s => new Promise(r => setTimeout(r, s * 1000))