Skip to content

Instantly share code, notes, and snippets.

@ZaneHannanAU
Created March 27, 2018 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZaneHannanAU/6529b62c2ff059542ad7844848512064 to your computer and use it in GitHub Desktop.
Save ZaneHannanAU/6529b62c2ff059542ad7844848512064 to your computer and use it in GitHub Desktop.
autoadd series novelupdates
// ==UserScript==
// @name NovelUpdates Series autoadd
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.novelupdates.com/series/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
console.log('Running userscript');
const tmp = document.body.appendChild(document.createElement('template'));
const selectors = {table: 'table#myTable',next: '.digg_pagination [rel=next]'};
tmp.innerHTML = '<div class="digg_pagination"><a href="./?pg=2" rel="next">2</a></div>';
const myTable = document.querySelector(selectors.table);
(function loop() {
const next = tmp.content.querySelector(selectors.next);
if (!next) {
document.querySelector('.digg_pagination').hidden = true;
return;
}
fetch(next.href).then(res => {
if (!res.ok) throw res;
console.log(res);
return res.text();
}).then(v => {
tmp.innerHTML = v;
loop();
const table = tmp.content.querySelector(selectors.table);
for (const row of table.tBodies[0].rows)
myTable.tBodies[0].appendChild(row.cloneNode(true));
}).catch(console.error);
})();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment