From 6257c101374c31411e4aeb76454cd134fb8f3d18 Mon Sep 17 00:00:00 2001 From: Phantop Date: Fri, 15 Nov 2019 15:16:42 -0500 Subject: [PATCH] Qute: AO3 DL and Latest Chapter userscripts --- .../share/qutebrowser/greasemonkey/ao3dl.js | 87 +++++++++++++++++++ .../share/qutebrowser/greasemonkey/ao3lz.js | 24 +++++ 2 files changed, 111 insertions(+) create mode 100644 .local/share/qutebrowser/greasemonkey/ao3dl.js create mode 100644 .local/share/qutebrowser/greasemonkey/ao3lz.js diff --git a/.local/share/qutebrowser/greasemonkey/ao3dl.js b/.local/share/qutebrowser/greasemonkey/ao3dl.js new file mode 100644 index 0000000..3565869 --- /dev/null +++ b/.local/share/qutebrowser/greasemonkey/ao3dl.js @@ -0,0 +1,87 @@ +// ==UserScript== +// @name ao3 download buttons +// @description Adds download buttons to each work blurb on AO3's works index pages. +// @namespace ao3 +// @include http*://archiveofourown.org/*works* +// @include http*://archiveofourown.org/series/* +// @include http*://archiveofourown.org/users/*/bookmarks* +// @include http*://archiveofourown.org/users/*/readings* +// @grant none +// @version 2.0 +// ==/UserScript== + +(function () { + const blurbs = Array.from(document.querySelectorAll('li.blurb')); + + if (!blurbs.length) { + return; + } + + const style = document.createElement('style'); + + style.innerHTML = ` + .blurb .download.actions { + position: absolute; + right: 7em; + top: 0.5em; + white-space: nowrap; + } + + .blurb .download .expandable { + position: absolute; + right: calc(100% + 0.5em); + top: -0.5em; + } + + .blurb .download .expandable li { + display: inline-block; + margin: 0; + } + `; + + document.head.appendChild(style); + + blurbs.forEach(blurb => { + + const titleLink = blurb.querySelector('.header.module .heading a'); + const title = titleLink.textContent.trim(); + const workId = titleLink.href + .match(/\/works\/(\d+)\b/)[1]; + const formats = ['azw3', 'epub', 'mobi', 'pdf', 'html']; + const tuples = formats + .map(ext => [ + ext.toUpperCase(), + `/downloads/${workId}/${encodeURIComponent(title)}.${ext}?updated_at=${Date.now()}` + ]); + + blurb.innerHTML += ` +
+ + +
+ `; + + blurb.querySelector('.download.actions > a').addEventListener('click', ev => { + const button = ev.currentTarget; + + button.classList.toggle('collapsed'); + button.classList.toggle('expanded'); + button.parentNode + .querySelector('.expandable') + .classList.toggle('hidden'); + + ev.preventDefault(); + }); + }); +})(); diff --git a/.local/share/qutebrowser/greasemonkey/ao3lz.js b/.local/share/qutebrowser/greasemonkey/ao3lz.js new file mode 100644 index 0000000..bb3e026 --- /dev/null +++ b/.local/share/qutebrowser/greasemonkey/ao3lz.js @@ -0,0 +1,24 @@ +// ==UserScript== +// @name AO3 Lazier +// @namespace ao3lazier +// @description Adds a latest chapter button to the top navigation. +// @include http*://archiveofourown.org/* +// ==/UserScript== + +var match = location.pathname.match(/^(\/works\/\d+\/chapters\/)\d+/); + +if (match) { + var chapEls = document.getElementById('selected_id').children; + var lastChapEl = chapEls[chapEls.length-1]; + if (!lastChapEl.selected) { + var lastChap = lastChapEl.value; + var button = document.createElement('a'); + button.href = match[1] + lastChap; + button.appendChild(document.createTextNode('Latest Chapter ' + String.fromCharCode(0x2192))); + var buttonParent = document.createElement('li'); + buttonParent.className = 'chapter'; + buttonParent.appendChild(button); + var chapsParent = document.getElementById('chapter_index').parentElement; + chapsParent.parentElement.insertBefore(buttonParent, chapsParent); + } +}