Skip to content

Instantly share code, notes, and snippets.

@andre-st
Last active July 18, 2022 10:48
Show Gist options
  • Save andre-st/212159db35c8c294d843c8cfb330440f to your computer and use it in GitHub Desktop.
Save andre-st/212159db35c8c294d843c8cfb330440f to your computer and use it in GitHub Desktop.
freie-radios.net: Adds download-buttons for the audio-files directly on the frontpage + removes no-audio articles from the frontpage + History of already downloaded audio + larger "next" link #injectjs
//////////////////////////////////////////////////////////////////////////////
//
// FREIE-RADIOS.NET
//
// 1. Adds download-buttons for the audio-files of each article directly on the frontpage
// 2. Removes 'internal' no-audio articles from the frontpage
// 3. History of already downloaded audio
//
mixin( ["https://www.freie-radios.net/"], () =>
{
chrome.storage.local.get([ 'frnDownloadHistory' ], stored =>
{
stored.frnDownloadHistory = stored.frnDownloadHistory
? stored.frnDownloadHistory.slice( -500 ) // History max. 500 items
: [];
const cards = document.querySelectorAll( '.card' );
for( var i = 0; i < cards.length; i++ )
{
const card = cards[i]; // For closures
const pageLink = card.querySelector( 'a' );
const heading = card.querySelector( '.card-title' );
const isInternal = heading.classList.contains( 'btitel_unknown' ) ||
heading.classList.contains( 'btitel_restricted' );
if( isInternal )
{
card.remove();
continue;
}
if( !pageLink ) continue;
pageLink.classList.remove( 'stretched-link' ); // Would overlay our button
if( stored.frnDownloadHistory.includes( pageLink.href ))
card.classList.add( 'downloaded' );
const btn = document.createElement( 'BUTTON' );
btn.innerText = 'Download';
btn.onclick = ev =>
{
getUrl( pageLink.href, text =>
{
const audioUrl = (text.match( /rel="download" href="([^"]*)/ ) || ['', ''])[1];
if( !audioUrl ) return;
saveUrl( audioUrl, () =>
{
stored.frnDownloadHistory.push( pageLink.href );
chrome.storage.local.set({ 'frnDownloadHistory': stored.frnDownloadHistory });
card.classList.add( 'downloaded' );
});
});
};
card.querySelector( '.card-footer .right' ).appendChild( btn );
}
});
}, { runAsContentScript: true });
// 1. Larger "next" link on the frontpage
// 2. make articles that have not yet been downloaded stand out more
//
mixin( ["https://www.freie-radios.net/"], `
.next a
{
background-color: #008aff;
color: #fff;
text-decoration: underline;
padding: 1em 1.5em;
font-size: 1.5em;
font-weight: bold;
}
.card.downloaded
{
opacity: 0.5;
}
.card.downloaded:hover
{
opacity: 1;
}
`);
@andre-st
Copy link
Author

andre-st commented Oct 6, 2021

Can be used with the Javascript injection extension https://github.com/andre-st/chrome-injectjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment