Possible to run userscript in IE11

2020-03-09 09:07发布

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

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

5条回答
▲ chillily
2楼-- · 2020-03-09 09:13

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

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:
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:
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.
查看更多
Summer. ? 凉城
3楼-- · 2020-03-09 09:23

A simple Google Search (I searched "greasemonkey for IE") yields various alternatives available 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.

查看更多
乱世女痞
4楼-- · 2020-03-09 09:25

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

查看更多
Rolldiameter
5楼-- · 2020-03-09 09:30

Fiddler supports modifying the response of http requests.
We can use this feature to load userscript in any browser, include 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

查看更多
神经病院院长
6楼-- · 2020-03-09 09:36

TrixIE WPF4.5 claims to emulate Greasemonkey on IE11.

Unfortunately, the original Trixie and IE7Pro stopped working around IE8-ish.

查看更多
登录 后发表回答