mirror of
https://github.com/BlackLight/ultimate-guitar-mytabs.git
synced 2024-11-27 21:55:11 +01:00
First commit
This commit is contained in:
parent
5b488f7fdd
commit
003b4e8218
2 changed files with 95 additions and 1 deletions
20
README.md
20
README.md
|
@ -1,2 +1,20 @@
|
||||||
# ultimate-guitar-mytabs
|
# ultimate-guitar-mytabs
|
||||||
Browser script to scrape and download your saved UltimateGuitar tabs to CSV/JSON
|
|
||||||
|
This browser script allows you to scrape and download your saved UltimateGuitar tabs to JSON format.
|
||||||
|
|
||||||
|
There are two ways to use this script:
|
||||||
|
|
||||||
|
1. Install it as a Greasemonkey script (or whatever extension you use for custom UserScript).
|
||||||
|
Every time you browse to your UltimateGuitar page, the Download button will appear next to
|
||||||
|
the header.
|
||||||
|
|
||||||
|
2. Manually paste the code in the browser developer console - the button will be added on the
|
||||||
|
fly. You can also manually call `getTabs` from the developer console to access, filter
|
||||||
|
and manipulate the list of objects.
|
||||||
|
|
||||||
|
![Screenshot](https://i.ibb.co/WPmwQbT/837c447a43af.png)
|
||||||
|
|
||||||
|
Note that the script will download all the tabs on the current page. If you want to download all
|
||||||
|
of your tabs, then select _All_ from the top filter. The current order of the tabs on the page is
|
||||||
|
also preserved in the downloaded JSON.
|
||||||
|
|
||||||
|
|
76
ug.js
Normal file
76
ug.js
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
// ==UserScript==
|
||||||
|
// @name UltimateGuitar Library Downloader
|
||||||
|
// @description It adds a "Download as JSON" button to the mytabs page on UltimateGuitar.
|
||||||
|
// @author Fabio "Blacklight" Manganiello
|
||||||
|
// @version 1.0
|
||||||
|
// @grant none
|
||||||
|
// @include https://www.ultimate-guitar.com/user/mytabs
|
||||||
|
// ==/UserScript==
|
||||||
|
|
||||||
|
/**
|
||||||
|
* There are two ways to use this script:
|
||||||
|
*
|
||||||
|
* 1. Install it as a Greasemonkey script (or whatever extension you use for custom UserScript).
|
||||||
|
* Every time you browse to your UltimateGuitar page, the Download button will appear next to
|
||||||
|
* the header.
|
||||||
|
*
|
||||||
|
* 2. Manually paste the code in the browser developer console - the button will be added on the
|
||||||
|
* fly. You can also manually call `getTabs` from the developer console to access, filter
|
||||||
|
* and manipulate the list of objects.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
function getTabs() {
|
||||||
|
let artist = null;
|
||||||
|
return [
|
||||||
|
...document.querySelector('article[isdesktop=true] div').childNodes
|
||||||
|
].slice(1).map(item => {
|
||||||
|
const childNodes = [...item.childNodes];
|
||||||
|
const parsedItem = {};
|
||||||
|
|
||||||
|
if (childNodes.length > 0) {
|
||||||
|
const cellContent = childNodes[0].innerText.trim();
|
||||||
|
if (cellContent.length)
|
||||||
|
artist = cellContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (childNodes.length > 1) {
|
||||||
|
const cellContent = childNodes[1].innerText.trim();
|
||||||
|
if (cellContent.length)
|
||||||
|
parsedItem.title = cellContent;
|
||||||
|
|
||||||
|
const link = childNodes[1].querySelector('a').getAttribute('href');
|
||||||
|
if (link.length)
|
||||||
|
parsedItem.link = link;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!artist && parsedItem.title)
|
||||||
|
return;
|
||||||
|
|
||||||
|
parsedItem.artist = artist;
|
||||||
|
return parsedItem;
|
||||||
|
}).filter(item => item)
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadTabs() {
|
||||||
|
const tabs = getTabs();
|
||||||
|
window.open('data:application/json,' + encodeURIComponent(JSON.stringify(tabs)));
|
||||||
|
}
|
||||||
|
|
||||||
|
function addDownloadButton() {
|
||||||
|
const header = document.querySelector('main section header');
|
||||||
|
if (!header)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (header.querySelector('button.__download-btn'))
|
||||||
|
return;
|
||||||
|
|
||||||
|
const btn = document.createElement('button');
|
||||||
|
btn.classList.add('__download-btn');
|
||||||
|
btn.innerText = 'Download as JSON';
|
||||||
|
btn.onclick = downloadTabs;
|
||||||
|
header.querySelector('section').appendChild(btn);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.onload = addDownloadButton;
|
||||||
|
|
Loading…
Reference in a new issue