Ashley_Blade / Lightnovel scrape

// ==UserScript==
// @name     Lightnovel scrape
// @description Scrapes ReadLightNovel.org for contents and saves to a file, press F9 to start scrapping.
// @include https://www.readlightnovel.org/*
// @require     https://raw.githubusercontent.com/eligrey/FileSaver.js/master/dist/FileSaver.js
// @version  1.1.0
// @license MIT
// @grant    none
// ==/UserScript==

console.log('Lightnovel scrape launching...');

const getChapterContent = () => {
  const content = document.querySelector('.chapter-content3');
  if (!content) return console.log('There is no content on the page!');

  const pTag = document.querySelectorAll('p:not([class])');
  const array = Array.from(pTag);

  let chapter = array.map(a => a.innerText);
  let chapterFull = chapter.join(`\n`);

  const chapterName = prompt('What do you want to save the chapter as?');
  if (!chapterName) return;

  const blob = new Blob([chapterFull], {
    type: "text/plain;charset=utf-8"
  });

  saveAs(blob, `${chapterName}.txt`);
}

const checkURL = () => {
  const url = document.URL;
  if (url.includes('chapter')) {
    getChapterContent();
  }
  else {
    console.log('[LightNovel Scrape] This is not a chapter, try going to a chapter to scrape!');
  }
}

const scrapeSingleChapter = e => {
	const keyCode = e.keyCode;
  if(keyCode === 120) checkURL();
}

document.addEventListener("keydown", scrapeSingleChapter);


console.log('Lightnovel scrape loaded, press F9 to scrape');