Created
March 27, 2018 19:47
-
-
Save davmillar/cf68f6002715532b44df071bcbb36bdb to your computer and use it in GitHub Desktop.
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 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