mirror of
https://github.com/BlackLight/ultimate-guitar-mytabs.git
synced 2024-11-23 20:15: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)
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -65,10 +60,12 @@ function addDownloadButton() {
|
|||
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;
|
||||
const tabs = 'data:application/json,' + encodeURIComponent(JSON.stringify(getTabs()));
|
||||
const btn = document.createElement('a');
|
||||
btn.download = 'tabs.json';
|
||||
btn.innerHTML = 'Download tabs as JSON';
|
||||
btn.style = 'color: #ffc600; text-decoration: underline';
|
||||
btn.href = tabs;
|
||||
header.querySelector('section').appendChild(btn);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue