由於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,''));