JavaScript:
let appNames = [];
zIndex = 1;
function forHTML(element, callback) {
callback(element);
var enfants = element.childNodes;
for (var i = 0; i < enfants.length; i++) {
if(enfants[i].tagName == "DIV" || enfants[i].tagName == "div") {
forHTML(enfants[i], (element) => {
callback(element);
});
}
}
}
function copytext(texte) {
const zoneDeTexte = document.createElement("textarea");
zoneDeTexte.value = texte;
document.body.appendChild(zoneDeTexte);
zoneDeTexte.select();
document.execCommand("copy");
document.body.removeChild(zoneDeTexte);
}
// Push part
////////////////////////////////////////////////////////////////////////////////////
let div1 = document.createElement("div");
div1.style.zIndex = "100000";
div1.className = "div1forpush";
document.body.appendChild(div1);
let text1 = document.createElement("p");
text1.style = "margin-top: 0px; margin-bottom: 10px;";
let button1 = document.createElement("button");
button1.className = "Fd";
let button2 = document.createElement("button");
button2.className = "Fd";
div1.appendChild(text1);
div1.appendChild(button1);
div1.appendChild(button2);
let occuped = false;
let Fa = [];
function Fb() {
setTimeout(() => {
occuped = false;
if (Fa.length !== 0) {
let index = 0
while (Fa[index] == undefined && index <= Fa.length) {
index++
}
if (Fa.length < index) {
Fa = [];
}
if (Fa.length !== 0) {
push(Fa[index][0], Fa[index][1], Fa[index][2], Fa[index][3], Fa[index][4])
delete Fa[index];
}
}
}, 800)
}
let clicked = false;
let answer = {};
function push(message, option1, option2, id, callback) {
if (occuped == false) {
occuped = true;
text1.innerHTML = message;
button1.innerHTML = option1;
button2.innerHTML = option2;
clicked = false;
div1.style.left = "15px";
if (option1 == false) {
button1.style.display = "none";
} else {
button1.style.display = "block";
}
button1.onclick = function () {
if (clicked == false) {
clicked = true;
div1.style.left = "-515px";
Fb();
answer[id] = option1;
callback();
}
}
if (option2 == false) {
button2.style.display = "none";
} else {
button2.style.display = "block";
}
button2.onclick = function () {
if (clicked == false) {
clicked = true;
div1.style.left = "-515px";
Fb();
answer[id] = option2;
callback();
}
}
} else {
Fa.push([message, option1, option2, id, callback]);
}
}
////////////////////////////////////////////////////////////////////////////////////
// End push part
class App {
name;
callback = () => {};
html = {
divbox: document.createElement("div"),
};
style;
constructor(name, callback, style) {
this.name = name;
this.callback = callback;
if (style !== undefined) this.style = style;
let nameExist = false;
appNames.forEach(element => {
if (name == element) {
nameExist = true;
}
});
if (!nameExist) appNames.push(this.name);
if (nameExist) {
let newName = this.name + " (copy)";
let index = 1;
while (appNames.includes(newName)) {
newName = this.name + " (copy " + index + ")";
index++;
}
appNames.push(newName);
this.name = newName;
}
if (this.name.length < 4) {
this.html.divbox.innerText = this.name;
} else {
this.html.divbox.innerText = "ERR";
}
this.html.divbox.style = this.style;
this.html.divbox.className = "app";
this.html.divbox.onclick = () => {
this.execute();
};
toolbar.appendChild(this.html.divbox);
}
execute() {
this.callback();
}
}
windowsDivBox = [];
function newWindow(width, height, callback) {
let tab = document.createElement("div");
tab.style = "box-sizing: border-box; box-shadow: white 0 0 0 1px; position: absolute; width: 0px; height: 0px; min-height: fit-content;";
if (height == "fit-content") tab.style.height = "fit-content";
if (width == "fit-content") tab.style.width = "fit-content";
document.body.appendChild(tab);
windowsDivBox.push(tab);
let tabBar = document.createElement("div");
tabBar.style = "height: 35px; background-color: black; width: 100%;";
tab.appendChild(tabBar);
let tabBody = document.createElement("div");
tabBody.style = "overflow-y: auto; height: " + (height - 35) + "px; background-color: rgba(20, 20, 20); width: 100%; padding: 16px; box-sizing: border-box;";
tab.appendChild(tabBody);
let tabClose = document.createElement("div");
tabClose.style = "user-select: none; font-family: 'Source Code Pro', monospace; cursor: pointer; color: white; height: 35px; background-color: black; width: 50px; float: right; align-items: center; display: flex; justify-content: center;";
tabClose.innerText = "x";
tabClose.onclick = function () {
document.body.removeChild(tab);
}
tabClose.onmouseover = function () {
this.style.backgroundColor = "red";
}
tabClose.onmouseout = function () {
this.style.backgroundColor = "black";
}
tabBar.appendChild(tabClose);
let isDragging = false;
let offsetX = 0;
let offsetY = 0;
tabBar.addEventListener("mousedown", function(event) {
zIndex++;
tab.style.zIndex = zIndex;
isDragging = true;
offsetX = event.clientX - tab.offsetLeft;
offsetY = event.clientY - tab.offsetTop;
});
document.addEventListener("mousemove", function(event) {
if (isDragging) {
event.preventDefault();
let newPosX = event.clientX - offsetX;
let newPosY = event.clientY - offsetY;
let maxX = (window.innerWidth - tab.offsetWidth) + (width - 50);
let maxY = (window.innerHeight - tab.offsetHeight) + (height - 35);
if (newPosX < -(width-50)) newPosX = 0;
if (newPosX > maxX) newPosX = maxX;
if (newPosY < toolbar.clientHeight) newPosY = toolbar.clientHeight;
if (newPosY > maxY) newPosY = maxY;
tab.style.left = newPosX + "px";
tab.style.top = newPosY + "px";
}
});
document.addEventListener("mouseup", function(event) {
isDragging = false;
});
let duration = 500;
let startTime = null;
let startWidth = 0;
let startHeight = 0;
function animate(timestamp) {
if (!startTime) {
startTime = timestamp;
startWidth = 0;
startHeight = 0;
}
let progress = timestamp - startTime;
if (progress > duration) {
progress = duration;
}
let ratio = progress / duration;
let newWidth = startWidth + (width - startWidth) * ratio;
let newHeight = startHeight + (height - startHeight) * ratio;
tab.style.width = newWidth + "px";
tab.style.height = newHeight + "px";
if (progress < duration) {
window.requestAnimationFrame(animate);
}
}
window.requestAnimationFrame(animate);
callback(tab, tabBar, tabBody, tabClose);
forHTML(tab, (element) => {
document.addEventListener("mousedown", (event) => {
if (event.target == element) focusedWindow = tab;
})
})
}
let focusedWindow;
let focusedWindowBackup = focusedWindow;
document.addEventListener("mousedown", () => {
setTimeout(() => {
if (focusedWindowBackup !== focusedWindow) {
zIndex++;
focusedWindow.style.zIndex = zIndex;
focusedWindowBackup = focusedWindow;
}
}, 100)
})
let fullscreenW = document.body.clientWidth;
let fullscreenH = document.body.clientHeight - 54;
let toolbar = document.getElementById("toolbar");
let terminal = new App("CMD", function () {
newWindow(700, 500, function (tab, tabBar, tabBody, tabClose) {
let color = "rgb(255 255 255)";
let ul1 = document.createElement("ul");
ul1.style = "margin: 0px; list-style: none;";
tabBody.appendChild(ul1);
let li1;
let p1;
let input1;
function newLine() {
li1 = document.createElement("li");
li1.style = "margin-top: 10px; display: flex; align-items: baseline; background-color: rgb(0 0 0); color: " + color + "; width: 100%; height: 30px;";
ul1.appendChild(li1);
p1 = document.createElement("p");
p1.style = "padding-left: 8px; font-size: 14px; user-select: none; font-family: 'Source Code Pro', monospace; background-color: rgb(0, 0, 0); color: " + color + "; margin: 0px;";
p1.innerHTML = "Command prompt > ";
li1.appendChild(p1);
input1 = document.createElement("input");
input1.style = "margin-left: 10px; font-size: 14px; user-select: none; font-family: 'Source Code Pro', monospace; background-color: rgb(0, 0, 0); color: " + color + "; width: 75%; height: 27px; border: none; outline: none;";
li1.appendChild(input1);
input1.focus();
}
newLine();
let console = {
push(message, bgcolor, iswhite) {
let li1 = document.createElement("li");
li1.className = "li1";
li1.style = "background-color: rgb(0, 0, 0); color: " + color + ";";
ul1.appendChild(li1);
let p1 = document.createElement("p");
p1.className = "p1";
if (!iswhite) p1.style = "background-color: " + bgcolor + "; color: " + color + "";
if (iswhite) p1.style = "background-color: " + bgcolor + "; color: rgb(255 255 255)";
p1.innerHTML = message;
li1.appendChild(p1);
tabBody.scrollTop = tabBody.scrollHeight;
},
error(message) {
this.push(message, "rgb(60, 9, 9)", true);
},
log(message) {
this.push(message, "rgb(50, 50, 50)", false);
},
info(message) {
this.push(message, "rgb(0, 43, 81)", true);
},
warn(message) {
this.push(message, "rgb(86, 64, 0)", true)
},
};
function handleKeyDown(event) {
if (document.activeElement === input1) {
if (event.key == "Enter") {
input1.disabled = true;
input1.style.cursor = "text";
if (input1.value.slice(0, 3) == "JS>") {
try {
eval(input1.value.slice(3, input1.value.length));
} catch (error) {
console.error(error);
}
} else if (input1.value.slice(0, 4) == "CMD.") {
if (input1.value.slice(4, 10) == "color[" && input1.value.slice(-1, input1.value.length) == "]") {
let result = input1.value.slice(10, -1);
color = "rgb(" + result + ")";
li1.style.Color = color;
p1.style.color = color;
input1.style.color = color;
} else if (input1.value == "CMD.clear") {
ul1.innerText = "";
} else if (input1.value == "CMD.shutdown") {
windowsDivBox.forEach(element => {
element.remove();
});
windowsDivBox = [];
} else if (input1.value.slice(4, 15) == "background[" && input1.value.slice(-1, input1.value.length) == "]") {
let result = input1.value.slice(15, -1);
document.getElementById("background").src = result;
} else if (input1.value.slice(4, 12) == "execute[" && input1.value.slice(-1, input1.value.length) == "]") {
let result = input1.value.slice(12, -1);
if (result == "CMD") {
terminal.execute();
} else if (result == "TXT") {
notepad.execute();
} else if (result == "CAL") {
calculator.execute();
} else {
console.error("Error: App doesn't exist");
};
} else if (input1.value.slice(4,8) == "copy") {
if (input1.value.slice(8, 12) == "-wwh") {
copytext(window.innerWidth + "x" + window.innerHeight);
console.info("'" + window.innerWidth + "x" + window.innerHeight + "' copied !");
}
} else {
console.error("Error: unexpected command");
}
} else if (input1.value.slice(0, 2) == "::") {
console.log(input1.value.slice(2, input1.value.length));
} else {
console.error("Error: unexpected command");
}
newLine();
tabBody.scrollTop = tabBody.scrollHeight;
}
}
}
document.addEventListener("keydown", handleKeyDown);
});
}, "background-color: black; color: white;");
let notes = {};
let notepad = new App ("TXT", function () {
newWindow(700, 400, function (tab, tabBar, tabBody, tabClose) {
tabBody.innerHTML = "";
tabBody.style.overflow = "hidden";
let menuUl = document.createElement("ul");
menuUl.style = "width: 100%; height: 80%; padding: 0px; margin-bottom: 0px; overflow-y: auto;";
tabBody.appendChild(menuUl);
let menuDiv = document.createElement("ul");
menuDiv.style = "width: 100%; height: 15%; padding: 0px; margin: 0px;";
tabBody.appendChild(menuDiv);
for (element in notes) {
let noteLi = document.createElement("li");
noteLi.style = "width: 100%; height: fit-content; list-style: none; display: flex; align-items: baseline;";
menuUl.appendChild(noteLi);
let p2 = document.createElement("p");
p2.className = "p21";
p2.innerHTML = element;
noteLi.appendChild(p2);
let p3 = document.createElement("p");
p3.className = "p22";
p3.innerHTML = "Edit";
p3.onclick = function () {
tabBody.innerHTML = "";
let textarea = document.createElement("textarea");
textarea.style = "width: 100%; height: 99%; resize: none; outline: none; color: white; background-color: black; border: none; padding: 15px; box-sizing: border-box;";
textarea.value = notes[p2.innerHTML];
tabBody.appendChild(textarea);
let backup = tabClose.onclick;
tabClose.onclick = function () {
notes[p2.innerHTML] = textarea.value;
backup();
};
};
noteLi.appendChild(p3);
let p4 = document.createElement("p");
p4.className = "p22";
p4.style = "width: 8%; margin: 0px;";
p4.innerHTML = "Delete";
let deleted = false;
p4.onclick = function () {
if (!deleted) push("Are you sure to want to delete the file ?",
"yes",
"no",
"1",
() => {
if (answer["1"] == "yes") {
noteLi.remove();
delete notes[p2.innerHTML];
} else if (answer["1"] == "no") {
deleted = false;
}
})
deleted = true;
};
noteLi.appendChild(p4);
}
let p12 = document.createElement("p");
p12.style = "height: 20px; text-align: center; justify-content: center; display: flex; width: 20px; margin-top: 5px; margin-inline: 0px; border-radius: 20px;";
p12.className = "p22";
p12.innerHTML = "+";
p12.onclick = function () {
let limit;
let noteLi = document.createElement("li");
noteLi.style = "width: 100%; height: fit-content; list-style: none; display: flex; align-items: baseline;";
menuUl.appendChild(noteLi);
let p2 = document.createElement("input");
p2.style = "border: none; outline: none;";
p2.className = "p21";
p12.remove();
menuUl.appendChild(p12);
noteLi.appendChild(p2);
p2.focus();
limit = true;
function handleKeyDown(event) {
if (document.activeElement === p2 && event.key == "Enter") {
let backup = p2.value;
p2.remove();
p3.remove();
p4.remove();
p2 = document.createElement("p");
p2.style = "border: none; outline: none;";
p2.className = "p21";
p2.innerHTML = backup;
if (notes[backup] == undefined) {
noteLi.appendChild(p2);
noteLi.appendChild(p3);
noteLi.appendChild(p4);
notes[backup] = "";
}
limit = false;
}
}
let p3 = document.createElement("p");
p3.className = "p22";
p3.innerHTML = "Edit";
p3.onclick = function () {
if (limit == false) {
tabBody.innerHTML = "";
let textarea = document.createElement("textarea");
textarea.style = "width: 100%; height: 99%; resize: none; outline: none; color: white; background-color: black; border: none; padding: 15px; box-sizing: border-box;";
textarea.value = notes[p2.innerHTML];
tabBody.appendChild(textarea);
let backup = tabClose.onclick;
tabClose.onclick = function () {
notes[p2.innerHTML] = textarea.value;
backup();
};
};
};
noteLi.appendChild(p3);
let p4 = document.createElement("p");
p4.className = "p22";
p4.style = "width: 8%; margin: 0px;";
p4.innerHTML = "Delete";
let deleted = false;
p4.onclick = function () {
if (limit == false) {
if (!deleted) push("Are you sure to want to delete the file ?",
"yes",
"no",
"1",
() => {
if (answer["1"] == "yes") {
noteLi.remove();
delete notes[element];
} else if (answer["1"] == "no") {
deleted = false;
}
})
deleted = true;
p12.remove();
menuUl.appendChild(p12);
}
};
noteLi.appendChild(p4);
document.addEventListener("keydown", handleKeyDown);
menuUl.scrollTop = menuUl.scrollHeight;
};
menuUl.appendChild(p12);
let button1 = document.createElement("button");
button1.style = "margin-left: 10px; float: left; box-shadow: none;";
button1.className = "Fd";
button1.innerHTML = "Download";
menuDiv.appendChild(button1);
button1.onclick = function () {
let zip = new JSZip();
for (let note in notes) {
let content = notes[note];
zip.file(note + ".txt", content);
}
zip.generateAsync({ type: "blob" }).then(function (blob) {
let url = URL.createObjectURL(blob);
let a = document.createElement("a");
a.href = url;
a.download = "notes.zip";
a.click();
URL.revokeObjectURL(url);
});
};
});
}, "background-color: rgb(50 50 50); color: white;");
let calculator = new App("CAL", () => {
newWindow(300, 350, (tab, tabBar, tabBody, tabClose) => {
let isworking = true;
let displayDiv = document.createElement("div");
displayDiv.style = "box-sizing: border-box; overflow-x: hidden; width: 100%; height: 12%; background-color: #676767; box-shadow: white 0 0 0 1px; color: white; font-family: 'Source Code Pro', monospace; font-size: 26px; text-align: end; padding-right: 5px;";
displayDiv.innerText = "0";
tabBody.appendChild(displayDiv);
let div2 = document.createElement("div");
div2.style = "width: 100%; display: flex; height: 80%; margin-top: 20px; color: white;";
tabBody.appendChild(div2);
let numberDiv = document.createElement("div");
numberDiv.style = "width: 70%; height: 100%; background-color: #676767; box-shadow: white 0 0 0 1px; color: white;";
div2.appendChild(numberDiv);
let operatorDiv = document.createElement("div");
operatorDiv.style = "text-align: center; width: 23%; margin-left: 18px; height: 100%; background-color: #676767; box-shadow: white 0 0 0 1px; color: white;";
div2.appendChild(operatorDiv);
let decimal = false;
let keysA = {
"0": ()=>{
if (displayDiv.innerText !== "0") displayDiv.innerText += "0";
displayDiv.scrollLeft = displayDiv.scrollWidth;
},
",": ()=>{
if (decimal !== true) displayDiv.innerText += ".";
decimal = true;
displayDiv.scrollLeft = displayDiv.scrollWidth;
},
"Enter": ()=>{
try {
displayDiv.innerText = eval((displayDiv.innerText).replaceAll("÷", "/").replaceAll("×", "*"));
} catch (error) {
push(error, false, "ok", "1", () => {
if (answer["1"] == "ok") {
displayDiv.innerText = "ERR";
document.addEventListener("mousedown", function () {
tab.remove();
return;
})
}
});
}
},
"+": ()=>{
if (displayDiv.innerText.slice(-1, displayDiv.innerText.length) !== "+" && displayDiv.innerText.slice(-1, displayDiv.innerText.length) !== "-" && displayDiv.innerText.slice(-1, displayDiv.innerText.length) !== "×" && displayDiv.innerText.slice(-1, displayDiv.innerText.length) !== "÷") displayDiv.innerText += "+";
decimal = false;
},
"-": ()=>{
if (displayDiv.innerText.slice(-1, displayDiv.innerText.length) !== "+" && displayDiv.innerText.slice(-1, displayDiv.innerText.length) !== "-" && displayDiv.innerText.slice(-1, displayDiv.innerText.length) !== "×" && displayDiv.innerText.slice(-1, displayDiv.innerText.length) !== "÷") displayDiv.innerText += "-";
decimal = false;
},
"*": ()=>{
if (displayDiv.innerText.slice(-1, displayDiv.innerText.length) !== "+" && displayDiv.innerText.slice(-1, displayDiv.innerText.length) !== "-" && displayDiv.innerText.slice(-2, displayDiv.innerText.length) !== "××" && displayDiv.innerText.slice(-1, displayDiv.innerText.length) !== "÷") displayDiv.innerText += "×";
decimal = false;
},
":": ()=>{
if (displayDiv.innerText.slice(-1, displayDiv.innerText.length) !== "+" && displayDiv.innerText.slice(-1, displayDiv.innerText.length) !== "-" && displayDiv.innerText.slice(-1, displayDiv.innerText.length) !== "×" && displayDiv.innerText.slice(-2, displayDiv.innerText.length) !== "÷÷") displayDiv.innerText += "÷";
decimal = false;
},
};
for (let i = 1; i < 10; i++) {
keysA["" + i] = () => {
if (displayDiv.innerText == "0" || displayDiv.innerText == "-0") displayDiv.innerText = "";
displayDiv.innerText += "" + i;
displayDiv.scrollLeft = displayDiv.scrollWidth;
};
}
for (let o = 3; o > 0; o--) {
let div3 = document.createElement("div");
div3.style.display = "flex";
numberDiv.appendChild(div3);
for (let i = -2; i < 1; i++) {
let p1 = document.createElement("div");
p1.className = "p13";
p1.innerHTML = i+o*3;
p1.onclick = function () {
keysA[p1.innerHTML]();
}
div3.appendChild(p1);
}
}
let div3 = document.createElement("div");
div3.style.display = "flex";
numberDiv.appendChild(div3);
let p1 = document.createElement("div");
p1.className = "p13";
p1.innerHTML = 0;
p1.onclick = function () {
keysA["0"]();
}
div3.appendChild(p1);
let p2 = document.createElement("div");
p2.className = "p13";
p2.innerHTML = ",";
p2.onclick = function () {
keysA[","]();
}
div3.appendChild(p2);
let p3 = document.createElement("div");
p3.className = "p13";
p3.style = "background-color: rgb(255 96 0); color: black;";
p3.onmouseover = () => {p3.style.backgroundColor = "white"};
p3.onmouseout = () => {p3.style.backgroundColor = "rgb(255 96 0)"};
p3.innerHTML = "=";
p3.onclick = function () {
keysA["Enter"]();
}
div3.appendChild(p3);
let list = [["+", "+"], ["-", "-"], ["*", "×"], [":", "÷"]];
list.forEach(element => {
let p4 = document.createElement("div");
p4.className = "p13";
p4.style = "display: inline-flex; font-size: 30px; margin-inline: 0px; background-color: rgb(255 96 0); color: black;";
p4.onmouseover = () => {p4.style.backgroundColor = "white"};
p4.onmouseout = () => {p4.style.backgroundColor = "rgb(255 96 0)"};
p4.innerHTML = element[1];
p4.onclick = function () {
keysA[element[0]]();
}
operatorDiv.appendChild(p4);
});
function handleKeyDown(event) {
if (keysA[event.key] !== undefined && focusedWindow == tab) keysA[event.key]();
}
document.addEventListener("keydown", handleKeyDown);
});
}, "background-color: rgb(255 96 0); color: white;");
let game1 = new App ("CHK", () => {
newWindow(500, 535, (tab, tabBar, tabBody, tabClose) => {
tabBody.style.overflow = "hidden";
tabBody.style.backgroundColor = "rgb(0, 162, 232)";
let turn = "blue";
let turnToplay = "blue";
let screen = document.createElement("div");
screen.style = "width: 100%; height: 100%;";
tabBody.appendChild(screen);
let caseList = [];
let caseColor = "black";
for (let columns = 0; columns < 8; columns++) {
let line = document.createElement("div");
line.style = "display:flex";
screen.appendChild(line);
if (caseColor == "black") {
caseColor = "white";
} else if (caseColor == "white") {
caseColor = "black";
}
for (let lines = 0; lines < 8; lines++) {
let cases = document.createElement("div");
cases.className = "checkCases"
if (caseColor == "black") {
caseColor = "white";
} else if (caseColor == "white") {
caseColor = "black";
}
cases.style = "background-color: " + caseColor + ";";
line.appendChild(cases);
caseList.push(cases);
}
}
let relativeDeplacements = {};
class piece {
html;
constructor (type, line, column, color, deplacement, id) {
id = 0;
while (relativeDeplacements[id] !== undefined) {
id++;
}
let piece = document.createElement("img");
let index = ((line - 1) * 8) + column;
let parent = caseList[index];
let piecefocused = false;
piece.style = "width: 100%;";
parent.appendChild(piece);
piece.src = "./images/" + type + " " + parent.style.backgroundColor + " " + color + ".png";
this.relativeDeplacement = [];
this.RRD = function refreshRelativeDeplacement () {
this.relativeDeplacement = [];
if (deplacement.line !== undefined) {
if (deplacement.line.top !== undefined) {
for (let i = 1; i < deplacement.line.top + 1; i++) {
let newIndex = index - (i * 8);
if (caseList[newIndex] !== undefined) {
this.relativeDeplacement.push([caseList[newIndex], line - i, column + 0]);
if (caseList[newIndex].childNodes[0] !== undefined) {
break;
}
}
}
}
if (deplacement.line.bottom !== undefined) {
for (let i = 1; i < deplacement.line.bottom + 1; i++) {
let newIndex = index + (i * 8);
if (caseList[newIndex] !== undefined) {
this.relativeDeplacement.push([caseList[newIndex], line + i, column + 0]);
if (caseList[newIndex].childNodes[0] !== undefined) {
break;
}
}
}
}
if (deplacement.line.right !== undefined) {
for (let i = 1; i < deplacement.line.right + 1; i++) {
let newIndex = index + i;
if (caseList[newIndex] !== undefined && newIndex < (Math.floor(index/8)*8)+8) {
this.relativeDeplacement.push([caseList[newIndex], line + 0, column + i]);
if (caseList[newIndex].childNodes[0] !== undefined) {
break;
}
}
}
}
}
relativeDeplacements[id] = this.relativeDeplacement;
}
this.RRD();
document.addEventListener("mousedown", (event) => {
pieceList.forEach((element) => {
element.RRD();
});
if (color == turn && turnToplay == color) {
if (event.target == piece) {
piecefocused = true;
this.relativeDeplacement.forEach(element => {
if (element[0] !== undefined) element[0].style.boxShadow = "#ff5500 0 0 0 3px inset";
});
} else {
if (piecefocused == true) {
this.relativeDeplacement.forEach(element => {
if (element[0] !== undefined) {
element[0].style.boxShadow = "";
if (event.target == element[0] && turn == color || event.target == element[0].childNodes[0] && turn == color) {
this.RRD();
piece.remove();
element[0].innerHTML = "";
element[0].appendChild(piece);
piece.src = "./images/" + type + " " + element[0].style.backgroundColor + " " + color + ".png";
line = element[1];
column = element[2];
index = ((line - 1) * 8) + column;
this.relativeDeplacement = [];
this.RRD();
if (turn == "blue") {
turn = "red";
tabBody.style.backgroundColor = "rgb(237, 28, 36)";
} else if (turn == "red") {
turn = "blue";
tabBody.style.backgroundColor = "rgb(0, 162, 232)";
};
if (color == "blue") turnToplay = "red";
if (color == "red") turnToplay = "blue";
}
}
});
}
piecefocused = false;
}
}
})
}
}
pieceList = [];
for (let i = 0; i < 8; i++) {
let a = new piece ("pion", 7, i, "blue", {line: {top: 2,},});
pieceList.push(a);
}
for (let i = 0; i < 8; i++) {
let a = new piece ("pion", 2, i, "red", {
line: {bottom: 10, right: 10,},
});
pieceList.push(a);
}
});
}, "background-color: rgb(23, 175, 32); color: white;");
Modifies les définitions et redéfinitions de variables en JavaScript avec cette syntaxe """exempleVar = exempleValeur;""" donnera """exempleVar = cpush("exempleVar", exempleValeur);""". En gros que toutes les variables du code passent par un appel de cpush avec pour premier argument leur nom (entre guillemets) et en deuxième leur valeur.