wwmoraes / Native


Version: 1.1+294b9a0 updated

Summary: Save native functions to allow overrides to fix/extend functionality.

Homepage: https://github.com/wwmoraes/userscripts

Support: https://github.com/wwmoraes/userscripts/issues

Copyright: 2013, William Moraes (https://william.moraes.nom.br)

License: GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt

Native Overrides

This library allows any script to override native functions pretty much like OOP languages do. It also supports base/super call, which allows the override function to act like a proxy, i.e., you'll still get the native function result.

How to override

Simple Override

It's pretty simple to override a function:

Function.override('aObject.nativeFunction', function(){

You can do this multiple times: any subsequent call will override the last override function.

Override with native function call (a.k.a. base/super call)

If you need to use the native function inside your override, use the base object:

Function.override('aObject.nativeFunction', function(){

Override with original function arguments

If you need to use the original function arguments, or any arguments you receive, you can use the vanilla's arguments's object:

Function.override('aObject.nativeFunction', function(){
    doSomething.apply(this, arguments);
    base.nativeFunction.apply(this, arguments);

Restoring native function

You can restore the native function any time by calling:


This will rollback the function to it's vanilla state, even though the function got overridden multiple times.

Userscripts Using This Library

Rating: 0