0

I want to edit a function of a website after the page is loaded.. When the page is loaded it contains a function like this

function PosttempKey(){

var token_dt = d.getHours() +''+ d.getMinutes() +''+ d.getSeconds();
var random = Math.floor(Math.random() * 1000) + 1;
var temp_key = token_dt + '' + random;
$.post( contextPath + "/doServlet",  {key : "send.PostKey", TEMPORARY_KEY:temp_key,  USER_EMAIL:user_email }, function(data, status) {
    console.log(data); }

As you can see the function do not return any value, but just logs it.

What I want to do is to add some code inside the function PosttempKey like return data; so that it will return data after it executes.

we can edit the html content using document.queryselector(.class).value = "abc";

But is there a way I can modify the Script(function) as well ?

Please help ~

shane
  • 39
  • 7
  • No, there isn't, you've to re-write the entire function if you want to change it. – Teemu Apr 13 '22 at 15:27
  • Thanks for the reply, I only want the data from the console.log-- Is there a way I can get it in a variable, Outside the function? – shane Apr 13 '22 at 15:30
  • 1
    $.post is async, so just putting return data isn't going to work. See https://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-asynchronous-call – James Apr 13 '22 at 15:31
  • So is there anyway I can capture console.log? – shane Apr 13 '22 at 15:52

0 Answers0