在网页加载时替换JS文件

  1. Download and install Fiddler if you are on windows.
  2. Enable it to catch http traffic [IE/Chrome does it by default, Firefox - enable it through the add on it installs]
  3. Load up the page in question.
  4. Find the file you want to replace in the http traffic list on the left and click on it.
  5. On the right there is an AutoResponder tab. click on it.
  6. Click on the checkbox to "enable automatic responses"
  7. Click Add.. button
  8. The 2nd dropdown on right, choose the option that says "find a file"
  9. Locate the file in the dialog and click save
  10. Repeat steps 4-9 until you replace all the files you want to replace
  11. Refresh the browser window and your new js files are running
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
替换网页内的图片,你需要在 Android 的 WebView 中使用 WebViewClient 的 onPageFinished() 方法来实现。具体步骤如下: 1. 创建一个类继承自 WebViewClient,并重写其中的 onPageFinished() 方法。 2. 在 onPageFinished() 方法中,获取 WebView 中的 HTML 内容,然后使用正则表达式来匹配网页中的图片标签。 3. 对于每个匹配到的图片标签,使用 Android 的本地文件系统读取对应的本地图片文件,然后将其转换为 Base64 编码的字符串。 4. 使用 JavaScript 来替换网页中的图片标签,将其替换为包含 Base64 编码字符串的 data URI。 下面是示例代码: ```java public class MyWebViewClient extends WebViewClient { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); String javascript = "javascript:(function() {" + "var imgs = document.getElementsByTagName('img');" + "for (var i = 0; i < imgs.length; i++) {" + "var img = imgs[i];" + "var url = img.src;" + "if (url.startsWith('http')) {" + "var xhr = new XMLHttpRequest();" + "xhr.open('GET', url, true);" + "xhr.responseType = 'arraybuffer';" + "xhr.onload = function() {" + "if (xhr.status === 200) {" + "var uInt8Array = new Uint8Array(xhr.response);" + "var i = uInt8Array.length;" + "var binaryString = new Array(i);" + "while (i--) {" + "binaryString[i] = String.fromCharCode(uInt8Array[i]);" + "}" + "var data = binaryString.join('');" + "var base64 = window.btoa(data);" + "img.src = 'data:image/png;base64,' + base64;" + "}" + "};" + "xhr.send();" + "}" + "}" + "})()"; view.loadUrl(javascript); } } ``` 这段代码会在 WebView 加载网页完成后,使用 JavaScript 来替换所有 HTTP 开头的图片链接为对应的 Base64 编码字符串。你需要将图片的本地路径替换为对应的路径。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值