Add onload hook

This commit is contained in:
the1812 2019-03-24 22:17:41 +08:00
parent a556cb2045
commit da64d2653d
5 changed files with 82 additions and 57 deletions

View File

@ -1,6 +1,6 @@
// ==UserScript==
// @name Bilibili Evolved (Offline)
// @version 250.89
// @version 251.27
// @description Bilibili Evolved 的离线版, 所有功能都已内置于脚本中.
// @author Grant Howard, Coulomb-G
// @copyright 2019, Grant Howard (https://github.com/the1812) & Coulomb-G (https://github.com/Coulomb-G)
@ -293,27 +293,32 @@ function setupAjaxHook()
fireHandlers("after" + name, thisArgs, ...args);
return returnValue;
};
XMLHttpRequest.prototype.open = function (...args) { return hook("open", this, ...args); };
XMLHttpRequest.prototype.send = function (...args)
const hookOnEvent = (name, thisArg) =>
{
if (this.onreadystatechange)
if (thisArg[name])
{
const originalHandler = this.onreadystatechange;
this.onreadystatechange = (...args) =>
const originalHandler = thisArg[name];
thisArg[name] = (...args) =>
{
fireHandlers("beforeOnReadyStateChange", this, ...args);
originalHandler.apply(this, args);
fireHandlers("afterOnReadyStateChange", this, ...args);
fireHandlers("before" + name, thisArg, ...args);
originalHandler.apply(thisArg, args);
fireHandlers("after" + name, thisArg, ...args);
};
}
else
{
this.onreadystatechange = (...args) =>
thisArg[name] = (...args) =>
{
fireHandlers("beforeOnReadyStateChange", this, ...args);
fireHandlers("afterOnReadyStateChange", this, ...args);
fireHandlers("before" + name, thisArg, ...args);
fireHandlers("after" + name, thisArg, ...args);
};
}
};
XMLHttpRequest.prototype.open = function (...args) { return hook("open", this, ...args); };
XMLHttpRequest.prototype.send = function (...args)
{
hookOnEvent("onreadystatechange", this);
hookOnEvent("onload", this);
return hook("send", this, ...args);
};
}

View File

@ -1,6 +1,6 @@
// ==UserScript==
// @name Bilibili Evolved (Preview Offline)
// @version 250.89
// @version 251.27
// @description Bilibili Evolved 的预览离线版, 可以抢先体验新功能, 并且所有功能都已内置于脚本中.
// @author Grant Howard, Coulomb-G
// @copyright 2019, Grant Howard (https://github.com/the1812) & Coulomb-G (https://github.com/Coulomb-G)
@ -293,27 +293,32 @@ function setupAjaxHook()
fireHandlers("after" + name, thisArgs, ...args);
return returnValue;
};
XMLHttpRequest.prototype.open = function (...args) { return hook("open", this, ...args); };
XMLHttpRequest.prototype.send = function (...args)
const hookOnEvent = (name, thisArg) =>
{
if (this.onreadystatechange)
if (thisArg[name])
{
const originalHandler = this.onreadystatechange;
this.onreadystatechange = (...args) =>
const originalHandler = thisArg[name];
thisArg[name] = (...args) =>
{
fireHandlers("beforeOnReadyStateChange", this, ...args);
originalHandler.apply(this, args);
fireHandlers("afterOnReadyStateChange", this, ...args);
fireHandlers("before" + name, thisArg, ...args);
originalHandler.apply(thisArg, args);
fireHandlers("after" + name, thisArg, ...args);
};
}
else
{
this.onreadystatechange = (...args) =>
thisArg[name] = (...args) =>
{
fireHandlers("beforeOnReadyStateChange", this, ...args);
fireHandlers("afterOnReadyStateChange", this, ...args);
fireHandlers("before" + name, thisArg, ...args);
fireHandlers("after" + name, thisArg, ...args);
};
}
};
XMLHttpRequest.prototype.open = function (...args) { return hook("open", this, ...args); };
XMLHttpRequest.prototype.send = function (...args)
{
hookOnEvent("onreadystatechange", this);
hookOnEvent("onload", this);
return hook("send", this, ...args);
};
}

View File

@ -292,27 +292,32 @@ function setupAjaxHook()
fireHandlers("after" + name, thisArgs, ...args);
return returnValue;
};
XMLHttpRequest.prototype.open = function (...args) { return hook("open", this, ...args); };
XMLHttpRequest.prototype.send = function (...args)
const hookOnEvent = (name, thisArg) =>
{
if (this.onreadystatechange)
if (thisArg[name])
{
const originalHandler = this.onreadystatechange;
this.onreadystatechange = (...args) =>
const originalHandler = thisArg[name];
thisArg[name] = (...args) =>
{
fireHandlers("beforeOnReadyStateChange", this, ...args);
originalHandler.apply(this, args);
fireHandlers("afterOnReadyStateChange", this, ...args);
fireHandlers("before" + name, thisArg, ...args);
originalHandler.apply(thisArg, args);
fireHandlers("after" + name, thisArg, ...args);
};
}
else
{
this.onreadystatechange = (...args) =>
thisArg[name] = (...args) =>
{
fireHandlers("beforeOnReadyStateChange", this, ...args);
fireHandlers("afterOnReadyStateChange", this, ...args);
fireHandlers("before" + name, thisArg, ...args);
fireHandlers("after" + name, thisArg, ...args);
};
}
};
XMLHttpRequest.prototype.open = function (...args) { return hook("open", this, ...args); };
XMLHttpRequest.prototype.send = function (...args)
{
hookOnEvent("onreadystatechange", this);
hookOnEvent("onload", this);
return hook("send", this, ...args);
};
}

View File

@ -292,27 +292,32 @@ function setupAjaxHook()
fireHandlers("after" + name, thisArgs, ...args);
return returnValue;
};
XMLHttpRequest.prototype.open = function (...args) { return hook("open", this, ...args); };
XMLHttpRequest.prototype.send = function (...args)
const hookOnEvent = (name, thisArg) =>
{
if (this.onreadystatechange)
if (thisArg[name])
{
const originalHandler = this.onreadystatechange;
this.onreadystatechange = (...args) =>
const originalHandler = thisArg[name];
thisArg[name] = (...args) =>
{
fireHandlers("beforeOnReadyStateChange", this, ...args);
originalHandler.apply(this, args);
fireHandlers("afterOnReadyStateChange", this, ...args);
fireHandlers("before" + name, thisArg, ...args);
originalHandler.apply(thisArg, args);
fireHandlers("after" + name, thisArg, ...args);
};
}
else
{
this.onreadystatechange = (...args) =>
thisArg[name] = (...args) =>
{
fireHandlers("beforeOnReadyStateChange", this, ...args);
fireHandlers("afterOnReadyStateChange", this, ...args);
fireHandlers("before" + name, thisArg, ...args);
fireHandlers("after" + name, thisArg, ...args);
};
}
};
XMLHttpRequest.prototype.open = function (...args) { return hook("open", this, ...args); };
XMLHttpRequest.prototype.send = function (...args)
{
hookOnEvent("onreadystatechange", this);
hookOnEvent("onload", this);
return hook("send", this, ...args);
};
}

View File

@ -96,27 +96,32 @@ export function setupAjaxHook()
fireHandlers("after" + name, thisArgs, ...args);
return returnValue;
};
XMLHttpRequest.prototype.open = function (...args) { return hook("open", this, ...args); };
XMLHttpRequest.prototype.send = function (...args)
const hookOnEvent = (name, thisArg) =>
{
if (this.onreadystatechange)
if (thisArg[name])
{
const originalHandler = this.onreadystatechange;
this.onreadystatechange = (...args) =>
const originalHandler = thisArg[name];
thisArg[name] = (...args) =>
{
fireHandlers("beforeOnReadyStateChange", this, ...args);
originalHandler.apply(this, args);
fireHandlers("afterOnReadyStateChange", this, ...args);
fireHandlers("before" + name, thisArg, ...args);
originalHandler.apply(thisArg, args);
fireHandlers("after" + name, thisArg, ...args);
};
}
else
{
this.onreadystatechange = (...args) =>
thisArg[name] = (...args) =>
{
fireHandlers("beforeOnReadyStateChange", this, ...args);
fireHandlers("afterOnReadyStateChange", this, ...args);
fireHandlers("before" + name, thisArg, ...args);
fireHandlers("after" + name, thisArg, ...args);
};
}
};
XMLHttpRequest.prototype.open = function (...args) { return hook("open", this, ...args); };
XMLHttpRequest.prototype.send = function (...args)
{
hookOnEvent("onreadystatechange", this);
hookOnEvent("onload", this);
return hook("send", this, ...args);
};
}