fixing cors issue

This commit is contained in:
hkgnp 2022-02-15 16:30:01 +08:00
parent 48d80f1889
commit bca113b989
2 changed files with 28 additions and 28 deletions

View File

@ -5,7 +5,7 @@
"icon": "./icon.svg" "icon": "./icon.svg"
}, },
"name": "logseq-mermaid-plugin", "name": "logseq-mermaid-plugin",
"version": "1.0.6", "version": "1.0.7",
"description": "", "description": "",
"main": "dist/index.html", "main": "dist/index.html",
"targets": { "targets": {

View File

@ -19,32 +19,32 @@ export const renderMermaid = async (type, payload, colour, mermaidUUID) => {
); );
}; };
const handleEvent = async (e) => { // const handleEvent = async (e) => {
if (e.currentTarget.response !== 'invalid encoded code') { // if (e.currentTarget.response !== 'invalid encoded code') {
if (colour === undefined) { if (colour === undefined) {
renderBlock(`<img src="https://mermaid.ink/img/${jsonString}" />`); renderBlock(`<img src="https://mermaid.ink/img/${jsonString}" />`);
} else if (colour.startsWith('#')) { } else if (colour.startsWith('#')) {
renderBlock( renderBlock(
`<img src="https://mermaid.ink/img/${jsonString}?bgColor=${colour.substring( `<img src="https://mermaid.ink/img/${jsonString}?bgColor=${colour.substring(
1 1
)}" />` )}" />`
); );
} else if (!colour.startsWith('#')) { } else if (!colour.startsWith('#')) {
renderBlock( renderBlock(
`<img src="https://mermaid.ink/img/${jsonString}?bgColor=!${colour}" />` `<img src="https://mermaid.ink/img/${jsonString}?bgColor=!${colour}" />`
); );
} else { } else {
renderBlock(`<img src="https://mermaid.ink/img/${jsonString}" />`); renderBlock(`<img src="https://mermaid.ink/img/${jsonString}" />`);
} }
} else { // } else {
renderBlock( // renderBlock(
'<p>There is an error with your mermaid syntax. Please rectify and render again.</p>' // '<p>There is an error with your mermaid syntax. Please rectify and render again.</p>'
); // );
} // }
}; // };
let req = new XMLHttpRequest(); // let req = new XMLHttpRequest();
req.open('GET', `https://mermaid.ink/img/${jsonString}`, true); // req.open('GET', `https://mermaid.ink/img/${jsonString}`, true);
req.send(); // req.send();
req.onload = handleEvent; // req.onload = handleEvent;
}; };