Skip to content

Instantly share code, notes, and snippets.

@davmillar
Created March 27, 2018 19:47
Show Gist options
  • Save davmillar/cf68f6002715532b44df071bcbb36bdb to your computer and use it in GitHub Desktop.
Save davmillar/cf68f6002715532b44df071bcbb36bdb to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Take Over(cast)
// @version 0.1
// @namespace https://davegoesthedistance.com
// @description Convert Apple Podcast links to Overcast links.
// @author David Millar
// @match *://*/*
// @run-at document-end
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
document.addEventListener("DOMContentLoaded", replaceLinks, false );
if( document.readyState === "complete" ) {
replaceLinks();
}
function checkLink(a) {
var linkCheck = a.href.toString().match(/itunes\.apple\..*\/.*\/podcast\/.*\/?id(\d+)/i);
if (linkCheck && linkCheck[1]) {
a.href = 'https://overcast.fm/itunes' + linkCheck[1];
if (a.textContent.match(/itunes|apple/ig)) {
a.textContent = a.textContent.replace(/itunes|apple/ig, 'Overcast');
}
}
}
function replaceLinks() {
Array.forEach(document.links, checkLink);
}
document.body.addEventListener('mousedown', function(e) {
if (e.target.tagName != "A") return;
checkLink(e.target);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment