Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/public/js/main.js

89 lignes
2,9 Kio
JavaScript
Brut Vue normale Historique

2017-06-04 07:43:41 +02:00
// @source https://github.com/NyaaPantsu/nyaa/tree/dev/public/js
// @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt Expat
var explosion = document.getElementById("explosion");
var nyanpassu = document.getElementById("nyanpassu");
var kawaii = document.getElementById("kawaii");
// Switches between themes when a new one is selected
function switchThemes(){
themeName = document.getElementById("theme-selector").value
var head = document.getElementsByTagName("head")[0];
// Remove the theme in place, it fails if one isn't set
try{
head.removeChild(document.getElementById("theme"));
} catch(err){}
// Don't add a node if we don't want extra styling
if(themeName === ""){
return;
}
// Create the new one and put it back
var newTheme = document.createElement("link");
newTheme.setAttribute("rel", "stylesheet");
newTheme.setAttribute("href", "/css/"+ themeName + ".css");
newTheme.setAttribute("id", "theme");
head.appendChild(newTheme);
}
2017-05-05 12:59:56 +02:00
// Used by spoiler tags
function toggleLayer(elem) {
if (elem.classList.contains("hide"))
elem.classList.remove("hide");
else
elem.classList.add("hide");
}
function parseAllDates() {
// Date formatting
var lang = document.getElementsByTagName("html")[0].getAttribute("lang");
var ymdOpt = { year: "numeric", month: "short", day: "numeric" };
var hmOpt = { hour: "numeric", minute: "numeric" };
2017-05-05 15:55:25 +02:00
var list = document.getElementsByClassName("date-short");
for(var i in list) {
var e = list[i];
e.title = e.innerText;
e.innerText = new Date(e.innerText).toLocaleString(lang, ymdOpt);
}
2017-05-05 15:55:25 +02:00
var list = document.getElementsByClassName("date-full");
for(var i in list) {
var e = list[i];
e.title = e.innerText;
e.innerText = new Date(e.innerText).toLocaleString(lang);
}
2017-05-05 15:55:25 +02:00
}
parseAllDates();
/*Fixed-Navbar offset fix*/
document.addEventListener("DOMContentLoaded", function(event) {
var shiftWindow = function() { scrollBy(0, -70) };
if (location.hash) shiftWindow();
window.addEventListener("hashchange", shiftWindow);
document.getElementsByClassName("search-box")[0].addEventListener("focus", function (e) {
var w = document.getElementsByClassName("h-user")[0].offsetWidth;
document.getElementsByClassName("h-user")[0].style.display = "none";
document.getElementsByClassName("search-box")[0].style.width = document.getElementsByClassName("search-box")[0].offsetWidth + w + "px";
});
document.getElementsByClassName("search-box")[0].addEventListener("blur", function (e) {
document.getElementsByClassName("search-box")[0].style.width = "";
document.getElementsByClassName("h-user")[0].style.display = "inline-block";
});
});
function playVoice() {
2017-05-27 23:33:52 +02:00
if (explosion) {
explosion.volume = 0.2;
explosion.play();
2017-05-27 23:33:52 +02:00
}
else if (kawaii) {
kawaii.volume = 0.2;
kawaii.play();
}
2017-05-27 23:33:52 +02:00
else {
nyanpassu.volume = 0.2;
nyanpassu.play();
}
}
2017-06-04 07:43:41 +02:00
// @license-end