Created
November 27, 2017 15:41
-
-
Save kardeiz/9183bbf0701f44d0feeb61c7a67725aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Utils = { | |
waitForElem: function(selector, cb) { | |
var elem = $(selector); | |
if (elem.length) { | |
cb(); | |
} else { | |
setTimeout(function() { | |
Utils.waitForElem(selector, cb); | |
}, 100); | |
} | |
}, | |
modal: function(id, header, body) { | |
var modal = $('<div class="modal fade" role="dialog"/>').attr('id', id); | |
var dialog = $('<div class="modal-dialog"/>').appendTo(modal); | |
var content = $('<div class="modal-content"/>').appendTo(dialog); | |
$('<div class="modal-header"/>') | |
.append('<button type="button" class="close" data-dismiss="modal">×</button>') | |
.append('<p class="modal-title">' + header + '</p>') | |
.appendTo(content); | |
$('<div class="modal-body">' + body + '</div>').appendTo(content); | |
return modal.appendTo('body'); | |
}, | |
clickAndWait: function(selector, time, cb) { | |
setTimeout(function() { | |
$(selector).click(); | |
setTimeout(cb, time); | |
}, time); | |
} | |
} | |
function imageTable() { | |
var table = $('<table style="border: 1px solid gray;"><tr><th style="border: 1px solid gray; vertical-align: middle;">SRC</th><th style="border: 1px solid gray; vertical-align: middle;">ALT</th></tr></table>'); | |
$('img').each(function() { | |
var that = $(this); | |
$('<tr/>') | |
.append('<td style="border: 1px solid gray; vertical-align: middle;">' + that.attr('src') + '</td>') | |
.append('<td style="border: 1px solid gray; vertical-align: middle;">' + that.attr('alt') + '</td>') | |
.appendTo(table); | |
}); | |
return table; | |
} | |
function reportErrors() { | |
$('body').on('click', 'a#confirm-copy', function() { | |
clipboard.write(Utils.localClipboardData); | |
}); | |
$('#tota11y-toolbar .tota11y-toolbar-toggle').click(); | |
var outer = $('<div/>'); | |
var inner = $('<div/>').appendTo(outer); | |
inner.append('<h2>' + window.location.href + '</h2>'); | |
function appendCurrentErrors() { | |
$('.tota11y-info ul.tota11y-info-errors').each(function() { | |
$(this).children('li').each(function() { | |
var that = $(this); | |
that.find('label:contains("Preview")').replaceWith('<br/>'); | |
inner.append(that.html()); | |
}) | |
}); | |
} | |
Utils.clickAndWait('.tota11y-plugin-title:contains("Headings")', 100, function() { | |
appendCurrentErrors(); | |
Utils.clickAndWait('.tota11y-plugin-title:contains("Contrast")', 100, function() { | |
appendCurrentErrors(); | |
Utils.clickAndWait('.tota11y-plugin-title:contains("Link text")', 100, function() { | |
appendCurrentErrors(); | |
inner.append('<h3>Images</h3>') | |
inner.append(imageTable()); | |
var data = new clipboard.DT(); | |
data.setData("text/html", outer.html()); | |
Utils.localClipboardData = data; | |
Utils.clickAndWait('.tota11y-plugin-title:contains("Link text")', 100, function() { | |
Utils.clickAndWait('#tota11y-toolbar .tota11y-toolbar-toggle', 100, function() { | |
var modal = Utils.modal('copy-to-clipboard', 'Copy errors to clipboard?', '<a class="btn btn-success" href="#" id="confirm-copy">Yes</a>'); | |
modal.modal('show'); | |
}); | |
}); | |
}); | |
}); | |
}); | |
} | |
function main() { | |
try { | |
// var innerBody = $('#body-content'); | |
var innerBody = $('.s-la-faq-answer'); | |
// var innerBody = $('<div/>') | |
// .append($('#s-lg-tabs-container')) | |
// .append($('#s-lg-guide-main')); | |
if (innerBody.length) { | |
$('body').html(innerBody); | |
} | |
} catch(e) { | |
console.log(e); | |
} | |
var tota11yPromise = $.getScript('//khan.github.io/tota11y/tota11y/build/tota11y.min.js'); | |
var clipboardPromise = $.getScript('//cdn.rawgit.com/lgarron/clipboard-polyfill/master/build/clipboard-polyfill.js'); | |
var bootstrapPromise = $.when(); | |
if (typeof($.fn.modal) != "function") { | |
bootstrapPromise = $.getScript('//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js'); | |
} | |
$.when(tota11yPromise, clipboardPromise, bootstrapPromise).done(function(tota11y, clipboard, bootstrap) { | |
Utils.waitForElem('#tota11y-toolbar .tota11y-toolbar-toggle', reportErrors); | |
}); | |
} | |
if (typeof jQuery=='undefined') { | |
var headTag = document.getElementsByTagName("head")[0]; | |
var jqTag = document.createElement('script'); | |
jqTag.type = 'text/javascript'; | |
jqTag.src = '//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js'; | |
jqTag.onload = main; | |
headTag.appendChild(jqTag); | |
} else { | |
main(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment