批处理之家's Archiver

powerbat 发表于 2011-11-12 02:44

[分享]添加IE工具栏按钮及解除网页常见限制

[code]
'On Error Resume Next

IEbarRegPath = "HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Extensions\"

'例1
Guid = "{8287321c-032b-451d-b030-8fd617629efb}" 'Guid随便写,只要不和别的重名就可以了
'Guid = CreateObject("ScriptLet.TypeLib").Guid '可以用这个对象得到一个Guid
RegPath = IEbarRegPath & Guid & "\" '按钮的注册表位置
ButtonText = "执行JS" '按钮名称
MenuText = "执行JS" '“工具”菜单中显示文字
MenuStatusBar = "执行JS" '鼠标放在“工具”菜单相应条目上时状态栏显示文字
ButtonType = "Script" '按钮类型,有4种:Exec(可执行文件)、Script(脚本)、ClsidExtension(COM对象)、BandCLSID(浏览器栏)
FilePath = "C:\js.htm" '脚本文件路径
Icon = "wscript.exe,1" '默认显示图标
HotIcon = "wscript.exe,3" '鼠标放上去显示图标
DefaultShow = "Yes" '按钮显示与否
Call AddIEbar(RegPath, ButtonText, MenuText, MenuStatusBar, ButtonType, FilePath, Icon, HotIcon, DefaultShow)

'例2
Guid = "{8287321c-032b-451d-b030-8fd617629efc}" 'Guid随便写,只要不和别的重名就可以了
'Guid = CreateObject("ScriptLet.TypeLib").Guid '可以用这个对象得到一个Guid
RegPath = IEbarRegPath & Guid & "\" '按钮的注册表位置
ButtonText = "Explorer" '按钮名称
MenuText = "资源管理器" '“工具”菜单中显示文字
MenuStatusBar = "资源管理器" '鼠标放在按钮上时状态栏显示文字
ButtonType = "Exec" '按钮类型,有4种:Exec(可执行文件)、Script(脚本)、ClsidExtension(COM对象)、BandCLSID(浏览器栏)
FilePath = "C:\Windows\Explorer.exe" '可执行文件路径,可以是本地文件,也可以是网页地址
Icon = "C:\Windows\Explorer.exe,0" '默认显示图标
HotIcon = "C:\Windows\Explorer.exe,0" '鼠标放上去显示图标
DefaultShow = "Yes" '按钮显示与否
Call AddIEbar(RegPath, ButtonText, MenuText, MenuStatusBar, ButtonType, FilePath, Icon, HotIcon, DefaultShow)

'设置了显示后,在“工具”菜单中可以看到相应条目,但系统还不会显示在工具栏上,得手动添加上去

WScript.Echo "OK, 操作完成"

'添加到IE工具栏按钮函数
Function AddIEbar(RegPath, ButtonText, MenuText, MenuStatusBar, ButtonType, FilePath, Icon, HotIcon, DefaultShow)
    dim clsid, ws
    Select Case 0
    Case StrComp(ButtonType,"Exec",1), StrComp(ButtonType,"Script",1), StrComp(ButtonType,"ClsidExtension",1)
        clsid = "{1FBA04EE-3024-11D2-8F1F-0000F87ABD16}"
    Case StrComp(ButtonType,"BandCLSID",1)
        clsid = "{E0DD6CAB-2D10-11D2-8F1A-0000F87ABD16}"
    Case Else
        'Err.Raise 10001, "Function 'AddIEbar'", "Argument 'ButtonType' error"
        AddIEbar = false
        exit function
    End Select
    Set ws = WScript.CreateObject("WScript.Shell")
    ws.RegWrite RegPath & "CLSID", clsid, "REG_SZ"
    ws.RegWrite RegPath & "ButtonText", ButtonText, "REG_SZ"
    ws.RegWrite RegPath & "MenuText", MenuText, "REG_SZ"
    ws.RegWrite RegPath & "MenuStatusBar", MenuStatusBar, "REG_SZ"
    ws.RegWrite RegPath & ButtonType, FilePath, "REG_SZ"
    ws.RegWrite RegPath & "Icon", Icon, "REG_SZ"
    ws.RegWrite RegPath & "HotIcon", HotIcon, "REG_SZ"
    ws.RegWrite RegPath & "Default Visible", DefaultShow, "REG_SZ"
    set ws = nothing
AddIEbar = true
End Function
[/code]C:\js.htm[code]
<script language="javascript">
var win = window.external.menuArguments;
var doc = win.document;

function enableMouse()
{
    if (event != null)
    {
        event.returnValue = true;
        event.cancelBubble = false;
    }
    return true;
}
function doEnableMouse(obj)
{
    obj.onmousedown = enableMouse;
    obj.onmouseup = enableMouse;
    obj.onmousemove = enableMouse;
    obj.oncontextmenu = enableMouse;
    obj.onselectstart = enableMouse;
    obj.ondragstart = enableMouse;
    obj.onbeforecopy = enableMouse;
    obj.oncopy = enableMouse;
    obj.onselect = enableMouse;
}
function doDocument(doc)
{
try
{
    doEnableMouse(doc);
    doEnableMouse(doc.body);
    var frs = doc.frames;
    if (frs != null && frs.length>0)
    {
        for (var i=0; i < frs.length; i++)
        {
            doDocument(frs[i].document);
        }
    }
} catch(e) {}
}

//解除鼠标右键限制
doDocument(doc);

//防止google搜索结果重定向
if (win.location.href.search(/http:\/\/www\.google\.com\.hk/i) > -1)
{
    var el = doc.getElementById("RemoveGoogleRedirect");
    if (!el)
    {
        var sc = doc.createElement("script");
        sc.id = "RemoveGoogleRedirect";
        sc.text = "function rwt(){return true;}";
        doc.body.appendChild(sc);
    }
}


var div = "<div id='zqz_tool' style='background-color:#d5d8de; background-image: url(about:blank); background-repeat: no-repeat; border-top: 1px solid #c0c3c9; bottom:0; left:0; width:100%; height:50px; line-height: 15px; padding: 0; margin: 0; font-size: 10px; text-align: center; overflow:visible; z-index:99999; position:fixed; /* for ie6 */ _position:absolute; ";
var s = doc.documentElement.clientHeight ? true : false;
if (s) div += "_top: expression(documentElement.scrollTop + documentElement.clientHeight - this.offsetHeight); ";
else div += "_top: expression(body.scrollTop + body.clientHeight - this.offsetHeight); ";
div += "'>";
div += "<div style='cursor: hand; border-bottom: 1px solid #a0a3a9; color: blue; height:10px; line-height: 10px; padding: 0; margin: 0; ' onclick=(function(o){if(o.parentNode.style.height!='10px'){o.parentNode.style.height='10px';o.parentNode.style.overflow='hidden';o.innerText='▲';}else{o.parentNode.style.height='50px';o.parentNode.style.overflow='visible';o.innerText='▼';}})(this)>▼</div>";
div +="<textarea id='zqz_cmd' rows=2 cols=80>new ActiveXObject('WScript.Shell').Run('calc');</textarea><button onclick='eval(zqz_cmd.innerText)'>eval</button>";
div +="<input id='zqz_external' type='checkbox' title='选中后再次点击工具栏按钮执行此代码' />外部";
div += '</div>';
doc.getElementById('zqz_tool') || doc.body.insertAdjacentHTML("beforeEnd", div);

s = doc.getElementById('zqz_external');
s && s.checked && eval( doc.getElementById('zqz_cmd').value );

//new ActiveXObject('WScript.Shell').Run('calc');

//eval(clipboardData.getData('text'));

</script>
[/code]

broly 发表于 2011-11-12 22:22

网页错误详细信息

用户代理: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; QQDownload 702; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)
时间戳: Sat, 12 Nov 2011 14:21:08 UTC


消息: 'win.document' 为空或不是对象
行: 3
字符: 1
代码: 0
URI: file:///C:/Users/Broly/Desktop/js.htm

JS.HTM有点错误,IE8

lazdkiy 发表于 2011-11-17 09:45

那天弄电脑的用for语句和regsvr32重新注册了系统所有组件,我没看清,请问如何实现?

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.