Created
January 7, 2018 23:59
-
-
Save matheusfaustino/a9b689171f578fe42547fa06ff2bb7f5 to your computer and use it in GitHub Desktop.
Bulk read action Gooreads by Name (set all the books with a certain name as read)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Bulk read action Gooreads by Name | |
// @namespace goodreads.bulk.read.name | |
// @author matheusfaustino | |
// @description set all the books with a certain name as read | |
// @include *goodreads.com/series/* | |
// @include *goodreads.com/search* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
async function readAll(name) { | |
for (let book of document.querySelectorAll('.bookTitle')) { | |
if (book.innerText.toLowerCase().indexOf(name) >= 0 || book.innerText.indexOf(name) >= 0) { | |
let form = book.parentNode.parentNode.querySelector('form.hiddenShelfForm'); | |
if (!form) | |
continue; | |
let wtr_id = book.parentNode.parentNode.querySelector('.wtrButtonContainer').getAttribute('id'); | |
await sleep(500); | |
$j.ajax({ | |
method: form.getAttribute('method'), | |
url: form.getAttribute('action'), | |
data: $j(form).serialize() + '&name=read' + '&wtr_button_id=' + wtr_id | |
}) | |
.done(r => { | |
console.log(r); | |
eval(r); | |
}); | |
} | |
} | |
} | |
function clickRead() { | |
let click = document.createElement('a'); | |
click.textContent = 'Mark books as read'; | |
click.setAttribute('href', "javascript: void(0);"); | |
click.style.cssText = 'padding: 5px; margin-bottom:5px; float: right; clear: both; background: #409D69; color: white; border-radius: 5px; font-size: 17px;'; | |
click.addEventListener('click', e => { | |
let name = prompt('Anime\'s name: '); | |
if (!name) | |
return; | |
readAll(name).then(() => alert('All list added.')); | |
}); | |
return click; | |
} | |
document.querySelector('.tableList').parentNode.insertBefore(clickRead(), document.querySelector('.tableList')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment