copy to clipboard enhancement
If clipboard is a table it converts the json string to lua table format
This commit is contained in:
1 parent
d4908042be
commit
ee955c9b79
2 files changed
+33
-25
No files matched your search
+22
-6
@@ -9,12 +9,21 @@
|
||||
<div id="root"></div>
|
||||
<script type="module" src="./src/main.jsx"></script>
|
||||
</body>
|
||||
<script>
|
||||
<script>
|
||||
// dont judge me
|
||||
|
||||
function isTableJSON(jsonString) {
|
||||
try {
|
||||
const parsed = JSON.parse(jsonString);
|
||||
return parsed;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const copyToClipboard = (str) => {
|
||||
const el = document.createElement("textarea");
|
||||
el.value = str;
|
||||
document.body.appendChild(el);
|
||||
const el = document.createElement("textarea");
|
||||
el.value = str;
|
||||
document.body.appendChild(el);
|
||||
el.select();
|
||||
document.execCommand("copy");
|
||||
document.body.removeChild(el);
|
||||
@@ -23,9 +32,16 @@
|
||||
window.addEventListener("message", (event) => {
|
||||
if (event?.data?.type === "copytoclipboard") {
|
||||
var str = event.data.text;
|
||||
// str = JSON.parse(str);
|
||||
console.log("copying to clipboard", isTableJSON(str));
|
||||
if (isTableJSON(str)) {
|
||||
str = str.replace(/\[/g, '{');
|
||||
str = str.replace(/\]/g, '}');
|
||||
str = str.replace(/:/g, '=');
|
||||
str = str.replace(/"([^"]+)"=/g, '$1=');
|
||||
}
|
||||
copyToClipboard(str);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
Reference in new issue
Block a user