userscripts/catalogues/goodreads_expand.user.js

83 lines
2.8 KiB
JavaScript
Raw Normal View History

2020-08-17 22:23:17 +02:00
// ==UserScript==
// @name Goodreads expand
// @description Show the whole description / author information / book details on goodreads.com.
// @description:de Zeige die ganze beschreibung / author·inneninformation / buchdetails auf goodreads.com an.
// @version 2021.07.20.1
2020-08-17 22:23:17 +02:00
// @author tastytea
// @copyright 2020, 2021, tastytea (https://tastytea.de/)
2020-08-17 22:23:17 +02:00
// @license GPL-3.0-only
// @namespace tastytea.de
// @homepageURL https://schlomp.space/tastytea/userscripts
// @supportURL https://schlomp.space/tastytea/userscripts/issues
2020-08-17 22:24:50 +02:00
// @downloadURL https://schlomp.space/tastytea/userscripts/raw/branch/main/catalogues/goodreads_expand.user.js
2020-08-17 22:23:17 +02:00
// @grant none
// @match https://www.goodreads.com/*
2020-08-17 22:23:17 +02:00
// @run-at document-end
// @inject-into content
// ==/UserScript==
(function()
{
// Book description.
const description = document.getElementById("description");
// Author info on author page.
let author = document.getElementsByClassName("aboutAuthorInfo")[0];
if (author === undefined)
2020-08-17 22:23:17 +02:00
{
// Author info on book page.
author = document.getElementsByClassName("bookAuthorProfile")[0];
2020-08-17 22:23:17 +02:00
}
for (const element of [description, author])
2020-08-17 22:23:17 +02:00
{
if (element == null) // null or undefined.
{
continue;
}
const spans = element.getElementsByTagName("span");
if (spans.length >= 2)
{
spans[1].setAttribute("style", "display: block;");
spans[0].setAttribute("style", "display: none;");
const links = element.getElementsByTagName("a");
links[links.length - 1].text = "(less)";
}
2020-08-17 22:23:17 +02:00
}
// Data below books.
const bookdata = document.getElementById("bookDataBox");
if (bookdata !== null)
{
bookdata.setAttribute("style", "display: block;");
document.getElementById("bookDataBoxShow").setAttribute("style", "display: none;");
}
2020-08-17 22:23:17 +02:00
})();
// On-hover book descriptions are getting loaded dynamically, so we have to look
// for them periodically.
function userscript_expand_hover_description()
{
const descriptions = document.getElementsByClassName("addBookTipDescription");
for (const element of descriptions)
{
if (element == null) // null or undefined.
{
continue;
}
const spans = element.getElementsByTagName("span");
if (spans.length >= 2)
{
spans[1].setAttribute("style", "display: block;");
spans[0].setAttribute("style", "display: none;");
const links = element.getElementsByTagName("a");
links[links.length - 1].text = "(less)";
}
}
}
setInterval(userscript_expand_hover_description, 1000);