'use strict'; window.addEventListener('load', function (e) { var tokenFields = document.getElementsByName('as_token'); if (tokenFields.length === 0) { console.error('No tokenfield found!') } var runTests = function () { var i; // test for loaded images (bots don't download them) var images = document.querySelectorAll('img'); var notLoadedCount = 0; for (i = 0; i < images.length; i++) { if (!images[i].width || !images[i].height) { notLoadedCount++; } } if (images.length && notLoadedCount / images.length > 0.5) { return false; } // TODO other tests? return true; }; if (runTests()) { for (var i = 0; i < tokenFields.length; i++) { tokenFields[i].value = '/XM89fe2zVxF+Ahjwx5rfw=='; } } else { console.error('Not a human'); } });