{"id":13442450,"url":"https://github.com/pnigos/hookjs","last_synced_at":"2025-03-20T14:30:32.826Z","repository":{"id":6963167,"uuid":"8215604","full_name":"pnigos/hookjs","owner":"pnigos","description":"javascript function hook","archived":false,"fork":false,"pushed_at":"2020-10-06T00:23:18.000Z","size":6,"stargazers_count":107,"open_issues_count":0,"forks_count":42,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-28T05:13:28.194Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pnigos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-15T09:25:58.000Z","updated_at":"2024-05-22T03:51:11.000Z","dependencies_parsed_at":"2022-07-21T12:18:18.253Z","dependency_job_id":null,"html_url":"https://github.com/pnigos/hookjs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnigos%2Fhookjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnigos%2Fhookjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnigos%2Fhookjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnigos%2Fhookjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pnigos","download_url":"https://codeload.github.com/pnigos/hookjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244629973,"owners_count":20484288,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T03:01:45.849Z","updated_at":"2025-03-20T14:30:32.418Z","avatar_url":"https://github.com/pnigos.png","language":"JavaScript","readme":"hook.js\n===\nA hooks to any Javascript function.\n\n##Notice\n```\n[bool]hook:params{\n\trealFunc[String|must]:用于保存原始函数的函数名称,用于unHook;\n\thookFunc[Function|must]:替换的hook函数;\n\tcontext[Object|opt]:目标函数所在对象,用于hook非window对象下的函数，如String.protype.slice,carInstance1\n\tmethodName[String|opt]:匿名函数需显式传入目标函数名eg:this.Begin = function(){....};\n}\n[bool]unhook:params{\n\trealFunc[String|must]:用于保存原始函数的函数名称,用于unHook;\n\tfuncName[String|must]:被Hook的函数名称\n\tcontext[Object|opt]:目标函数所在对象,用于hook非window对象下的函数，如String.protype.slice,carInstance1\n}\n```\n##Examples\n```\n\u003cscript src=hook.js\u003e\u003c/script\u003e\nvar myHook = new Hooks();\nmyHook.initEnv();\n\n//普通全局函数\nvar _alert = null;\nfunction myalert(param){console.log(\"before hook\");}\nalert.hook(\"_alert\",myalert);\nalert.unhook(\"_alert\",\"alert\");\nalert(1);\n\n//自定义对象匿名函数\nfunction Person() {\nthis.getName = function(name) {\nalert('Call' + name);\n}\n} \nvar p = new Person();\nvar _p_getName = null;\nfunction mygetName(name){alert(\"Hooked\");}\np.getName.hook(\"_p_getName\",mygetName,p,\"getName\");\np.getName.unhook(\"_p_getName\",\"getName\",p);\np.getName(\"pnig0s\");\n\n//原型对象函数\nvar _slice = null;\nfunction myslice(param){alert(\"Hooked\");}\nString.prototype.slice.hook(\"_slice\",myslice,String.prototype);\nString.prototype.slice.unhook(\"_slice\",\"slice\",String.prototype);\nvar str = \"pnig0s\";\nstr.slice(1);\n\nmyHooks.cleanEnv(); //clear hooks\n```\n","funding_links":[],"categories":["JavaScript"],"sub_categories":["REST"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpnigos%2Fhookjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpnigos%2Fhookjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpnigos%2Fhookjs/lists"}