Skip to content

Instantly share code, notes, and snippets.

@vaaas
Last active February 19, 2018 12:27
Show Gist options
  • Save vaaas/59b76d8eaa8db88b081f781db591d46f to your computer and use it in GitHub Desktop.
Save vaaas/59b76d8eaa8db88b081f781db591d46f to your computer and use it in GitHub Desktop.
mine ao3 works listings, output RSS items
(function() {
"use strict"
function map (a, fn) {
var r = []
for (let i = 0; i < a.length; i++) r.push(fn(a[i]))
return r }
const works = document.querySelectorAll("ol.work.index.group > li.own.work")
const data = map(works, el => {
const obj = {}
let t
t = el.querySelector("h4 > a:first-child")
obj.url = t.href
obj.title = t.textContent
t = el.querySelector("p.datetime")
obj.date = t.textContent
t = el.querySelectorAll("h5.fandoms.heading > a.tag")
obj.fandoms = map(t, el => { return el.textContent })
t = el.querySelector("ul.required-tags span.rating > span.text")
obj.rating = t.textContent
t = el.querySelector("ul.required-tags span.category > span.text")
obj.category = t.textContent
t = el.querySelectorAll("ul.tags > li.warnings a.tag")
obj.warnings = map(t, el => { return el.textContent })
t = el.querySelectorAll("ul.tags > li.relationships a.tag")
obj.relationships = map(t, el => { return el.textContent })
t = el.querySelectorAll("ul.tags > li.characters a.tag")
obj.characters = map(t, el => { return el.textContent })
t = el.querySelectorAll("ul.tags > li.freeforms a.tag")
obj.freeforms = map(t, el => { return el.textContent })
t = el.querySelector("blockquote.summary")
obj.summary = t.textContent
t = el.querySelector("dl.stats > dd.words")
obj.words = t.textContent
return obj })
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
function rfc822(string) {
const d = new Date(string)
return `${days[d.getDay()]}, ${d.getDate()} ${months[d.getMonth()]} ${d.getFullYear()} 00:00:00 GMT` }
data.forEach(item => {
console.log(`<item>
<title>${item.title}</title>
<link>${item.url}</link>
<guid>${item.url}</guid>
<pubDate>${rfc822(item.date)}</pubDate>
<description><![CDATA[
<table>
<tr><th>Date</th> <td>${item.date}</td></tr>
<tr><th>Fandoms</th> <td>${item.fandoms.join(", ")}</td></tr>
<tr><th>Rating</th> <td>${item.rating}</td></tr>
<tr><th>Category</th> <td>${item.category}</td></tr>
<tr><th>Warnings</th> <td>${item.warnings.join(", ")}</td></tr>
<tr><th>Characters</th> <td>${item.characters.join(", ")}</td></tr>
<tr><th>Additional tags</th> <td>${item.freeforms.join(", ")}</td></tr>
<tr><th>Words</th> <td>${item.words}</td></tr>
</table>
<p>${item.summary}</p>
]]></description>
</item>`)})
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment