// ==UserScript==
// @name RSS
// @namespace tg.i-c-a.su
// @version 1.0
// @description try to take over the world!
// @author You
// @match https://tg.i-c-a.su/rss/*
// @icon https://tg.i-c-a.su/favicon.ico
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
function prettify() {
var r = document.querySelector('head,rss');
if (r) {
// override the builtin XML viewer's stylesheet, if it exists, or if it doesn't, add one
(document.querySelector('#xml-viewer-style') || GM_addStyle('')).innerHTML = `#webkit-xml-viewer-source-xml
{display:block!important}.header,.pretty-print,channel>lastBuildDate,item>guid{display:none!important}channel>*{
display:block;margin:0 16pt}channel>title{font-size:300%}item{background:#0001;border-radius:.5em;margin:16pt;
padding:6pt}item>*{display:block;margin:6pt;clear:left}item>title{font-size:200%;overflow:hidden;white-space:nowrap;
text-overflow:ellipsis;border-bottom:solid 1px darkgray;padding-bottom:2pt;margin-top:2pt}item>pubDate{border-top:
solid 1px darkgray;padding-top:5pt}item description img{display:inline-block;max-width:120px!important;margin:
0pt 8pt 8pt 0;float:left}item description br{content:'';display:block;margin-top:6pt}`;
let domParser = new DOMParser, xmlSerializer = new XMLSerializer;
document.querySelectorAll('item description').forEach(e => {
try {
// try to escape invalid <not-html stuff> so it won't error out when we try to append to the document
let r = /<(?!\/\w+|\w+( |\/?>))([^<>])*>?/g;
let html = e.textContent.replace(r, c => c.replaceAll('<', '<').replaceAll('>', '>'));
let d = domParser.parseFromString(html, 'text/html'), fragment = new DocumentFragment;
fragment.append(...d.querySelector('body').childNodes);
e.innerHTML = xmlSerializer.serializeToString(fragment);
} catch (e) {
console.error(e);
}
});
}
return r; // return truthy if we did the thing
}
if (!prettify()) {
// if the page was not ready yet, use a MutationObserver to detect when the head or rss node loads
(new MutationObserver((m, o) => {
if (prettify()) {
// once the function runs successfully, disconnect the MutationObserver so it only runs once
o.disconnect();
}
})).observe(document, {childList: true});
}
})();