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
15
ug.js
15
ug.js
|
@ -52,11 +52,6 @@ function getTabs() {
|
||||||
}).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)
|
||||||
|
@ -65,10 +60,12 @@ function addDownloadButton() {
|
||||||
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';
|
||||||
|
btn.style = 'color: #ffc600; text-decoration: underline';
|
||||||
|
btn.href = tabs;
|
||||||
header.querySelector('section').appendChild(btn);
|
header.querySelector('section').appendChild(btn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue