Last active
January 18, 2024 07:17
-
-
Save hyrious/427a165279836aba6361f8a380b559b5 to your computer and use it in GitHub Desktop.
Turn your github rss into a readable page.
This file contains 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 Read on GitHub RSS | |
// @namespace gh-rss.hyrious.me | |
// @match https://github.com/*.atom | |
// @grant none | |
// @version 1.0 | |
// @author hyrious | |
// @description Because github new dashboard is terrible. | |
// ==/UserScript== | |
(async () => { | |
Object.assign(document.documentElement.dataset, { | |
colorMode: 'auto', | |
lightTheme: 'light', | |
darkTheme: 'dark', | |
}) | |
const user = location.pathname.slice(1).split('.')[0] | |
const index = await fetch('/').then(r => r.text()) | |
index.replace(/ href="(.+?\.css)"/g, (t, css) => { | |
const el = document.createElement('link') | |
el.rel = 'stylesheet' | |
el.href = css | |
document.head.append(el) | |
}) | |
document.head.appendChild(document.createElement('style')).textContent = 'body { padding: 50px 30px }' | |
const raw = document.querySelector('pre').textContent | |
const root = new DOMParser().parseFromString(raw, 'application/xml') | |
let html = '' | |
for (const entry of root.querySelectorAll('entry')) { | |
html += entry.querySelector('content').textContent | |
} | |
document.body.innerHTML = html | |
const fix = () => { | |
document.querySelectorAll('.Link--primary.text-bold.no-underline').forEach(a => { | |
if (a.textContent[0] === '/') { | |
const parts = a.textContent.split('/') // ['', 'owner', 'repo'] | |
a.textContent = parts.slice(2).join('/') | |
} | |
}) | |
document.querySelectorAll('.p-3.border-top').forEach(div => div.remove()) | |
} | |
fix() | |
const url = new URL(location.href) | |
const more = document.body.appendChild(document.createElement('a')) | |
more.textContent = 'Load More' | |
more.href = 'javascript:void 0' | |
more.onclick = (e) => { | |
e.preventDefault() | |
const page = url.searchParams.get('page') || '1' | |
const nextPage = +page + 1 | |
url.searchParams.set('page', nextPage + '') | |
fetch(url).then(r => r.text()).then(raw => { | |
const root = new DOMParser().parseFromString(raw, 'application/xml') | |
let html = '' | |
for (const entry of root.querySelectorAll('entry')) { | |
html += entry.querySelector('content').textContent | |
} | |
const fragment = document.createElement('div') | |
fragment.innerHTML = html | |
for (const el of fragment.children) | |
document.body.appendChild(el) | |
fix() | |
document.body.appendChild(more) | |
}) | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment