简体   繁体   English

可以在 IE11 中运行用户脚本

[英]Possible to run userscript in IE11

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?有没有办法在 IE11 中使用这个脚本? Or is there any plugins for IE11 that does what Tampermonkey/Greasemonkey does?或者是否有任何适用于 IE11 的插件可以执行 Tampermonkey/Greasemonkey 的功能?

TrixIE WPF4.5 claims to emulate Greasemonkey on IE11. TrixIE WPF4.5声称可以在 IE11 上模拟 Greasemonkey。

Unfortunately, the original Trixie and IE7Pro stopped working around IE8-ish.不幸的是, 最初的TrixieIE7Pro停止围绕 IE8-ish 工作。

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 提供了类似的功能。

Fiddler supports modifying the response of http requests. Fiddler 支持修改 http 请求的响应。
We can use this feature to load userscript in any browser, include IE8.我们可以使用此功能在任何浏览器中加载用户脚本,包括 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: 修改请求或响应

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:当当前窗口位于您希望脚本运行的域中时,在 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:创建书签并将 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.如果用户清除浏览器缓存,则需要重新安装。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM