-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
168 lines (140 loc) · 5.25 KB
/
Copy pathscript.js
File metadata and controls
168 lines (140 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
document.addEventListener('DOMContentLoaded', () => {
const tbody = document.querySelector('tbody');
const thx = document.querySelectorAll('th');
const trxb = tbody.querySelectorAll('tr');
const searchInput = document.getElementById('searchInput');
const categorySelect = document.getElementById('categorySelect');
const specsTable = document.getElementById('specsTable');
const rows = specsTable.getElementsByTagName('tr');
const columnMap = {
os: 0,
version: 1,
cpu: 2,
cores: 3,
threads: 4,
gpu: 5,
vram: 6,
ram: 7,
owner: 8,
denomination: 9,
device: 10
};
let currentSortColumn = -1;
let currentSortDirection = null;
thx.forEach((th, index) => {
th.addEventListener('click', () => {
const isAscending = currentSortColumn === index && currentSortDirection === 'asc';
currentSortDirection = isAscending ? 'desc' : 'asc';
currentSortColumn = index;
const sortedRows = Array.from(trxb).sort((row1, row2) => {
const tdValue = (row, idx) => row.children[idx].textContent.trim();
const v1 = tdValue(row1, index);
const v2 = tdValue(row2, index);
if (!isNaN(parseFloat(v1)) && !isNaN(parseFloat(v2))) {
return isAscending ? v2 - v1 : v1 - v2;
}
return isAscending
? v2.localeCompare(v1)
: v1.localeCompare(v2);
});
sortedRows.forEach(row => tbody.appendChild(row));
});
});
searchInput.addEventListener('keyup', filterTable);
categorySelect.addEventListener('change', filterTable);
function filterTable() {
const filter = searchInput.value.toLowerCase();
const category = categorySelect.value;
for (let i = 0; i < rows.length; i++) {
const cells = rows[i].getElementsByTagName('td');
let match = false;
if (category === "all") {
for (let j = 0; j < cells.length; j++) {
if (cells[j].textContent.toLowerCase().includes(filter)) {
match = true;
break;
}
}
} else {
const columnIndex = columnMap[category];
if (cells[columnIndex] && cells[columnIndex].textContent.toLowerCase().includes(filter)) {
match = true;
}
}
rows[i].style.display = match ? '' : 'none';
}
}
});
// Fonction pour activer/désactiver le mode sombre
function toggleDarkMode() {
const body = document.body;
const switchInput = document.getElementById('darkModeToggle');
// Si le switch est coché, on active le dark mode
if (switchInput.checked) {
body.classList.add('dark-mode');
localStorage.setItem('darkMode', 'enabled'); // Enregistrer dans le localStorage
} else {
body.classList.remove('dark-mode');
localStorage.setItem('darkMode', 'disabled'); // Enregistrer dans le localStorage
}
}
// Vérifier si le dark mode était activé précédemment dans le localStorage
function checkDarkMode() {
const darkModeStatus = localStorage.getItem('darkMode');
const switchInput = document.getElementById('darkModeToggle');
const body = document.body;
// Si le dark mode était activé, on applique la classe "dark-mode"
if (darkModeStatus === 'enabled') {
body.classList.add('dark-mode');
switchInput.checked = true; // Coche le switch
} else {
body.classList.remove('dark-mode');
switchInput.checked = false; // Décoche le switch
}
}
// Initialisation de la page
document.addEventListener('DOMContentLoaded', () => {
checkDarkMode(); // Vérifie et applique le dark mode au chargement de la page
// Écouteur d'événements sur le switch
const switchInput = document.getElementById('darkModeToggle');
switchInput.addEventListener('change', toggleDarkMode); // Toggle le dark mode lors du changement de l'état du switch
});
function copyReceiverLink() {
let url = window.location.href;
if (url.includes("index.php")) {
url = url.replace("index.php", "receiver.php");
} else {
url = url.replace(/\/?$/, "/receiver.php");
}
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(url).then(showCopyToast).catch(() => {
fallbackCopy(url);
});
} else {
fallbackCopy(url);
}
}
function fallbackCopy(text) {
const textarea = document.createElement("textarea");
textarea.value = text;
textarea.style.position = "fixed";
textarea.style.opacity = "0";
document.body.appendChild(textarea);
textarea.focus();
textarea.select();
try {
document.execCommand("copy");
showCopyToast();
} catch (e) {
console.error("Copy failed");
}
document.body.removeChild(textarea);
}
function showCopyToast() {
const toast = document.getElementById("copyToast");
if (!toast) return;
toast.classList.add("show");
setTimeout(() => {
toast.classList.remove("show");
}, 1500);
}