这是一个仅限IE的网站,我想与其他浏览器一起使用,例如Firefox:
https://golestan.sbu.ac.ir/Forms/AuthenticateUser/login.htm
我被迫将这个网站用于我的大学。它使用Msxml2.XMLHTTP
,这是一个仅限IE的功能。我尝试将其转换为XMLHttpRequest
,因此仅适用于Firefox。这是我创建的Greasemonkey脚本。现在它没有给出错误,但它不起作用。
所有功能都来自网站的原始脚本,但它们已被更改,以便它们与XMLHttpRequest
一起使用。
如果登录脚本出现,我很好。我该如何调试这个javascript?
// ==UserScript==
// @name Golestan Login
// @namespace sbu.ac.ir
// @include https://golestan.sbu.ac.ir/Forms/AuthenticateUser/login.htm
// @version 1
// @grant none
// ==/UserScript==
var isInternetExplorer = 0;
function check(){
var x;
if (window.XMLHttpRequest) {
x = new XMLHttpRequest();
} else {
try {
x = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
x = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
x = false;
}
}
}
x.open("HEAD",document.location,true);
x.send();
var sd=new Date(x.getResponseHeader('Last-Modified'));
var cd=new Date(document.lastModified);
if(sd-cd>3660000){
document.cookie = "reloading=1";
window.location.reload(true);
return false;
}
return true;
}
function a(){
for (k = 0; k < nall; k++) {
td = document.createElement('TD');
td.className = 'e';
Pr.appendChild(td);
}
if (!check()) {
//window.open("/_Templates/howtoclearcache.htm","_blank");
//top.close();
return;
}
var aCookie = document.cookie.split("; ");
var cook=0;
for (var i=0; i < aCookie.length; i++)
{
var aCrumb = aCookie[i].split("=");
if ("reloading" == aCrumb[0]) {
cook=unescape(aCrumb[1]);
break;
}
}
var ind=0;
for( i=0;i<all.length;i=i+2){
if(all[i+1]==1)
for(j=0;j<4;j++){
var r;
if (window.XMLHttpRequest) {
r = new XMLHttpRequest();
} else {
try {
r = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
r = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
r = false;
}
}
}
r.open("GET", all[i]+imstat[j]+".gif", true);
if(cook==1) r.setRequestHeader('If-Modified-Since','Sat,01 Jan 2000 00:00:00 GMT');
getobj(r,ind++);
}
else{
var r;
if (window.XMLHttpRequest) {
r = new XMLHttpRequest();
} else {
try {
r = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
r = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
r = false;
}
}
} r.open("GET", all[i], true);
if(cook==1) r.setRequestHeader('If-Modified-Since','Sat,01 Jan 2000 00:00:00 GMT');
getobj(r,ind++);
}
}
document.cookie = "reloading=0; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}
function main_DoFSCommand(command, args) {
var mainObj = document.all.main;
//
// Place your code here.
//
document.getElementById("rdir").style.visibility = "hidden";
if(command != "showmenu")
if(command == "Animation_Complete")
{
var x = 0;
var y = 0;
x = main.clientHeight/2 - 300;
y = main.clientWidth/2 - 400;
document.getElementById("iframeNews").style.top = x + 120;
document.getElementById("iframeNews").style.left = y + 264;
modifySrc();
document.getElementById("iframeNews").style.visibility = "visible";
}
else
{
if(command == "Enter")
{
bal('main');
}
else if(command == "Education")
{
bal('test');
}
else
document.getElementById("iframeNews").style.visibility = "hidden";
}
}
// http://stackoverflow.com/questions/21271997
addJS_Node (check);
addJS_Node (a);
addJS_Node (main_DoFSCommand);
isInternetExplorer=true;
function addJS_Node (text, s_URL, funcToRun, runOnLoad) {
var D = document;
var scriptNode = D.createElement ('script');
if (runOnLoad) {
scriptNode.addEventListener ("load", runOnLoad, false);
}
scriptNode.type = "text/javascript";
if (text) scriptNode.textContent = text;
if (s_URL) scriptNode.src = s_URL;
if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
targ.appendChild (scriptNode);
}
我认为这项工作值得做,因为数百名大学生用户受到了影响。
更新:我们可以进一步升级,并达到main.htm
。所以,我为这个页面编写了另一个脚本。但是,最后我得到ReferenceError: element is not defined[Learn More]
。
// ==UserScript==
// @name Golestan Main
// @namespace sbu.ac.ir
// @include https://golestan.sbu.ac.ir/Forms/AuthenticateUser/main.htm
// @version 1
// @grant none
// ==/UserScript==
// Microsoft WebService Behavior (Predecessor of modern AJAX)
// Information: https://web.archive.org/web/20060101200359/https://msdn.microsoft.com/workshop/author/webservice/webservice.asp
// JavaScript version: https://raw.githubusercontent.com/nzakas/professional-javascript/master/edition1/ch17/webservice.htc
// NOTE: You should paste the Javascript code from the above URL here
// end Microsoft WebService Behavior
function l(){
useService("../f0241_process_authexit/authexit.asmx?WSDL", "get");
// useService("authuser.asmx?WSDL", "get");
mt = new MainTit(document,titH);
mt.Maxi();
t = new Tab(document,titH,0,document.body.clientWidth,document.body.clientHeight-titH);
t.maintitle=mt;
OpenFaci('صفحه اصلي','nav.htm?fid=0;1&tck='+'&'+location.search.replace('?',''));
mt.HideGTit();
KeysValues = location.search.split(/[\?&]+/);
for (i = 0; i < KeysValues.length; i++) {
KeyValue = KeysValues[i].split("=");
if (KeyValue[0] == "CSURL") {
CSURL = KeyValue[1];
break;
}
}
}
function ex(ltck,tck,u,si,ft,fid,sess){
var co = createCallOptions();
co.funcName = "ex";
co.async = false;
// callService(function(result){if(result.error){/*alert(result.errorDetail.string);*/}},"ex",ltck,tck,u,si,ft,fid,sess);
callService(co,ltck,tck,u,si,ft,fid,sess);
}
addJS_Node (l);
addJS_Node (ex);
addJS_Node(ErrDetail);
addJS_Node(postError);
addJS_Node(returnError);
addJS_Node(createCallOptions);
addJS_Node(createUseOptions);
addJS_Node(cloneObject);
addJS_Node(ensureVBArray);
addJS_Node(encb64hlp);
addJS_Node(decb64hlp);
addJS_Node(encb64);
addJS_Node(decb64);
addJS_Node(ensureWsdlUrl);
addJS_Node(allocCall);
addJS_Node(fnShowProgress);
addJS_Node(isSimpleType);
addJS_Node(isPrimitive);
addJS_Node(getSdl);
addJS_Node(processService);
addJS_Node(onImportLoaded);
addJS_Node(loadImports);
addJS_Node(invokeNext);
addJS_Node(callNext);
addJS_Node(getAttrib);
addJS_Node(getBaseName);
addJS_Node(getQualifier);
addJS_Node(getNextNsq);
addJS_Node(getUniqueNsq);
addJS_Node(parseSimpleType);
addJS_Node(parseType);
addJS_Node(parseArrayType);
addJS_Node(parseComplexType);
addJS_Node(parseAttrib);
addJS_Node(parseElem);
addJS_Node(parseSoapHeader);
addJS_Node(expBase);
addJS_Node(parseSchemas);
addJS_Node(parseSdl);
addJS_Node(ensureXmlHttp);
addJS_Node(encodeHeader);
addJS_Node(_invoke);
addJS_Node(callService);
addJS_Node(useService);
addJS_Node(getMsg);
addJS_Node(fixupDT);
addJS_Node(encTZ);
addJS_Node(encodePrimitive);
addJS_Node(bldJsAry);
addJS_Node(getNextIndexAry);
addJS_Node(vbArrayToJs);
addJS_Node(encodeArray);
addJS_Node(encodeVar);
addJS_Node(getArySize);
addJS_Node(get1stAryItem);
addJS_Node(getAryItemFromIndex);
addJS_Node(getSchema);
addJS_Node(getArySizeInfo);
addJS_Node(encodeAttrib);
addJS_Node(serPart);
addJS_Node(getWrap);
addJS_Node(encodeArgs);
addJS_Node(returnResult);
addJS_Node(decTZ);
addJS_Node(applyTZ);
addJS_Node(decDate);
addJS_Node(decTime);
addJS_Node(decodePrimitive);
addJS_Node(getAryInfo);
addJS_Node(decodeArray);
addJS_Node(decodeAryItem);
addJS_Node(getAryElem);
addJS_Node(decodeElem);
addJS_Node(decodeType);
addJS_Node(processResult);
addJS_Node(hideProgress);
addJS_Node(getResult);
function addJS_Node (text, s_URL, funcToRun, runOnLoad) {
var D = document;
var scriptNode = D.createElement ('script');
if (runOnLoad) {
scriptNode.addEventListener ("load", runOnLoad, false);
}
scriptNode.type = "text/javascript";
if (text) scriptNode.textContent = text;
if (s_URL) scriptNode.src = s_URL;
if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
targ.appendChild (scriptNode);
}
答案 0 :(得分:3)
在HEAD请求中使用xhr(async:false)
的网站。哪个被弃用
您可以在此处详细了解https://xhr.spec.whatwg.org/
主要陈述是
工作人员之外的同步XMLHttpRequest正在从Web平台中删除,因为它会对最终用户的体验产生不利影响。 (这是一个需要很多年的漫长过程。)当前全局对象是Window对象时,开发人员不能为异步参数传递false。强烈建议用户代理在开发人员工具中警告这种用法,并尝试在发生时抛出InvalidAccessError异常。
因此,请将其更改为true
。
然后使用@run-at document-end
。
我创建了一个为您完成工作的脚本。
我使用的方法,
从网站复制整个脚本代码并进行必要的更改。
在用户脚本中,删除脚本元素并将更改的脚本注入网页。
它将改变页面,如下所示。但似乎所有来自服务器的td元素都是空的。
您可以在此处查看网络转移
这是用户脚本
// ==UserScript==
// @name golestan
// @namespace Sagar V
// @author Sagar V
// @include https://golestan.sbu.ac.ir/Forms/AuthenticateUser/login.htm
// @version 1
// @grant none
// @run-at document-end
// ==/UserScript==
(function(){
var script=document.createElement('script');
script.innerHTML=`c=0;
Ip="/_Images/";ip="/_images/";tp="/_Templates/";scp="/_Scripts/";stp="/_styles/";Stp="/_Styles/";ap="/Forms/AuthenticateUser/";
all =new Array(
'/blank.htm',0,
scp+'printTemplate.htm?tck=r',0,
stp+'comm_butt2.htc',0,
stp+'select.htc',0,
stp+'simplegrid.htc',0,
stp+'validation.htc',0,
stp+'webservice.htc',0,
Stp+'helpStyle.css',0,
Stp+'winlessmovable.htc',0,
stp+'main.css',0,
stp+'MenuStyle.css',0,
stp+'Toolb.htc',0,
stp+'npui.css',0,
ap+'Message.XSLT',0,
ap+'Golestan.htm',0,
ap+'NewsPage.htm',0,
ap+'LoginPage.htm',0,
ap+'TopPage.htm',0,
ap+'main.htm',0,
tp+'Commander.htm',0,
tp+'Message_Page.htm',0,
tp+'help.htm',0,
scp+'Commander.js',0,
scp + 'npobj.js', 0,
scp + 'faci.js', 0,
scp+'Forms1_5.js',0,
scp+'help.js',0,
scp + 'Message.js', 0,
scp + 'npnfwin.js', 0,
'/_scripts/jqnpsrv.js', 0,
'/_scripts/npgrd.js', 0,
scp + 'Forms1_5_npgrid.js', 0,
Ip+'Status_OK.gif',0,
ip+'tabs.png',0,
ip+'ftabs.png',0,
ip+'corner.png',0,
ip+'c1.png',0,
ip+'jqnpgridicons.png',0,
'/Forms/F0202_PROCESS_REP_FILTER/command.htm',0);
nall=0;
for(k=0;k<all.length;k=k+2){
if(all[k+1]==1)nall=nall+4;
else nall++;
}
imstat=new Array('','_clicked','_focus','_disable');
function check(){
var x=new XMLHttpRequest() || new ActiveXObject("MSXML2.XMLHTTP");
x.open("HEAD",document.location,true);
x.send();
var sd=new Date(x.getResponseHeader('Last-Modified'));
var cd=new Date(document.lastModified);
if(sd-cd>3660000){
//alert('با توجه به تغييرات جديد سيستم ، جهت مشاهده کامل صفحات لطفا فايل هاي ذخيره شده در مرورگر خودرا حذف کنيد');
document.cookie = "reloading=1";
window.location.reload(true);
return false;
}
return true;
}
function a(){
for (k = 0; k < nall; k++) {
td = document.createElement('TD');
td.className = 'e';
Pr.appendChild(td);
}
if (!check()) {
//window.open("/_Templates/howtoclearcache.htm","_blank");
//top.close();
return;
}
var aCookie = document.cookie.split("; ");
var cook=0;
for (var i=0; i < aCookie.length; i++)
{
var aCrumb = aCookie[i].split("=");
if ("reloading" == aCrumb[0]) {
cook=unescape(aCrumb[1]);
break;
}
}
var ind=0;
for( i=0;i<all.length;i=i+2){
if(all[i+1]==1)
for(j=0;j<4;j++){
var r=new XMLHttpRequest() || new ActiveXObject("MSXML2.XMLHTTP");
r.open("GET", all[i]+imstat[j]+".gif", true);
if(cook==1) r.setRequestHeader('If-Modified-Since','Sat,01 Jan 2000 00:00:00 GMT');
getobj(r,ind++);
}
else{
var r=new XMLHttpRequest() || new ActiveXObject("MSXML2.XMLHTTP");
r.open("GET", all[i], true);
if(cook==1) r.setRequestHeader('If-Modified-Since','Sat,01 Jan 2000 00:00:00 GMT');
getobj(r,ind++);
}
}
document.cookie = "reloading=0; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}
function getobj(o,ind){
o.onreadystatechange=function(){
if(o.readystate==4){
Pr.cells(c).className="f";
c++;
if(c==nall){
if (location.search){
top.location = "main.htm" + location.search ;
}
else
top.location="main.htm";
}
}
}
o.send();
}`;
//alert(script);
document.getElementsByTagName('script')[0].parentNode.removeChild(document.getElementsByTagName('script')[0]);
document.head.appendChild(script);
})();
直接从Github
安装答案 1 :(得分:3)
可悲的是,为IE构建的JavaScript密集型Web应用程序可能在其中包含更多IE特定的内容,而不仅仅是生成XMLHttpRequests。使用ActiveXObject
生成XMLHttpRequests也意味着JavaScript是为非常旧版本的IE编写的,因为标准的XmlHttpRequest对象自IE7以来就已存在。所以,期待最坏的情况!
针对使new ActiveXObject("MSXML.HttpRequest")
的所有来电都在Firefox中运行的具体问题。您可以在Greasemonkey脚本中使用以下内容:
window.ActiveXObject = function(type) {
switch(type.toUpperCase()) {
case "MSXML2.XMLHTTP":
case "MICROSOFT.XMLHTTP":
return new XMLHttpRequest();
break;
default:
console.log("Unknown ActiveXObject type: ", type);
}
}
我用您给出的示例对此进行了测试,我注意到JavaScript测试.readystate
,而不是.readyState
!
进一步的Greasemonkey修补可以解决这个问题:
Object.defineProperty(XMLHttpRequest.prototype, "readystate", {
get: function() { return this.readyState; }
});
下一个问题是JavaScript使用TableRow单元格集合就好像它是一个函数...因此:
Object.defineProperty(HTMLTableRowElement.prototype, "cells", {
get: function() { return function(index) {
return this.querySelectorAll('td')[index];
};
}
})
如果它已经感觉事情已经失控,页面就会完成并转移到&#34; main.html&#34;,这会让事情变得更有趣。
因为它包含了过去非常棘手的爆炸声:
<div id="service" style="display:none" style="behavior:url(/_styles/webservice.htc)"></div>
Microsoft CSS行为!!!这些都是大约15年前的风靡一时。
如果您认为达到这一点是不好的,再往前走,需要比我有时间更多的耐心,我确实看了一下webservice.htc,并且那里有很多反向 - 针对一个Stack Overflow问题,围绕该脚本进行工程设计。
我很抱歉,我无法让这个为你工作!
不要花时间投入时间,我个人会通过VirtualBox让自己在Linux上运行IE并使用IE VM