Last active
September 23, 2024 08:07
-
-
Save berteh/8c052685905f58b64ccc44f272273506 to your computer and use it in GitHub Desktop.
download tabs/chords from ultimate-guitar.com song as a text file, simply hit CTRL+ALT+D after page is loaded.
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 download Ultimate Guitar tabs-chords | |
// @description hit CTRL+ALT+D after whole page is loaded to download tabs/chords of current page as a text file. | |
// @version 1.1 | |
// @icon https://tabs.ultimate-guitar.com/static/public/img/product_icons/ug/favicon.ico | |
// @require http://code.jquery.com/jquery-latest.js | |
// @run-at document-end | |
// @downloadURL https://gist.github.com/berteh/8c052685905f58b64ccc44f272273506/raw/ultimate-guitar-download.user.js | |
// @match https://tabs.ultimate-guitar.com/* | |
// ==/UserScript== | |
unsafeWindow.console.clear (); | |
unsafeWindow.console.log("Grabbing ready"); | |
function grab() { | |
var title = document.title; | |
var url = window.location.href; | |
unsafeWindow.console.log("grabbing " + title); | |
var a = document.createElement('a'); | |
a.download = title+'.cpro'; //supported by chrome 14+, firefox 20+, edge 20+ | |
var data = document.querySelectorAll('pre>span'); | |
if(data.length>0){ | |
const datas = Array.from(data); //extract text from NodeList | |
var txts = datas.map(span => span.textContent); | |
a.href = 'data:text/plain;charset=utf-8,' + encodeURIComponent(title+'\n\n; adapted from '+url+'\n\n'+txts.join("")); | |
//unsafeWindow.console.log("file is at " + a.href); | |
a.click(); | |
} else { | |
unsafeWindow.console.log("got NO data, wait for page to load"); | |
} | |
} | |
// key allocations requires http://code.jquery.com/jquery-latest.js | |
$(function(){ | |
$(document).keyup(function (e) { | |
if (e.keyCode == 68 && e.altKey && e.ctrlKey) { //hit CTRL+ALT+D | |
e.preventDefault(); | |
grab(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment