スクリプトタグにidを追加してから、idによってDOMからフェッチできます。
document.write('<script type="text/javascript" src="/plugin.js" id="myscript"></script>');
if (document.getElementById('myscript')) {
console.info('success');
} else {
console.error('failure');
}
または、何も変更したくない場合は、ページ上のすべてのスクリプトでそれを見つけようとすることができます。
document.write('<script type="text/javascript" src="/plugin.js"></script>');
(function () {
var scripts = document.getElementsByTagName('script'),
l = scripts.length - 1;
// If you'll check that just after document.write then it should be last script
// in the other case you would need to check all scripts.
// From src I'm removing domain - at least Safari is returning full URL here
if (scripts.length && scripts[l - 1].src && scripts[l - 1].src.replace(/^([a-z]+:\/\/[^\/]*)/i, '') == '/plugin.js') {
console.info('success');
} else {
console.error('failure');
}
}());