Skip to content

Instantly share code, notes, and snippets.

@berteh
Last active March 24, 2024 00:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save berteh/8c052685905f58b64ccc44f272273506 to your computer and use it in GitHub Desktop.
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.
// ==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