如何替换网站的javascript功能?

问题描述 投票:0回答:1

我正在尝试修改网站的JavaScript功能:

function example(pExample){
  ...
}

到:

function example(pExample){
  ...
  console.log(pExample)
}

我已经尝试在加载Chrome开发者工具的“源代码”选项卡中更改上述功能,但是更改似乎无效。我已经考虑过使用某种扩展名用自己的脚本替换脚本的源代码,但是该脚本会在每次重新加载页面时更改其名称,因此我认为这是不可能的。有什么想法吗?

javascript google-chrome-devtools reverse-engineering
1个回答
0
投票
  1. 参考原件。
  2. 创建您自己的功能。
  3. 确保它叫原始文件。
  4. 用您自己的原稿替换。

function example(x) {
  console.log("-->calling the original function");
  
  return x + 1;
}

///////

// 1. take the reference
let originalReference = example;

// 2. make the function
function custom() {
  console.log("->custom function called");
  // 3. call the original one
  let originalResult = originalReference.apply(this, arguments);
  
  console.log("->original was called with:", arguments, "\nand produced:", originalResult);
  
  return originalResult;
}

// 4. replace the original

example = custom;

console.log(example(4));
© www.soinside.com 2019 - 2024. All rights reserved.