Move from file IDs to file paths (with retrocompatibility)
This commit is contained in:
parent
56cf62f1eb
commit
a2503d5def
7 changed files with 62 additions and 49 deletions
|
@ -1,15 +1,15 @@
|
|||
function copyEditLink(fileID) {
|
||||
navigator.clipboard.writeText(getEditLink(fileID));
|
||||
function copyEditLink(path) {
|
||||
navigator.clipboard.writeText(getEditLink(path));
|
||||
}
|
||||
function copyImageLink(fileID) {
|
||||
navigator.clipboard.writeText(``);
|
||||
function copyImageLink(path) {
|
||||
navigator.clipboard.writeText(`})`);
|
||||
}
|
||||
|
||||
function refreshPage() {
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
function addButton(document, fileID) {
|
||||
function addButton(document, path) {
|
||||
|
||||
// Add floating button
|
||||
const floatingButton = document.createElement('button');
|
||||
|
@ -22,8 +22,8 @@ function addButton(document, fileID) {
|
|||
popupMenu.id = 'popupMenu';
|
||||
popupMenu.innerHTML = `
|
||||
<button onclick="refreshPage()">Refresh</button>
|
||||
<button onclick="copyEditLink('${fileID}')">Copy Direct Edit Link</button>
|
||||
<button onclick="copyImageLink('${fileID}')">Copy Image Link</button>
|
||||
<button onclick="copyEditLink('${path}')">Copy Direct Edit Link</button>
|
||||
<button onclick="copyImageLink('${path}')">Copy Image Link</button>
|
||||
`;
|
||||
document.body.appendChild(popupMenu);
|
||||
|
||||
|
|
|
@ -27,9 +27,9 @@ async function getFile(path) {
|
|||
|
||||
}
|
||||
|
||||
async function getSVG(fileID) {
|
||||
async function getSVG(path) {
|
||||
|
||||
const resp = await getFile("/data/assets/" + fileID + '.svg');
|
||||
const resp = await getFile(path);
|
||||
if(resp == null) {
|
||||
return FALLBACK;
|
||||
}
|
||||
|
@ -37,10 +37,10 @@ async function getSVG(fileID) {
|
|||
|
||||
}
|
||||
|
||||
function getEditLink(fileID) {
|
||||
function getEditLink(path) {
|
||||
const data = encodeURIComponent(
|
||||
JSON.stringify({
|
||||
id: fileID
|
||||
path: path,
|
||||
})
|
||||
)
|
||||
return `siyuan://plugins/siyuan-jsdraw-pluginwhiteboard/?icon=iconDraw&title=Drawing&data=${data}`;
|
||||
|
|
|
@ -5,18 +5,22 @@
|
|||
<script src="button.js"></script>
|
||||
<script>
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const fileID = urlParams.get('id');
|
||||
let path = urlParams.get('path');
|
||||
if(path === null) {
|
||||
const fileID = urlParams.get('id'); // legacy support
|
||||
path = "/data/assets/" + fileID + ".svg";
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
const editLink = document.createElement('a');
|
||||
editLink.href = getEditLink(fileID);
|
||||
editLink.href = getEditLink(path);
|
||||
document.body.appendChild(editLink);
|
||||
|
||||
const htmlContainer = document.createElement('div');
|
||||
htmlContainer.innerHTML = await getSVG(fileID);
|
||||
htmlContainer.innerHTML = await getSVG(path);
|
||||
editLink.appendChild(htmlContainer);
|
||||
|
||||
addButton(document, fileID);
|
||||
addButton(document, path);
|
||||
});
|
||||
</script>
|
||||
<link rel="stylesheet" href="index.css">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue