Massive assets cleanup.
This commit is contained in:
parent
dcbd6ae6d5
commit
7fa74bbfef
35 changed files with 364 additions and 450 deletions
|
@ -1,276 +0,0 @@
|
|||
Date.prototype.getWeek = function() {
|
||||
var date = new Date(this.getTime());
|
||||
date.setHours(0, 0, 0, 0);
|
||||
date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
|
||||
var week1 = new Date(date.getFullYear(), 0, 4);
|
||||
return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7);
|
||||
}
|
||||
Date.prototype.getWeekYear = function() {
|
||||
var date = new Date(this.getTime());
|
||||
date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
|
||||
return date.getFullYear();
|
||||
}
|
||||
|
||||
window.fm = (function() {
|
||||
var fm = this;
|
||||
this.container = document.querySelector('.container');
|
||||
this.headerBackground = null;
|
||||
this.originalHeaderBackground = null;
|
||||
this.defaultCoverImage = 'https://lastfm.freetls.fastly.net/i/u/174s/2a96cbd8b46e442fc41c2b86b821562f.png';
|
||||
this.indexIsPlaying = false;
|
||||
this.indexPlayingDefaultCover = false;
|
||||
this.indexPlayingContainer = null;
|
||||
this.indexPlayingCover = null;
|
||||
this.indexPlayingTitle = null;
|
||||
this.indexPlayingArtist = null;
|
||||
this.indexLastNp = null;
|
||||
this.indexPlayingInterval = null;
|
||||
this.homeInterval = null;
|
||||
|
||||
this.callByName = function(name, args) {
|
||||
var ref = window,
|
||||
parent = null,
|
||||
parts = name.split('.');
|
||||
for(var i = 0; i < parts.length; ++i) {
|
||||
parent = ref;
|
||||
if(typeof ref[parts[i]] !== 'undefined')
|
||||
ref = ref[parts[i]];
|
||||
else return;
|
||||
}
|
||||
if(typeof ref !== 'function')
|
||||
return;
|
||||
return ref.apply(parent, args);
|
||||
};
|
||||
|
||||
this.runFuncs = function(funcs) {
|
||||
for(var i = 0; i < funcs.length; ++i)
|
||||
fm.callByName(funcs[i][0], funcs[i].slice(1));
|
||||
};
|
||||
|
||||
if(this.onload && Array.isArray(this.onload))
|
||||
window.addEventListener('load', function() { fm.runFuncs(fm.onload); });
|
||||
|
||||
if(sessionStorage.getItem('header-bgs') === null
|
||||
|| sessionStorage.getItem('header-bgs-loaded') < Date.now() - 86400000) {
|
||||
var hXhr = new XMLHttpRequest;
|
||||
hXhr.onload = function() {
|
||||
sessionStorage.setItem('header-bgs', hXhr.responseText);
|
||||
sessionStorage.setItem('header-bgs-loaded', Date.now());
|
||||
};
|
||||
hXhr.open('GET', '/header-bgs.json');
|
||||
hXhr.send();
|
||||
}
|
||||
|
||||
this.selectTextInElement = function(elem) {
|
||||
// MSIE
|
||||
if(document.body.createTextRange) {
|
||||
var range = document.body.createTextRange();
|
||||
range.moveToElementText(elem);
|
||||
range.select();
|
||||
return;
|
||||
}
|
||||
|
||||
// Mozilla
|
||||
if(window.getSelection) {
|
||||
var select = window.getSelection(),
|
||||
range = document.createRange();
|
||||
range.selectNodeContents(elem);
|
||||
select.removeAllRanges();
|
||||
select.addRange(range);
|
||||
return;
|
||||
}
|
||||
|
||||
console.warn('Unable to select text.');
|
||||
};
|
||||
|
||||
this.copySelectedText = function() {
|
||||
if(document.execCommand) {
|
||||
document.execCommand('copy');
|
||||
return;
|
||||
}
|
||||
|
||||
console.warn('Unable to copy text.');
|
||||
};
|
||||
|
||||
this.getNowListening = function(callback) {
|
||||
if(!callback)
|
||||
return;
|
||||
|
||||
const self = this;
|
||||
|
||||
$x.get('https://now.flash.moe/get.php?u=flashwave_').then(output => {
|
||||
if(output.status !== 200)
|
||||
return;
|
||||
|
||||
let info = output.json();
|
||||
if(info.length < 1)
|
||||
return;
|
||||
|
||||
info = info[0];
|
||||
|
||||
callback.call(self, {
|
||||
name: info.name,
|
||||
now_playing: !!info.nowplaying,
|
||||
url: info.url,
|
||||
cover: info.images?.large ?? '',
|
||||
artist: {
|
||||
name: info.artist?.name ?? '',
|
||||
url: info.url.split('/_/')[0]
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
this.updateIndexNowListening = function() {
|
||||
window.fm.getNowListening(function(info) {
|
||||
if(this.indexLastNp === null
|
||||
|| this.indexLastNp.url != info.url
|
||||
|| this.indexLastNp.now_playing != info.now_playing) {
|
||||
if(this.indexLastNp !== null)
|
||||
this.originalHeaderBackground = this.getRandomHeaderBackground();
|
||||
this.indexLastNp = info;
|
||||
} else return;
|
||||
|
||||
this.indexIsPlaying = info.now_playing;
|
||||
this.indexPlayingDefaultCover = !info.cover || info.cover === this.defaultCoverImage;
|
||||
this.indexPlayingContainer.classList[info.now_playing ? 'remove' : 'add']('header-now-playing-hidden');
|
||||
this.indexPlayingCover.alt = this.indexPlayingCover.src = (info.cover !== this.defaultCoverImage ? info.cover : '//now.flash.moe/resources/no-cover.png');
|
||||
this.indexPlayingTitle.textContent = this.indexPlayingTitle.title = info.name;
|
||||
this.indexPlayingTitle.href = info.url;
|
||||
this.indexPlayingArtist.textContent = this.indexPlayingArtist.title = (info.artist || {}).name || '';
|
||||
this.indexPlayingArtist.href = (info.artist || {}).url || '';
|
||||
this.switchHeaderBackground(
|
||||
info.now_playing && !this.indexPlayingDefaultCover
|
||||
? this.indexPlayingCover.src
|
||||
: this.originalHeaderBackground
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
this.getRandomHeaderBackground = function() {
|
||||
var set = JSON.parse(sessionStorage.getItem('header-bgs'));
|
||||
if(!set)
|
||||
return '/images/404.jpg';
|
||||
return set[parseInt(Math.random() * set.length) - 1];
|
||||
};
|
||||
|
||||
this.setRandomHeaderBackground = function() {
|
||||
this.switchHeaderBackground(this.getRandomHeaderBackground());
|
||||
};
|
||||
|
||||
this.setRandomHeaderBackgroundIfNotPlaying = function() {
|
||||
if(!this.indexIsPlaying || this.indexPlayingDefaultCover)
|
||||
this.setRandomHeaderBackground();
|
||||
};
|
||||
|
||||
this.getCurrentHeaderBackground = function() {
|
||||
return this.headerBackground.querySelector('img').src;
|
||||
};
|
||||
|
||||
this.headerBackgroundIsChanging = false;
|
||||
this.switchHeaderBackground = function(url) {
|
||||
if(this.headerBackgroundIsChanging || this.getCurrentHeaderBackground() === url)
|
||||
return;
|
||||
this.headerBackgroundIsChanging = true;
|
||||
var newImg = document.createElement('img'),
|
||||
oldImg = this.headerBackground.querySelector('img');
|
||||
newImg.alt = newImg.src = url;
|
||||
newImg.style.opacity = '0';
|
||||
oldImg.style.zIndex = '-1';
|
||||
newImg.style.zIndex = '0';
|
||||
this.headerBackground.appendChild(newImg);
|
||||
newImg.onload = function() {
|
||||
setTimeout(function() {
|
||||
newImg.style.opacity = null;
|
||||
setTimeout(function() {
|
||||
newImg.style.zIndex = null;
|
||||
this.headerBackground.removeChild(oldImg);
|
||||
this.headerBackgroundIsChanging = false;
|
||||
}.bind(this), 500);
|
||||
}.bind(this), 50);
|
||||
}.bind(this);
|
||||
newImg.onerror = function() {
|
||||
this.headerBackgroundIsChanging = false;
|
||||
this.switchHeaderBackground(this.originalHeaderBackground);
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
this.headerBackground = document.querySelector('.header-background');
|
||||
this.originalHeaderBackground = this.headerBackground.querySelector('img').src;
|
||||
|
||||
this.initIndex = function(npInterval) {
|
||||
if(!this.indexPlayingContainer) {
|
||||
this.indexPlayingContainer = document.querySelector('.header-now-playing');
|
||||
this.indexPlayingCover = window.fm.indexPlayingContainer.querySelector('.header-now-playing-cover img');
|
||||
this.indexPlayingCover.onerror = function() {
|
||||
this.indexPlayingCover.src = '//now.flash.moe/resources/no-cover.png';
|
||||
}.bind(this);
|
||||
this.indexPlayingTitle = window.fm.indexPlayingContainer.querySelector('.header-now-playing-title a');
|
||||
this.indexPlayingArtist = window.fm.indexPlayingContainer.querySelector('.header-now-playing-artist a');
|
||||
}
|
||||
|
||||
if(this.indexPlayingInterval) {
|
||||
clearInterval(this.indexPlayingInterval);
|
||||
this.indexPlayingInterval = null;
|
||||
}
|
||||
|
||||
this.updateIndexNowListening();
|
||||
this.indexPlayingInterval = setInterval(this.updateIndexNowListening, (npInterval || 30) * 1000);
|
||||
};
|
||||
|
||||
this.initClock = function() {
|
||||
if(this.homeInterval)
|
||||
return;
|
||||
|
||||
var digitalClock = document.querySelector('.php-time-digital'),
|
||||
analogClock = document.querySelector('.php-time-analog'),
|
||||
dateZone = document.querySelector('.php-time-date'),
|
||||
digHours = digitalClock.querySelector('.php-time-digital-hours'),
|
||||
digSeparator = digitalClock.querySelector('.php-time-digital-separator'),
|
||||
digMinutes = digitalClock.querySelector('.php-time-digital-minutes'),
|
||||
angHours = analogClock.querySelector('.clock-hand-hours'),
|
||||
angMinutes = analogClock.querySelector('.clock-hand-minutes'),
|
||||
angSeconds = analogClock.querySelector('.clock-hand-seconds')
|
||||
dateWeek = dateZone.querySelector('.php-date-week'),
|
||||
dateDay = dateZone.querySelector('.php-date-day'),
|
||||
dateMonth = dateZone.querySelector('.php-date-month'),
|
||||
dateYear = dateZone.querySelector('.php-date-year');
|
||||
|
||||
this.homeInterval = setInterval(function() {
|
||||
if(!document.body.contains(digitalClock)) {
|
||||
clearInterval(this.homeInterval);
|
||||
this.homeInterval = null;
|
||||
return;
|
||||
}
|
||||
|
||||
var time = new Date;
|
||||
|
||||
var dHour = time.getHours(),
|
||||
dMin = time.getMinutes();
|
||||
|
||||
if(dHour < 10)
|
||||
dHour = '0' + dHour;
|
||||
if(dMin < 10)
|
||||
dMin = '0' + dMin;
|
||||
|
||||
dateWeek.textContent = time.getWeek();
|
||||
dateDay.textContent = time.getDate();
|
||||
dateMonth.textContent = time.getMonth() + 1;
|
||||
dateYear.textContent = time.getFullYear();
|
||||
|
||||
digHours.textContent = dHour;
|
||||
digMinutes.textContent = dMin;
|
||||
digSeparator.classList[time.getSeconds() % 2 ? 'add' : 'remove']('php-time-digital-separator-hidden');
|
||||
|
||||
var rSec = time.getSeconds() / 60,
|
||||
rMin = (time.getMinutes() + Math.min(.99, rSec)) / 60,
|
||||
rHour = (time.getHours() + Math.min(.99, rMin)) / 12;
|
||||
|
||||
angHours.style.setProperty('--hand-rotation', (rHour * 360).toString() + 'deg');
|
||||
angMinutes.style.setProperty('--hand-rotation', (rMin * 360).toString() + 'deg');
|
||||
angSeconds.style.setProperty('--hand-rotation', (rSec * 360).toString() + 'deg');
|
||||
}.bind(this), 200);
|
||||
};
|
||||
|
||||
return this;
|
||||
}).call(window.fm || {});
|
|
@ -1,75 +0,0 @@
|
|||
(function() {
|
||||
var chars = document.getElementsByClassName('ascii-char'),
|
||||
search = document.getElementById('search');
|
||||
|
||||
function charsFilter(filter) {
|
||||
if(!filter) {
|
||||
for(var i = 0; i < chars.length; ++i)
|
||||
chars[i].classList.remove('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
filter = filter.toLowerCase();
|
||||
|
||||
for(var i = 0; i < chars.length; ++i) {
|
||||
var chr = chars[i],
|
||||
code = (chr.dataset.keyCode || 0).toString().toLowerCase(),
|
||||
print = (chr.dataset.keyPrint || "\0").toString().toLowerCase(),
|
||||
desc = (chr.dataset.keyDesc || '').toString().toLowerCase(),
|
||||
html = (chr.dataset.keyHtml || "\0").toString().toLowerCase(),
|
||||
codeInt = parseInt(code),
|
||||
isMatch = (filter === 'printable' && (codeInt > 31 && codeInt < 127))
|
||||
|| (filter === 'control' && (codeInt < 32 || codeInt === 127))
|
||||
|| code == filter || print == filter
|
||||
|| html == filter || desc.indexOf(filter) >= 0;
|
||||
chr.classList[isMatch ? 'remove' : 'add']('hidden');
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('scroll', function() {
|
||||
var hidden = document.getElementsByClassName('js-hidden-on-scroll'),
|
||||
invisible = document.getElementsByClassName('js-invisible-on-scroll'),
|
||||
atTop = window.scrollY === 0;
|
||||
|
||||
for(var i = 0; i < hidden.length; ++i)
|
||||
hidden[i].classList[atTop ? 'remove' : 'add']('hidden');
|
||||
for(var i = 0; i < invisible.length; ++i)
|
||||
invisible[i].classList[atTop ? 'remove' : 'add']('invisible');
|
||||
});
|
||||
search.addEventListener('keyup', function() {
|
||||
location.hash = search.value.trim();
|
||||
});
|
||||
window.addEventListener('hashchange', function() {
|
||||
charsFilter(decodeURIComponent((location.hash || '#').substring(1)));
|
||||
});
|
||||
if(location.hash.length > 0) {
|
||||
search.value = location.hash.substring(1).trim();
|
||||
charsFilter(search.value);
|
||||
}
|
||||
|
||||
for(var i = 0; i < chars.length; ++i) {
|
||||
chars[i].addEventListener('click', function(ev) {
|
||||
var target = ev.target;
|
||||
|
||||
while(target !== null && typeof target.dataset.copy === 'undefined') {
|
||||
target = target.parentNode || null;
|
||||
|
||||
if(target.classList.contains('char'))
|
||||
break;
|
||||
}
|
||||
|
||||
if(target === null || typeof target.dataset.copy === 'undefined')
|
||||
return;
|
||||
|
||||
var doCopy = function() { navigator.clipboard.writeText(target.dataset.copy); };
|
||||
|
||||
if(typeof window.mozInnerScreenX !== 'undefined')
|
||||
doCopy();
|
||||
else
|
||||
navigator.permissions.query({name: 'clipboard-write'}).then(function(res) {
|
||||
if(res.state === 'granted' || res.state === 'prompt')
|
||||
doCopy();
|
||||
});
|
||||
});
|
||||
}
|
||||
})();
|
|
@ -1,21 +0,0 @@
|
|||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
position: relative;
|
||||
outline-style: none;
|
||||
}
|
||||
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none !important;
|
||||
visibility: hidden !important;
|
||||
}
|
||||
|
||||
.invisible {
|
||||
opacity: 0;
|
||||
}
|
|
@ -1,3 +1,33 @@
|
|||
@font-face {
|
||||
font-family: 'Electrolize';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Electrolize'), local('Electrolize-Regular'), url('/fonts/electrolize400.woff2') format('woff2');
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
position: relative;
|
||||
outline-style: none;
|
||||
}
|
||||
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none !important;
|
||||
visibility: hidden !important;
|
||||
}
|
||||
|
||||
.invisible {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
html {
|
||||
scrollbar-color: #4a3650 #111;
|
||||
}
|
||||
|
@ -206,3 +236,6 @@ body {
|
|||
|
||||
@include home.css;
|
||||
@include clock.css;
|
||||
|
||||
@include ascii.css;
|
||||
@include whois.css;
|
76
assets/makai.js/ascii.js
Normal file
76
assets/makai.js/ascii.js
Normal file
|
@ -0,0 +1,76 @@
|
|||
#include utility.js
|
||||
|
||||
const MakaiASCII = () => {
|
||||
const chars = $c('ascii-char');
|
||||
const search = $i('search');
|
||||
|
||||
const charsFilter = (filter) => {
|
||||
if(!filter) {
|
||||
for(const chr of chars)
|
||||
chr.classList.remove('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
filter = filter.toLowerCase();
|
||||
|
||||
for(const chr of chars) {
|
||||
const code = (chr.dataset.keyCode || 0).toString().toLowerCase();
|
||||
const print = (chr.dataset.keyPrint || "\0").toString().toLowerCase();
|
||||
const desc = (chr.dataset.keyDesc || '').toString().toLowerCase();
|
||||
const html = (chr.dataset.keyHtml || "\0").toString().toLowerCase();
|
||||
const codeInt = parseInt(code);
|
||||
const isMatch = (filter === 'printable' && (codeInt > 31 && codeInt < 127))
|
||||
|| (filter === 'control' && (codeInt < 32 || codeInt === 127))
|
||||
|| code == filter || print == filter
|
||||
|| html == filter || desc.indexOf(filter) >= 0;
|
||||
chr.classList.toggle('hidden', !isMatch);
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('scroll', () => {
|
||||
const atTop = window.scrollY === 0;
|
||||
|
||||
const hidden = $c('js-hidden-on-scroll');
|
||||
for(const elem of hidden)
|
||||
elem.classList.toggle('hidden', !atTop);
|
||||
|
||||
const invisible = $c('js-invisible-on-scroll');
|
||||
for(const elem of invisible)
|
||||
elem.classList.toggle('invisible', !atTop);
|
||||
});
|
||||
search.addEventListener('keyup', () => {
|
||||
location.hash = search.value.trim();
|
||||
});
|
||||
window.addEventListener('hashchange', () => {
|
||||
charsFilter(decodeURIComponent((location.hash || '#').substring(1)));
|
||||
});
|
||||
if(location.hash.length > 0) {
|
||||
search.value = location.hash.substring(1).trim();
|
||||
charsFilter(search.value);
|
||||
}
|
||||
|
||||
for(const chr of chars) {
|
||||
chr.addEventListener('click', ev => {
|
||||
let target = ev.target;
|
||||
while(target !== null && typeof target.dataset.copy === 'undefined') {
|
||||
target = target.parentNode || null;
|
||||
|
||||
if(target.classList.contains('char'))
|
||||
break;
|
||||
}
|
||||
|
||||
if(target === null || typeof target.dataset.copy === 'undefined')
|
||||
return;
|
||||
|
||||
const doCopy = () => { navigator.clipboard.writeText(target.dataset.copy); };
|
||||
|
||||
if(typeof window.mozInnerScreenX !== 'undefined')
|
||||
doCopy();
|
||||
else
|
||||
navigator.permissions.query({ name: 'clipboard-write' }).then(res => {
|
||||
if(res.state === 'granted' || res.state === 'prompt')
|
||||
doCopy();
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
59
assets/makai.js/dev-home.js
Normal file
59
assets/makai.js/dev-home.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
#include utility.js
|
||||
|
||||
const MakaiDevHome = () => {
|
||||
const digitalClock = $q('.php-time-digital');
|
||||
const analogClock = $q('.php-time-analog');
|
||||
const dateZone = $q('.php-time-date');
|
||||
const digHours = digitalClock.querySelector('.php-time-digital-hours');
|
||||
const digSeparator = digitalClock.querySelector('.php-time-digital-separator');
|
||||
const digMinutes = digitalClock.querySelector('.php-time-digital-minutes');
|
||||
const angHours = analogClock.querySelector('.clock-hand-hours');
|
||||
const angMinutes = analogClock.querySelector('.clock-hand-minutes');
|
||||
const angSeconds = analogClock.querySelector('.clock-hand-seconds');
|
||||
const dateWeek = dateZone.querySelector('.php-date-week');
|
||||
const dateDay = dateZone.querySelector('.php-date-day');
|
||||
const dateMonth = dateZone.querySelector('.php-date-month');
|
||||
const dateYear = dateZone.querySelector('.php-date-year');
|
||||
|
||||
homeInterval = setInterval(() => {
|
||||
if(!document.body.contains(digitalClock)) {
|
||||
clearInterval(homeInterval);
|
||||
homeInterval = undefined;
|
||||
return;
|
||||
}
|
||||
|
||||
const time = new Date;
|
||||
|
||||
let dHour = time.getHours();
|
||||
let dMin = time.getMinutes();
|
||||
|
||||
if(dHour < 10)
|
||||
dHour = '0' + dHour;
|
||||
if(dMin < 10)
|
||||
dMin = '0' + dMin;
|
||||
|
||||
dateWeek.textContent = (() => {
|
||||
const wd = new Date(time.getTime());
|
||||
wd.setHours(0, 0, 0, 0);
|
||||
wd.setDate(wd.getDate() + 3 - (wd.getDay() + 6) % 7);
|
||||
const week1 = new Date(wd.getFullYear(), 0, 4);
|
||||
return 1 + Math.round(((wd.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7);
|
||||
})();
|
||||
|
||||
dateDay.textContent = time.getDate();
|
||||
dateMonth.textContent = time.getMonth() + 1;
|
||||
dateYear.textContent = time.getFullYear();
|
||||
|
||||
digHours.textContent = dHour;
|
||||
digMinutes.textContent = dMin;
|
||||
digSeparator.classList[time.getSeconds() % 2 ? 'add' : 'remove']('php-time-digital-separator-hidden');
|
||||
|
||||
const rSec = time.getSeconds() / 60;
|
||||
const rMin = (time.getMinutes() + Math.min(.99, rSec)) / 60;
|
||||
const rHour = (time.getHours() + Math.min(.99, rMin)) / 12;
|
||||
|
||||
angHours.style.setProperty('--hand-rotation', (rHour * 360).toString() + 'deg');
|
||||
angMinutes.style.setProperty('--hand-rotation', (rMin * 360).toString() + 'deg');
|
||||
angSeconds.style.setProperty('--hand-rotation', (rSec * 360).toString() + 'deg');
|
||||
}, 200);
|
||||
};
|
139
assets/makai.js/dev-index.js
Normal file
139
assets/makai.js/dev-index.js
Normal file
|
@ -0,0 +1,139 @@
|
|||
#include utility.js
|
||||
#include xhr.js
|
||||
|
||||
const MakaiDevIndex = npInterval => {
|
||||
let headerBackground;
|
||||
let originalHeaderBackground;
|
||||
const defaultCoverImage = 'https://lastfm.freetls.fastly.net/i/u/174s/2a96cbd8b46e442fc41c2b86b821562f.png';
|
||||
let indexIsPlaying = false;
|
||||
let indexPlayingDefaultCover = false;
|
||||
let indexPlayingContainer;
|
||||
let indexPlayingCover;
|
||||
let indexPlayingTitle;
|
||||
let indexPlayingArtist;
|
||||
let indexLastNp;
|
||||
let indexPlayingInterval;
|
||||
let homeInterval;
|
||||
|
||||
if(!sessionStorage.getItem('header-bgs') || sessionStorage.getItem('header-bgs-loaded') < Date.now() - 86400000)
|
||||
$x.get('/header-bgs.json').then(output => {
|
||||
if(output.status !== 200)
|
||||
return;
|
||||
|
||||
sessionStorage.setItem('header-bgs', output.body());
|
||||
sessionStorage.setItem('header-bgs-loaded', Date.now());
|
||||
});
|
||||
|
||||
const getNowListening = callback => {
|
||||
if(!callback)
|
||||
return;
|
||||
|
||||
$x.get('https://now.flash.moe/get.php?u=flashwave_').then(output => {
|
||||
if(output.status !== 200)
|
||||
return;
|
||||
|
||||
let info = output.json();
|
||||
if(info.length < 1)
|
||||
return;
|
||||
|
||||
info = info[0];
|
||||
|
||||
callback({
|
||||
name: info.name,
|
||||
now_playing: !!info.nowplaying,
|
||||
url: info.url,
|
||||
cover: info.images?.large ?? '',
|
||||
artist: {
|
||||
name: info.artist?.name ?? '',
|
||||
url: info.url.split('/_/')[0]
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const updateIndexNowListening = () => {
|
||||
getNowListening(info => {
|
||||
if(!indexLastNp || indexLastNp.url != info.url || indexLastNp.now_playing != info.now_playing) {
|
||||
if(!indexLastNp)
|
||||
originalHeaderBackground = getRandomHeaderBackground();
|
||||
indexLastNp = info;
|
||||
} else return;
|
||||
|
||||
indexIsPlaying = info.now_playing;
|
||||
indexPlayingDefaultCover = !info.cover || info.cover === defaultCoverImage;
|
||||
indexPlayingContainer.classList[info.now_playing ? 'remove' : 'add']('header-now-playing-hidden');
|
||||
indexPlayingCover.alt = indexPlayingCover.src = (info.cover !== defaultCoverImage ? info.cover : '//now.flash.moe/resources/no-cover.png');
|
||||
indexPlayingTitle.textContent = indexPlayingTitle.title = info.name;
|
||||
indexPlayingTitle.href = info.url;
|
||||
indexPlayingArtist.textContent = indexPlayingArtist.title = (info.artist || {}).name || '';
|
||||
indexPlayingArtist.href = (info.artist || {}).url || '';
|
||||
switchHeaderBackground(
|
||||
info.now_playing && !indexPlayingDefaultCover
|
||||
? indexPlayingCover.src
|
||||
: originalHeaderBackground
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const getRandomHeaderBackground = () => {
|
||||
var set = JSON.parse(sessionStorage.getItem('header-bgs'));
|
||||
if(!set)
|
||||
return '/images/404.jpg';
|
||||
return set[parseInt(Math.random() * set.length) - 1];
|
||||
};
|
||||
|
||||
const setRandomHeaderBackground = () => {
|
||||
switchHeaderBackground(getRandomHeaderBackground());
|
||||
};
|
||||
|
||||
const getCurrentHeaderBackground = function() {
|
||||
return headerBackground.querySelector('img').src;
|
||||
};
|
||||
|
||||
let headerBackgroundIsChanging = false;
|
||||
const switchHeaderBackground = function(url) {
|
||||
if(headerBackgroundIsChanging || getCurrentHeaderBackground() === url)
|
||||
return;
|
||||
headerBackgroundIsChanging = true;
|
||||
var newImg = document.createElement('img'),
|
||||
oldImg = headerBackground.querySelector('img');
|
||||
newImg.alt = newImg.src = url;
|
||||
newImg.style.opacity = '0';
|
||||
oldImg.style.zIndex = '-1';
|
||||
newImg.style.zIndex = '0';
|
||||
headerBackground.appendChild(newImg);
|
||||
newImg.onload = () => {
|
||||
setTimeout(() => {
|
||||
newImg.style.opacity = null;
|
||||
setTimeout(() => {
|
||||
newImg.style.zIndex = null;
|
||||
headerBackground.removeChild(oldImg);
|
||||
headerBackgroundIsChanging = false;
|
||||
}, 500);
|
||||
}, 50);
|
||||
};
|
||||
newImg.onerror = () => {
|
||||
headerBackgroundIsChanging = false;
|
||||
switchHeaderBackground(originalHeaderBackground);
|
||||
};
|
||||
};
|
||||
|
||||
headerBackground = $q('.header-background');
|
||||
originalHeaderBackground = headerBackground.querySelector('img').src;
|
||||
|
||||
if(!indexPlayingContainer) {
|
||||
indexPlayingContainer = document.querySelector('.header-now-playing');
|
||||
indexPlayingCover = indexPlayingContainer.querySelector('.header-now-playing-cover img');
|
||||
indexPlayingCover.onerror = () => { indexPlayingCover.src = '//now.flash.moe/resources/no-cover.png'; }
|
||||
indexPlayingTitle = indexPlayingContainer.querySelector('.header-now-playing-title a');
|
||||
indexPlayingArtist = indexPlayingContainer.querySelector('.header-now-playing-artist a');
|
||||
}
|
||||
|
||||
if(indexPlayingInterval) {
|
||||
clearInterval(indexPlayingInterval);
|
||||
indexPlayingInterval = undefined;
|
||||
}
|
||||
|
||||
updateIndexNowListening();
|
||||
indexPlayingInterval = setInterval(updateIndexNowListening, (npInterval || 30) * 1000);
|
||||
};
|
|
@ -1,3 +1,6 @@
|
|||
const $t = document.createTextNode.bind(document);
|
||||
const $er = (type, props, ...children) => $e({ tag: type, attrs: props, child: children });
|
||||
|
||||
const $e = function(info, attrs, child, created) {
|
||||
info = info || {};
|
||||
|
||||
|
@ -55,6 +58,11 @@ const $e = function(info, attrs, child, created) {
|
|||
}
|
||||
break;
|
||||
|
||||
case 'boolean':
|
||||
if(attr)
|
||||
elem.setAttribute(key, '');
|
||||
break;
|
||||
|
||||
default:
|
||||
if(key === 'className')
|
||||
key = 'class';
|
||||
|
@ -101,4 +109,3 @@ const $e = function(info, attrs, child, created) {
|
|||
|
||||
return elem;
|
||||
};
|
||||
const $er = (type, props, ...children) => $e({ tag: type, attrs: props, child: children });
|
19
assets/makai.js/main.js
Normal file
19
assets/makai.js/main.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include ascii.js
|
||||
#include dev-index.js
|
||||
#include dev-home.js
|
||||
#include whois.js
|
||||
|
||||
(() => {
|
||||
const runIfPathStartsWith = (prefix, func, ...args) => {
|
||||
if(location.pathname === prefix || location.pathname.startsWith(`${prefix}/`))
|
||||
func(...args);
|
||||
};
|
||||
|
||||
runIfPathStartsWith('/ascii', MakaiASCII);
|
||||
runIfPathStartsWith('/whois', MakaiWHOIS);
|
||||
runIfPathStartsWith('/home', MakaiDevHome);
|
||||
|
||||
runIfPathStartsWith('/home', MakaiDevIndex, 10);
|
||||
runIfPathStartsWith('/np', MakaiDevIndex, 10);
|
||||
if(location.pathname === '/') MakaiDevIndex();
|
||||
})();
|
|
@ -2,7 +2,6 @@ const $i = document.getElementById.bind(document);
|
|||
const $c = document.getElementsByClassName.bind(document);
|
||||
const $q = document.querySelector.bind(document);
|
||||
const $qa = document.querySelectorAll.bind(document);
|
||||
const $t = document.createTextNode.bind(document);
|
||||
|
||||
const $r = function(element) {
|
||||
if(element && element.parentNode)
|
||||
|
@ -59,6 +58,3 @@ const $csrfp = (function() {
|
|||
},
|
||||
};
|
||||
})();
|
||||
|
||||
#include elem.js
|
||||
#include xhr.js
|
|
@ -1,11 +1,14 @@
|
|||
(function() {
|
||||
let locked = false;
|
||||
const input = $i('lookup-input'),
|
||||
submit = $i('lookup-submit'),
|
||||
result = $i('lookup-result'),
|
||||
tabs = $i('lookup-tabs');
|
||||
#include utility.js
|
||||
#include xhr.js
|
||||
|
||||
const lock = function() {
|
||||
const MakaiWHOIS = () => {
|
||||
let locked = false;
|
||||
const input = $i('lookup-input');
|
||||
const submit = $i('lookup-submit');
|
||||
const result = $i('lookup-result');
|
||||
const tabs = $i('lookup-tabs');
|
||||
|
||||
const lock = () => {
|
||||
if(locked)
|
||||
return false;
|
||||
|
||||
|
@ -15,7 +18,7 @@
|
|||
return true;
|
||||
}
|
||||
|
||||
const unlock = function() {
|
||||
const unlock = () => {
|
||||
if(!locked)
|
||||
return false;
|
||||
|
||||
|
@ -25,7 +28,7 @@
|
|||
return true;
|
||||
}
|
||||
|
||||
const lookup = function(target) {
|
||||
const lookup = target => {
|
||||
if(!lock())
|
||||
return;
|
||||
|
||||
|
@ -43,15 +46,15 @@
|
|||
tabs.innerHTML = '';
|
||||
if(resp.result && resp.result.responses)
|
||||
for(const response of resp.result.responses) {
|
||||
const tab = document.createElement('a'),
|
||||
tabHeader = document.createElement('div'),
|
||||
tabServer = document.createElement('div');
|
||||
const tab = document.createElement('a');
|
||||
const tabHeader = document.createElement('div');
|
||||
const tabServer = document.createElement('div');
|
||||
|
||||
tab.href = 'javascript:;';
|
||||
tab.className = 'whois-result-tab';
|
||||
if(count === 0) tab.className += ' whois-result-tab-active';
|
||||
|
||||
tab.onclick = function() {
|
||||
tab.onclick = () => {
|
||||
const active = $q('.whois-result-tab-active');
|
||||
if(active) active.classList.remove('whois-result-tab-active');
|
||||
tab.classList.add('whois-result-tab-active');
|
||||
|
@ -78,7 +81,7 @@
|
|||
});
|
||||
}
|
||||
|
||||
const readHash = function() {
|
||||
const readHash = () => {
|
||||
if(location.hash.length < 2) {
|
||||
result.textContent = 'Enter a domain or IP address!';
|
||||
return;
|
||||
|
@ -90,14 +93,14 @@
|
|||
lookup(target);
|
||||
};
|
||||
|
||||
window.addEventListener('hashchange', function(ev) {
|
||||
window.addEventListener('hashchange', ev => {
|
||||
readHash();
|
||||
}, false);
|
||||
|
||||
submit.addEventListener('click', function(ev) {
|
||||
submit.addEventListener('click', ev => {
|
||||
ev.preventDefault();
|
||||
location.hash = encodeURIComponent(input.value);
|
||||
});
|
||||
|
||||
readHash();
|
||||
})();
|
||||
};
|
10
build.js
10
build.js
|
@ -21,17 +21,11 @@ const isDebugBuild = fs.existsSync(path.join(rootDir, '.debug'));
|
|||
|
||||
const buildTasks = {
|
||||
js: [
|
||||
{ source: 'common.js', target: '/assets', name: 'common.{hash}.js', },
|
||||
{ source: '2021.js', target: '/assets', name: '2021.{hash}.js', },
|
||||
{ source: 'ascii.js', target: '/assets', name: 'ascii.{hash}.js', },
|
||||
{ source: 'whois.js', target: '/assets', name: 'whois.{hash}.js', },
|
||||
{ source: 'makai.js', target: '/assets', name: 'makai.{hash}.js', },
|
||||
],
|
||||
css: [
|
||||
{ source: 'errors.css', target: '/', name: 'errors.css', },
|
||||
{ source: 'common.css', target: '/assets', name: 'common.{hash}.css', },
|
||||
{ source: '2021.css', target: '/assets', name: '2021.{hash}.css', },
|
||||
{ source: 'ascii.css', target: '/assets', name: 'ascii.{hash}.css', },
|
||||
{ source: 'whois.css', target: '/assets', name: 'whois.{hash}.css', },
|
||||
{ source: 'makai.css', target: '/assets', name: 'makai.{hash}.css', },
|
||||
],
|
||||
twig: [
|
||||
{ source: 'errors/401', target: '/', name: 'error-401.html', },
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
/* latin */
|
||||
@font-face {
|
||||
font-family: 'Electrolize';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Electrolize'), local('Electrolize-Regular'), url(electrolize400.woff2) format('woff2');
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
||||
}
|
|
@ -3,9 +3,6 @@
|
|||
{% set header_title = 'ascii table' %}
|
||||
{% set header_minimal = true %}
|
||||
|
||||
{% set styles = styles|default([])|merge([ globals.assetsInfo.get('ascii.css') ]) %}
|
||||
{% set scripts = scripts|default([])|merge([ globals.assetsInfo.get('ascii.js') ]) %}
|
||||
|
||||
{% set table = [
|
||||
['Null character', 'NUL'],
|
||||
['Start of heading', 'SOH'],
|
||||
|
@ -182,6 +179,4 @@
|
|||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="{{ globals.assetsInfo.get('ascii.js') }}"></script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
<div class="social social-{{ contact.name }}" style="--social-colour: {{ contact.colour }}">
|
||||
{% if contact.hasLink %}
|
||||
<a href="{{ contact.link }}" class="social-background" target="_blank" rel="noopener"></a>
|
||||
{% else %}
|
||||
<div class="social-background" onclick="fm.selectTextInElement(this.parentNode.querySelector('.social-handle')); fm.copySelectedText();"></div>
|
||||
{% endif %}
|
||||
|
||||
<div class="social-icon {{ contact.icon }}"></div>
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
{% set header_title = 'homepage' %}
|
||||
{% set header_full = true %}
|
||||
{% set footer_onload = [['fm.initClock'], ['fm.initIndex', 10]] %}
|
||||
|
||||
{% block container %}
|
||||
<div class="php">
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{% extends 'dev/master.twig' %}
|
||||
|
||||
{% set header_is_index = true %}
|
||||
{% set footer_onload = [['fm.initIndex']] %}
|
||||
|
||||
{% block container %}
|
||||
<div class="index-menu">
|
||||
|
@ -55,8 +54,6 @@
|
|||
<div class="social social-{{ contact.name }}" style="--social-colour: {{ contact.colour }}">
|
||||
{% if contact.hasLink %}
|
||||
<a href="{{ contact.link }}" class="social-background" target="_blank" rel="noopener"></a>
|
||||
{% else %}
|
||||
<div class="social-background" onclick="fm.selectTextInElement(this.parentNode.querySelector('.social-handle')); fm.copySelectedText();"></div>
|
||||
{% endif %}
|
||||
|
||||
<div class="social-icon {{ contact.icon }}"></div>
|
||||
|
|
|
@ -3,4 +3,3 @@
|
|||
{% set header_title = 'now listening' %}
|
||||
{% set header_full = true %}
|
||||
{% set header_now_playing = true %}
|
||||
{% set footer_onload = [['fm.initIndex', 10]] %}
|
||||
|
|
|
@ -2,16 +2,8 @@
|
|||
|
||||
{% set master_title = (header_title is defined ? (header_title ~ ' // ') : '') ~ 'flash.moe' %}
|
||||
|
||||
{% set styles = styles|default([])|merge([
|
||||
globals.assetsInfo.get('2021.css'),
|
||||
'/fonts/electrolize/style.css',
|
||||
globals.assetsInfo.get('common.css'),
|
||||
]) %}
|
||||
|
||||
{% set scripts = scripts|default([])|merge([
|
||||
globals.assetsInfo.get('2021.js'),
|
||||
globals.assetsInfo.get('common.js'),
|
||||
]) %}
|
||||
{% set styles = [ globals.assetsInfo.get('makai.css') ] %}
|
||||
{% set scripts = [ globals.assetsInfo.get('makai.js') ] %}
|
||||
|
||||
{% set master_body_attrs = master_body_attrs|default([])|merge({
|
||||
'class': html_classes({
|
||||
|
@ -64,9 +56,4 @@
|
|||
<div class="footer">
|
||||
<div class="footer-text">© flashwave {{ footer_copy_start|default('2010') }}-{{ footer_copy_end|default(('now'|date('Y'))) }} - {{ random(globals.siteInfo.footerQuotes) }}</div>
|
||||
</div>
|
||||
{% if footer_onload is defined %}
|
||||
<script type="text/javascript">
|
||||
window.fm = { onload: {{ footer_onload|json_encode|raw }} };
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -5,18 +5,14 @@
|
|||
{% if master_title is defined and master_title is not empty %}<title>{{ master_title }}</title>{% endif %}
|
||||
{% block master_head %}{% endblock %}
|
||||
{% if csrfp_available() %}<meta name="csrfp-token" content="{{ csrfp_token() }}">{% endif %}
|
||||
{% if styles is defined and styles is iterable and styles is not empty %}
|
||||
{% for style in styles|reverse %}
|
||||
<link href="{{ style }}" type="text/css" rel="stylesheet">
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% for style in styles|default([]) %}
|
||||
<link href="{{ style }}" type="text/css" rel="stylesheet">
|
||||
{% endfor %}
|
||||
</head>
|
||||
<body{% if master_body_attrs is defined and master_body_attrs is not empty %}{% for name, value in master_body_attrs %}{% if value is not empty %} {{ name }}="{{ value }}"{% endif %}{% endfor %}{% endif %}>
|
||||
{% block master_body %}{% endblock %}
|
||||
{% if scripts is defined and scripts is iterable and scripts is not empty %}
|
||||
{% for script in scripts|reverse %}
|
||||
<script src="{{ script }}" charset="utf-8" type="text/javascript"></script>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% for script in scripts|default([]) %}
|
||||
<script src="{{ script }}" charset="utf-8" type="text/javascript"></script>
|
||||
{% endfor %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -6,9 +6,6 @@
|
|||
{% set header_minimal = true %}
|
||||
{% set footer_copy_start = '2013' %}
|
||||
|
||||
{% set styles = styles|default([])|merge([ globals.assetsInfo.get('whois.css') ]) %}
|
||||
{% set scripts = scripts|default([])|merge([ globals.assetsInfo.get('whois.js') ]) %}
|
||||
|
||||
{% block container %}
|
||||
<div class="whois-container">
|
||||
<form class="whois-lookup-form" method="get" action="">
|
||||
|
|
Loading…
Reference in a new issue