mirror of
https://github.com/rvtr/wiki.git
synced 2025-10-31 06:31:13 -04:00
Remove unused JS
This commit is contained in:
parent
2f567f3848
commit
92734ed05b
@ -1,19 +0,0 @@
|
||||
const lengths = [1, 60, 3600, 86400, 604800, 2592000, 31536000, Infinity];
|
||||
const labels = ["", "second", "minute", "hour", "day", "week", "month", "year"];
|
||||
|
||||
function timeDifference(now, then) {
|
||||
let dif = Math.round((now - then) / 1000);
|
||||
|
||||
for(let i in lengths) {
|
||||
if(dif < lengths[i]) {
|
||||
return Math.round(dif / lengths[i - 1]) + " " + labels[i] + (Math.round(dif / lengths[i - 1]) == 1 ? "" : "s") + " ago";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(let i = 0; i < document.getElementsByTagName("time").length; i++) {
|
||||
let elem = document.getElementsByTagName("time")[i];
|
||||
let date = new Date(elem.dateTime);
|
||||
elem.innerText = timeDifference(new Date(), date);
|
||||
elem.title = date.toLocaleString();
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
Array.from(document.getElementsByClassName("back-link")).forEach(r => {
|
||||
if(window.history.length > 1)
|
||||
r.href = "javascript:window.history.back()";
|
||||
});
|
||||
|
||||
Array.from(document.getElementsByClassName("qr-link")).forEach(r => {
|
||||
r.href = "javascript:void(0);";
|
||||
});
|
||||
|
||||
Array.from(document.getElementsByClassName("script-show")).forEach(r => {
|
||||
r.classList.remove("d-none");
|
||||
});
|
||||
@ -1,11 +0,0 @@
|
||||
let item
|
||||
function search(query) {
|
||||
Array.from(document.getElementById("card-container").children).forEach(function(r) {
|
||||
let card = r.children[0];
|
||||
for(let item in card.dataset) {
|
||||
if(card.dataset[item].toLowerCase().includes(query.toLowerCase()))
|
||||
return r.classList.remove("d-none");
|
||||
}
|
||||
r.classList.add("d-none");
|
||||
});
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
if(!localStorage.sortDirection)
|
||||
localStorage.sortDirection = 1;
|
||||
if(!localStorage.sortProp)
|
||||
localStorage.sortProp = "updated";
|
||||
|
||||
document.getElementById("sort-" + localStorage.sortProp).classList.add("btn-secondary");
|
||||
document.getElementById("sort-" + localStorage.sortProp).classList.remove("btn-outline-secondary");
|
||||
document.getElementById("sort-direction").innerText = parseInt(localStorage.sortDirection) ? "Descending" : "Ascending";
|
||||
sort();
|
||||
|
||||
function toggleSortDirection() {
|
||||
localStorage.sortDirection ^= 1;
|
||||
document.getElementById("sort-direction").innerText = parseInt(localStorage.sortDirection) ? "Descending" : "Ascending";
|
||||
sort();
|
||||
}
|
||||
|
||||
function sort(prop) {
|
||||
if(prop) {
|
||||
document.getElementById("sort-" + prop).classList.remove("btn-outline-secondary");
|
||||
document.getElementById("sort-" + prop).classList.add("btn-secondary");
|
||||
document.getElementById("sort-" + localStorage.sortProp).classList.add("btn-outline-secondary");
|
||||
document.getElementById("sort-" + localStorage.sortProp).classList.remove("btn-secondary");
|
||||
localStorage.sortProp = prop;
|
||||
}
|
||||
|
||||
let sorted = Array.from(document.getElementsByClassName("card")).sort(function(l, r) {
|
||||
return ((l.dataset[localStorage.sortProp].toLowerCase() < r.dataset[localStorage.sortProp].toLowerCase()) ^ localStorage.sortDirection) ? -1 : 1;
|
||||
});
|
||||
let container = document.getElementById("card-container");
|
||||
container.innerHTML = "";
|
||||
sorted.forEach(function(r) {
|
||||
let col = document.createElement("div");
|
||||
col.classList = "col mb-3";
|
||||
col.appendChild(r);
|
||||
container.appendChild(col);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user