debuger for Olena
debuger for Olena
by Boba Poshtar
CSS
a:not([target]) { font-size: 32px !important; line-height: 40px; font-weight: bold !important; color: red !important;}
body { background: red;}
body.ok { background: white;}
body.err { background: orange;}
JavaScript
/* debug */
(function(){
function bodyAddClass(c){ document.body.classList.add(c); }
function bodyAddMsg(s){ document.body.innerHTML = s + document.body.innerHTML; }
/* крапка в кінці заголовків */
let ttl = ['title', 'h1', 'h2', 'h3', 'h4'];
ttl.forEach(function(tag){
let n = 0;
document.querySelectorAll(tag).forEach(function(e){
let t = e.innerText;
if (t[t.length - 1] === '.') { n++; }
});
if (n) {
bodyAddClass('err');
bodyAddMsg('<p>Dot in ' + tag + '.</p>');
}
});
/* відсутність h1 чи їх надмірна кількість */
let h1 = document.querySelectorAll('h1');
if (h1.length !== 1) {
bodyAddClass('err');
bodyAddMsg('<p>H1 count: ' + h1.length + '</p>');
}
/* кількість скриптів */
let scr = document.querySelectorAll('script');
bodyAddMsg('<p>Scripts: ' + scr.length + '</p>');
/* відсутність meta viewport */
let meta = document.querySelectorAll('meta');
let metavp = 0;
meta.forEach(function(m){ if (m.name === 'viewport') { metavp++; } });
if (metavp === 0) {
bodyAddClass('err');
bodyAddMsg('<p>Meta viewport is absent.</p>');
}
/* наявність додаткових стилів */
let st = document.querySelectorAll('style');
if (st.length) {
bodyAddMsg('<p>Tag <style> present here.</p>');
}
/* якщо немає помилок - то все ок */
if (!document.body.classList.contains('err')) {
bodyAddClass('ok');
}
})();