Last active
January 18, 2020 17:06
-
-
Save Greegko/e816837cb6d8a396d607c2e20ccfde7c to your computer and use it in GitHub Desktop.
Frovo play button converter to link
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 Frovo mp3 link extractor | |
// @description It convers the play button to link, to be able to copy directly playable link of the mp3 | |
// @include https://forvo.com/* | |
// @version 1.0 | |
// @run_at: "document-end" | |
// ==/UserScript== | |
const PlayRegEx = /Play\(\d+,'([a-zA-Z0-9=]+)'/; | |
const PlayPhraseRegEx = /PlayPhrase\(\d+,'([a-zA-Z0-9=]+)'/; | |
function getMP3UrlFromNode(node, regex, prefix) { | |
const match = regex.exec(node.onclick); | |
if (match === null) return null; | |
const urlBase64 = match[1]; | |
return prefix + atob(urlBase64); | |
} | |
function createLinkElementFromNode(node, url) { | |
const a = document.createElement('a'); | |
a.href = window.location.origin + url; | |
a.onclick = node.onclick; | |
a.innerHTML = node.innerHTML; | |
a.classList = "play icon-size-xl"; | |
return a; | |
} | |
(function () { | |
'use strict'; | |
document.querySelectorAll('span.play').forEach(node => { | |
const url = getMP3UrlFromNode(node, PlayRegEx, '/mp3/') || getMP3UrlFromNode(node, PlayPhraseRegEx, '/phrases/mp3/'); | |
if (url === null) return; | |
const aElement = createLinkElementFromNode(node, url); | |
node.parentElement.replaceChild(aElement, node); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment