Last active
March 15, 2023 11:57
-
-
Save Dan-Q/b6b7513b49678af94073361a1cd95320 to your computer and use it in GitHub Desktop.
Userscript to facilitate bypassing the (UK) region lock on radio.garden
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 radio.garden: bypass region restrictions (e.g. UK) | |
// @namespace dqne.me.radio.garden | |
// @match http://radio.garden/* | |
// @grant none | |
// @version 1.0 | |
// @author Dan Q <https://danq.me/> | |
// @description Adds a secondary player interface to radio.garden which still works even on region-blocked radio stations. Allows listening to non-UK stations from the UK. | |
// @run-at document-idle | |
// ==/UserScript== | |
const root = document.querySelector(':root'); | |
root.style.setProperty('--playbar-height', '150px'); | |
root.style.setProperty('--desktop-ui-width', '350px'); | |
let secondaryPlayer; | |
function addSecondaryPlayer(src){ | |
const primaryPlayer = document.querySelector('[class^="_leftSide_"]'); | |
if(!primaryPlayer) return; | |
let secondaryPlayer = document.getElementById('radio-garden-bypass-secondary-player'); | |
if(!secondaryPlayer){ | |
secondaryPlayer = document.createElement('audio'); | |
secondaryPlayer.id = 'radio-garden-bypass-secondary-player'; | |
secondaryPlayer.controls = true; | |
} | |
secondaryPlayer.src = src; | |
primaryPlayer.appendChild(secondaryPlayer); | |
secondaryPlayer.play(); | |
} | |
window.fetch = new Proxy(window.fetch, { | |
apply: (target, that, args)=>{ | |
const tmp = target.apply(that, args); | |
tmp.then(res=>{ | |
const matches = res.url.match(/\/api\/ara\/content\/channel\/(.*)/); | |
if(matches){ | |
const stationId = matches[1]; | |
addSecondaryPlayer(`http://radio.garden/api/ara/content/listen/${stationId}/channel.mp3`); | |
res.json(); // break the original so we don't tune in twice! | |
} | |
}); | |
return tmp; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment