Skip to content

Instantly share code, notes, and snippets.

@1000heads-luke
Created December 20, 2022 01:54
Show Gist options
  • Save 1000heads-luke/9d3f2170c5f0a326e570783603c9fdd2 to your computer and use it in GitHub Desktop.
Save 1000heads-luke/9d3f2170c5f0a326e570783603c9fdd2 to your computer and use it in GitHub Desktop.
javascript: (function() {
function callback() {
function l() {
$("strong.headings_detector").remove();
if( !$('style#headings_detector') ){
$('head').append(
'<style id="headings_detector">'+
'.headings_detector {'+
'color:#FFF;font-weight:bold;font-size:small;background:yellow;'+
'}'+
'</style>'
);
}
var count = 0;
for( var i = 1 ; i<7 ; i++ ){
count += $('h'+i)
.prepend('<i class="headings_detector--before">&lt;h'+i+'&gt;</i>')
.append('<i class="headings_detector--after">&lt;/h'+i+'&gt;</i>')
.length;
count += $('[role=heading][aria-level='+i+']')
.prepend('<i class="headings_detector--before">&lt;[role=heading][aria-level='+i+']&gt;</i>')
.append('<i class="headings_detector--after">&lt;/[role=heading][aria-level='+i+']&gt;</i>')
.length;
}
if( !count ) {
$('body').prepend('<strong style="color:black;font-weight:bold;font-family:sans-serif;font-size:small;background-color:yellow;margin:0 2px; padding:2px;" id="failure" role="status"></strong>');
$('#failure').html('No Headings Found on Page: ' + document.title);
setTimeout(function(){ $('#failure').remove(); }, 6000);
} else {
$('body').append('<div id="success" role="alert" style="position:absolute; width:0; height:0; clip: rect(0,0,0,0);"></div>');
$('#success').html('Success! Headings Found on Page: ' + document.title);
setTimeout(function(){ $('#success').remove(); }, 3000);
}
$("script[src$='headings.js']").remove();
s.remove();
}
l()
}
var s = document.createElement("script");
s.addEventListener ? s.addEventListener("load", callback, !1) : s.readyState && (s.onreadystatechange = callback), s.src = "https://code.jquery.com/jquery-3.6.2.slim.min.js", document.body.appendChild(s);
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment