Last active
March 7, 2021 01:33
-
-
Save EcutDavid/30afa27c10cc20eb4172614a2b9c0671 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html lang="en"> | |
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Demo</title> | |
<style> | |
body { | |
padding-top: 50px; | |
text-align: center; | |
font-size: 2.5em; | |
} | |
img { | |
max-width: 500px; | |
} | |
</style> | |
</head> | |
<body> | |
<p></p> | |
<script src="https://sdk.canva.com/designbutton/v2/api.js"></script> | |
<script> | |
const DESIGN_TYPES = [ | |
"BookCover", "Bookmark", "Card", "Certificate", "EmailHeader" | |
]; | |
const pTag = document.querySelector("p"); | |
Canva.DesignButton.initialize({ | |
// Please replace the apiKey with yours :) | |
apiKey: "18dxRFfjOIGvPQbq1TSGErFi", | |
}).then((api) => { | |
const roundCount = Math.floor(Math.random() * 10) + 4; | |
let counter = 0; | |
const timerId = setInterval(() => { | |
counter++; | |
const type = DESIGN_TYPES[counter % DESIGN_TYPES.length]; | |
pTag.innerText = "Maybe creating a " + type; | |
if (counter !== roundCount) { | |
return; | |
} | |
clearInterval(timerId); | |
api.createDesign({ | |
design: { type }, | |
onDesignPublish: ({ exportUrl }) => { document.body.innerHTML = `<img src="${exportUrl}"/>`; } | |
}); | |
}, 300); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment