2024-03-22 21:45:54 +05:30
|
|
|
(function savePlaygrounds() {
|
|
|
|
function setCodeToPlayground() {
|
2024-05-28 15:21:41 +05:30
|
|
|
Array.from(document.querySelectorAll(".playground")).forEach(function (
|
|
|
|
pre_block,
|
|
|
|
index
|
|
|
|
) {
|
|
|
|
let code_block = pre_block.querySelector("code");
|
|
|
|
let editor = window.ace.edit(code_block);
|
|
|
|
code = JSON.parse(
|
|
|
|
localStorage.getItem(`${window.location.href}₹${index}`)
|
|
|
|
);
|
|
|
|
if (code) {
|
|
|
|
editor.setValue(code);
|
2024-03-22 21:45:54 +05:30
|
|
|
editor.clearSelection();
|
2024-05-28 15:21:41 +05:30
|
|
|
}
|
|
|
|
});
|
2024-03-22 21:45:54 +05:30
|
|
|
}
|
|
|
|
function getCodeFromPlayground() {
|
|
|
|
Array.from(document.querySelectorAll(".playground")).forEach(function (
|
2024-05-28 15:21:41 +05:30
|
|
|
pre_block,
|
|
|
|
index
|
2024-03-22 21:45:54 +05:30
|
|
|
) {
|
|
|
|
let code_block = pre_block.querySelector("code");
|
|
|
|
let editor = window.ace.edit(code_block);
|
2024-05-28 15:21:41 +05:30
|
|
|
editor.session.on("change", function () {
|
|
|
|
let code = editor.getValue();
|
|
|
|
localStorage.setItem(
|
|
|
|
`${window.location.href}₹${index}`,
|
|
|
|
JSON.stringify(code)
|
|
|
|
);
|
|
|
|
});
|
2024-03-22 21:45:54 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
setCodeToPlayground();
|
2024-05-28 15:21:41 +05:30
|
|
|
getCodeFromPlayground();
|
2024-03-22 21:45:54 +05:30
|
|
|
})();
|
|
|
|
|
|
|
|
function resetPlaygroundsClicked() {
|
2024-05-28 15:21:41 +05:30
|
|
|
Array.from(document.querySelectorAll(".playground")).forEach(function (
|
|
|
|
pre_block,
|
|
|
|
index
|
|
|
|
) {
|
|
|
|
let code_block = pre_block.querySelector("code");
|
|
|
|
let editor = window.ace.edit(code_block);
|
|
|
|
editor.setValue(editor.originalCode);
|
|
|
|
editor.clearSelection();
|
|
|
|
});
|
|
|
|
|
2024-03-22 21:45:54 +05:30
|
|
|
let keys = [];
|
|
|
|
for (var i = 0, len = localStorage.length; i < len; i++) {
|
2024-05-28 15:21:41 +05:30
|
|
|
if (localStorage.key(i).includes("₹")) {
|
2024-03-22 21:45:54 +05:30
|
|
|
keys.push(localStorage.key(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (let j = 0; j < keys.length; j++) {
|
|
|
|
localStorage.removeItem(keys[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
window.resetPlaygroundsClicked = resetPlaygroundsClicked;
|