mirror of
https://github.com/BlackLight/ultimate-guitar-mytabs.git
synced 2024-11-24 04:25:11 +01:00
Preventing "Not allowed to navigate top frame to data URL" on Chromium-based browsers
Chromium no longer allows `data` URLs to be passed to `window.open`. The best alternative is to simply create an `a` element with a filename and the `data` URL and let the browser download it on click.
This commit is contained in:
parent
1a1873bf94
commit
35d50a7b98
1 changed files with 36 additions and 39 deletions
75
ug.js
75
ug.js
|
@ -21,55 +21,52 @@
|
||||||
|
|
||||||
|
|
||||||
function getTabs() {
|
function getTabs() {
|
||||||
let artist = null;
|
let artist = null;
|
||||||
return [
|
return [
|
||||||
...document.querySelector('article[isdesktop=true] div').childNodes
|
...document.querySelector('article[isdesktop=true] div').childNodes
|
||||||
].slice(1).map(item => {
|
].slice(1).map(item => {
|
||||||
const childNodes = [...item.childNodes];
|
const childNodes = [...item.childNodes];
|
||||||
const parsedItem = {};
|
const parsedItem = {};
|
||||||
|
|
||||||
if (childNodes.length > 0) {
|
if (childNodes.length > 0) {
|
||||||
const cellContent = childNodes[0].innerText.trim();
|
const cellContent = childNodes[0].innerText.trim();
|
||||||
if (cellContent.length)
|
if (cellContent.length)
|
||||||
artist = cellContent;
|
artist = cellContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (childNodes.length > 1) {
|
if (childNodes.length > 1) {
|
||||||
const cellContent = childNodes[1].innerText.trim();
|
const cellContent = childNodes[1].innerText.trim();
|
||||||
if (cellContent.length)
|
if (cellContent.length)
|
||||||
parsedItem.title = cellContent;
|
parsedItem.title = cellContent;
|
||||||
|
|
||||||
const link = childNodes[1].querySelector('a').getAttribute('href');
|
const link = childNodes[1].querySelector('a').getAttribute('href');
|
||||||
if (link.length)
|
if (link.length)
|
||||||
parsedItem.link = link;
|
parsedItem.link = link;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!artist && parsedItem.title)
|
if (!artist && parsedItem.title)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
parsedItem.artist = artist;
|
parsedItem.artist = artist;
|
||||||
return parsedItem;
|
return parsedItem;
|
||||||
}).filter(item => item)
|
}).filter(item => item)
|
||||||
}
|
|
||||||
|
|
||||||
function downloadTabs() {
|
|
||||||
const tabs = getTabs();
|
|
||||||
window.open('data:application/json,' + encodeURIComponent(JSON.stringify(tabs)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addDownloadButton() {
|
function addDownloadButton() {
|
||||||
const header = document.querySelector('main section header');
|
const header = document.querySelector('main section header');
|
||||||
if (!header)
|
if (!header)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (header.querySelector('button.__download-btn'))
|
if (header.querySelector('button.__download-btn'))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const btn = document.createElement('button');
|
const tabs = 'data:application/json,' + encodeURIComponent(JSON.stringify(getTabs()));
|
||||||
btn.classList.add('__download-btn');
|
const btn = document.createElement('a');
|
||||||
btn.innerText = 'Download as JSON';
|
btn.download = 'tabs.json';
|
||||||
btn.onclick = downloadTabs;
|
btn.innerHTML = 'Download tabs as JSON';
|
||||||
header.querySelector('section').appendChild(btn);
|
btn.style = 'color: #ffc600; text-decoration: underline';
|
||||||
|
btn.href = tabs;
|
||||||
|
header.querySelector('section').appendChild(btn);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onload = addDownloadButton;
|
window.onload = addDownloadButton;
|
||||||
|
|
Loading…
Reference in a new issue