javascript 可以在 IE11 中运行用户脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25059256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 03:49:54  来源:igfitidea点击:

Possible to run userscript in IE11

javascriptinternet-exploreruserscripts

提问by boston

I have a custom userscript that I'm running in Chrome and Firefox using Tampermonkey/Greasemonkey.

我有一个使用 Tampermonkey/Greasemonkey 在 Chrome 和 Firefox 中运行的自定义用户脚本。

Is there any way of using this script in IE11? Or is there any plugins for IE11 that does what Tampermonkey/Greasemonkey does?

有没有办法在 IE11 中使用这个脚本?或者是否有任何适用于 IE11 的插件可以执行 Tampermonkey/Greasemonkey 的功能?

回答by DasBeasto

TrixIE WPF4.5claims to emulate Greasemonkey on IE11.

TrixIE WPF4.5声称可以在 IE11 上模拟 Greasemonkey。

Unfortunately, the original Trixieand IE7Prostopped working around IE8-ish.

不幸的是,最初的TrixieIE7Pro停止围绕 IE8-ish 工作。

回答by Joeppie

A simple Google Search (I searched "greasemonkey for IE") yields various alternatives available for other browsers:

一个简单的谷歌搜索(我搜索了“greasemonkey for IE”)会产生可用于其他浏览器的各种替代方案:

http://en.wikipedia.org/wiki/Greasemonkey#Equivalents_for_other_browsers

http://en.wikipedia.org/wiki/Greasemonkey#Equivalents_for_other_browsers

For Internet Explorer, similar functionality is offered by IE7Pro,[19] Sleipnir,[20] and iMacros.

对于 Internet Explorer,IE7Pro、[19] Sleipnir、[20] 和 iMacros 提供了类似的功能。

回答by ipcjs

Fiddler supports modifying the response of http requests.
We can use this feature to load userscript in any browser, include IE8.

Fiddler 支持修改 http 请求的响应。
我们可以使用此功能在任何浏览器中加载用户脚本,包括 IE8。

This is an example:

这是一个例子:

static function OnBeforeResponse(oSession: Session) {
    if (m_Hide304s && oSession.responseCode == 304) {
        oSession["ui-hide"] = "true";
    }
    // match url
    if (oSession.fullUrl == "http://apply.ccopyright.com.cn/goadatadic/getR11List.do") {
        oSession.utilDecodeResponse();
        var script = System.IO.File.ReadAllText("C:\GitHub\@selpic\P660_printer\Printer\scripts\form-save-load.js")
        oSession.utilReplaceOnceInResponse("</body>", "<script>"+script+"</script></body>", true);
    }
}

doc: Modifying a Request or Response

doc:修改请求或响应

回答by Jingyu Lei

I use localStorage to make it work, which is supported by IE8 or later.

我使用 localStorage 使其工作,IE8 或更高版本支持。

Steps:

脚步:

  1. Run the following code in IE's developer tool when the current window is in the domain where you want the script to run in:
  1. 当当前窗口位于您希望脚本运行的域中时,在 IE 的开发人员工具中运行以下代码:
var scriptName = 'Hello world';
function scriptBody(){
//---userscript starts--->

document.body.innerHTML = '<h1>Hello world!</h1>';

//---userscript ends--->
}
var script = scriptBody.toString()
  .split('//---userscript starts--->')[1]
  .split('//---userscript ends--->')[0];
localStorage.setItem(scriptName, script);
  1. Create a bookmark and modify the URL into:
  1. 创建书签并将 URL 修改为:
javascript:(function(){eval(localStorage.getItem('Hello world'));})()

Advantages:

好处:

  • No additional plugin needed.
  • Almost no script text length limit.
  • 不需要额外的插件。
  • 几乎没有脚本文本长度限制。

Disadvantages:

缺点:

  • Need a user to click on a bookmark to run the script.
  • Need a reinstall if a user clears the browser cache.
  • 需要用户点击书签来运行脚本。
  • 如果用户清除浏览器缓存,则需要重新安装。

回答by D_Pavel

Just open Developer tools(press F12) and paste your script to Console, and then run it (Ctrl + Enter).

只需打开开发人员工具(按 F12)并将您的脚本粘贴到Console,然后运行它(Ctrl + Enter)。