You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on a bookmarklet to make copying code over to P5 Live easier. The tricky part is that P5 Live loads everything into one file, with a special syntax for loading libraries. I’m wondering if there’s a way, using just vanilla JS, to grab all the code as a string from index.html, sketch.js, and any other files on the client side, assuming the user is already logged in.
The text was updated successfully, but these errors were encountered:
@TiborUdvari to acheive to get p5 live code to you bookmarklet you can use document keyword.
Here is some Code snippet you can use
`javascript:(function() {
/**
* Extracts all inline and external scripts from the page.
* Inline scripts are captured as code, while external libraries are noted with their URLs.
*/
function extractScripts() {
let scripts = document.querySelectorAll("script");
let extracted = "";
scripts.forEach(script => {
if (script.src) {
// If the script has a 'src' attribute, note its URL as an external library.
extracted += `// External Library: ${script.src}\n`;
} else {
// If it's an inline script, capture its content.
extracted += `\n// Inline Script Content:\n${script.textContent}\n`;
}
});
return extracted;
}
/**
* Extracts the entire HTML content of the page.
* This includes the full document structure, styles, and any inline scripts.
*/
function extractHtml() {
return document.documentElement.outerHTML;
}
/**
* Copies the given text to the clipboard and notifies the user.
* @param {string} text - The text content to be copied.
*/
function copyToClipboard(text) {
navigator.clipboard.writeText(text).then(() => {
alert("Code copied to clipboard! You can now paste it into P5 Live.");
}).catch(err => console.error("Error copying text: ", err));
}
// Combine extracted HTML and script content into a single string.
let fullCode = "/* Extracted HTML */\n" + extractHtml() + "\n\n/* Extracted Scripts */\n" + extractScripts();
// Copy the combined code to the clipboard.
copyToClipboard(fullCode);
Increasing Access
Unsure
Feature enhancement details
I'm working on a bookmarklet to make copying code over to P5 Live easier. The tricky part is that P5 Live loads everything into one file, with a special syntax for loading libraries. I’m wondering if there’s a way, using just vanilla JS, to grab all the code as a string from index.html, sketch.js, and any other files on the client side, assuming the user is already logged in.
The text was updated successfully, but these errors were encountered: