Giter Site home page Giter Site logo

wildgenie / ihooker-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from klaudz/ihooker-js

0.0 3.0 0.0 112 KB

A simple kit for hooking methods and properties in JavaScript. It might help debug code and even fix it or hack it.

HTML 9.95% JavaScript 90.05%

ihooker-js's Introduction

iHooker-js

A simple kit for hooking methods and properties in JavaScript. It might help debug code and even fix it or hack it.

Getting Started

Here is a simple code that replaces alert() by console.log() by using iHooker.

iHooker.hookMethod(window, "alert", function(original_alert, args) {
    // Replace alert() by console.log().
    console.log(args[0]);
});

Documentation

iHooker.hookMethod()

Summary

Hooks a method with its context and string name by using an anonymous function.

Syntax

iHooker.hookMethod(context, methodName, hook)

Parameters

context{object}

The context of the target method. window will be as the default context if leaves it null.

methodName{string}

The string name of the target method. Make sure the name is valid, or may cause an exception.

hook{function}

An anonymous function for hooking the target method. This hook function could be defined as function(original_method, args).

Arguments

original_method, which is the first argument, is the reference of the original target function. args, which is the second, is the object when the the original is called.

Returns

Returns, which is optional (depending on the target), for the target function.

Returns {boolean}

True if this method succeeds to hook; otherwise, false.

Examples

Please see the sample code in Sample Folder.

iHooker.hookProperty()

Summary

Hooks a property with its context and string name by using a getter function and setter function.

Syntax

iHooker.hookProperty(context, propertyName, getter, setter)

Parameters

context{object}

The context of the target property. window will be as the default context if leaves it null.

propertyName {string}

The string name of the target property. Make sure the name is valid, or may cause an exception.

getter {function}

An anonymous function for hooking the target's getter. Leaves null if do not want to hook the getter. This getter function could be defined as function(getValue).

Arguments

getValue is the original return value from the original getter.

Returns

Returns a value as a new return value for hooking getter.

setter {function}

An anonymous function for hooking the target's setter. Leaves null if do not want to hook the setter. This setter function could be defined as <function(setValue, currentValue)>.

Arguments

setValue is the original value to set from the original setter.

currentValue is the original value before doing set.

Returns

Returns a value as a new value to set for hooking setter.

Returns {boolean}

True if this method succeeds to hook; otherwise, false.

Examples

Please see the sample code in Sample Folder.

Release

2014/8/15 - v1.0

License

Copyright (c) 2014 Klaudz

http://klaudz.me/

ihooker-js's People

Contributors

klaudz avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.