由于URL已知,因此很简单:
JSON.parse(
document.querySelector("script[src='https://apis.google.com/js/plusone.js']")
.innerHTML.replace(/^\s+|\s+$/g,'')
);
也就是说,正如Alohci在评论中指出的那样,页面上的最后一个脚本将是脚本运行时加载的最后一个脚本,因为(除非另有说明)脚本是阻塞的。 因此,这将工作:
var scripts = document.getElementsByTagName('script');
var data = JSON.parse(scripts[scripts.length-1].innerHTML.replace(/^\s+|\s+$/g,''));