javascript - Function runs on parent window instead of child -
this runs bookmarklet.
the creation of windows, extracting of values, , writing them window "log" works perfect.
i want save contents of "log" window scrypt.txt, contents of parent window saved instead. did wrong?
javascript: setinterval(logging,60000); w1 = window.open("https://scrypt.cc/index.php"); log = window.open(""); function logging(){ if(w1.document.body.innerhtml == 'server busy. please try again later.'){ w1.location.href = 'https://scrypt.cc/index.php'; console.log("busy"); }else{ console.log("ok"); log.document.body.innerhtml = ''; var re=/var\s*dayprofitperkhs\s*=\s*([0-9\.]+)\s/gi; var matches=re.exec(w1.document.body.innerhtml); log.document.write(regexp.$1 + "<p></p>"); log.document.write(w1.$('#t9_2').val() + "<p></p>"); log.settimeout(save,1000); w1.location.href = 'https://scrypt.cc/index.php'; } } function save() { = log.document.createelement('a'); a.href = log.location.href; a.download = 'scrypt.txt'; log.document.body.appendchild(a); a.click(); a.parentnode.removechild(a); } edit: saving *.html, a.href works perfectly:
a.href = 'data:text/html;base64,' + btoa(log.document.body.outerhtml); a.download = 'values.html';
your save() function using document of main window. if want run in log() context, need use log.document , log.location.
function save() { = log.document.createelement('a'); a.href = log.location.href; a.download = 'scrypt.txt'; log.document.body.appendchild(a); a.click(); a.parentnode.removechild(a); } this guess, try moving saving code script tag in log window this:
setinterval(logging, 60000); var w1 = window.open("https://scrypt.cc/index.php"); var log = window.open(""); function logging() { if (w1.document.body.innerhtml == 'server busy. please try again later.') { w1.location.href = 'https://scrypt.cc/index.php'; console.log("busy"); } else { console.log("ok"); log.document.body.innerhtml = ''; var re = /var\s*dayprofitperkhs\s*=\s*([0-9\.]+)\s/gi; var matches = re.exec(w1.document.body.innerhtml); log.document.write(regexp.$1 + "<p></p>"); log.document.write(w1.$('#t9_2').val() + "<p></p>"); // insert script tag create save link , click var sc = "<scr" + "ipt>"; sc += "function save() {"; sc += "var = document.createelement('a');"; sc += "a.href = location.href;"; sc += "a.download = 'scrypt.txt';"; sc += "document.body.appendchild(a);"; sc += "a.click();"; sc += "a.parentnode.removechild(a);"; sc += "}"; sc += "settimeout(save, 1000);"; sc += "</scr" + "ipt>"; log.document.write(sc); w1.location.href = 'https://scrypt.cc/index.php'; } }
Comments
Post a Comment