Skip to content

Instantly share code, notes, and snippets.

@mlt
Last active July 29, 2024 20:25
Show Gist options
  • Save mlt/25105711c5cf5d7e405fb48e67af4600 to your computer and use it in GitHub Desktop.
Save mlt/25105711c5cf5d7e405fb48e67af4600 to your computer and use it in GitHub Desktop.
TamperMonkey script to add (Garmin watch) PlayRun button to LibriVox
// ==UserScript==
// @name Add PlayRun button to LibriVox
// @namespace http://tampermonkey.net/
// @version 2024-07-29
// @description Speed up adding LibriVox books into PlayRun
// @author mlt
// @match https://librivox.org/*/
// @match https://www.playrun.app/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=librivox.org
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
(function() {
'use strict';
var token = GM_getValue('pr_token');
if (token === undefined) {
var t = localStorage.getItem("playrun");
var s = JSON.parse(t);
token = s.state.token;
GM_setValue('pr_token', token);
}
var dl = document.querySelector("dl.listen-download");
if (dl) {
var a = document.createElement('a');
a.href = '#';
a.className = 'book-download-btn';
a.appendChild( document.createTextNode('PlayRun') );
dl.appendChild( document.createElement('dt') ).appendChild( document.createTextNode('PlayRun subscribe') );
dl.appendChild( document.createElement('dd') ).appendChild(a);
var rss;
for (const elem of document.querySelectorAll("dl.listen-download>dd>a").entries()) {
if (elem[1].textContent === 'RSS') {
rss = elem[1].href;
break;
}
};
a.addEventListener('click', function(e) {
var data = { url: rss, isPrivate: false };
GM.xmlHttpRequest({
method: 'POST',
url: 'https://www.playrun.app/api/podcast',
data: JSON.stringify(data),
headers: {
"Content-Type": 'application/json',
Authorization: 'Bearer ' + token,
Host: 'www.playrun.app',
Origin: 'https://www.playrun.app',
Referer: 'https://www.playrun.app/podcast'
},
onload: function(data) {
var r = JSON.parse(data.response);
window.open('https://www.playrun.app/podcast/' + r.uuid);
}});
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment