https://github.com/octolinker/injection
https://github.com/octolinker/injection
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/octolinker/injection
- Owner: OctoLinker
- Created: 2015-01-27T23:33:34.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2023-09-07T17:20:12.000Z (over 2 years ago)
- Last Synced: 2025-07-01T16:51:23.305Z (7 months ago)
- Language: JavaScript
- Size: 88.9 KB
- Stars: 36
- Watchers: 6
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# injection
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]
> Tiny script which helps you to build better browser extensions for GitHub.com
## Why you need this package
GitHub.com is a huge web app with millions of visitors every day. To reduce the serve load, some parts are build as a single page app. This means, not every click results in a page reload. This is a big problem for some extension scenarios.
GitHub.com uses [pjax](https://github.com/defunkt/jquery-pjax) which fires an event after replacing the requested page with the previous one. GitHub-inject will invoke the provided callback when `pjax:end` is dispatched and you can reinitialize your extension. For simplicity the callback is also executed on the first script execution.
## Install
```bash
$ npm install --save github-injection
```
## Usage
```js
const gitHubInjection = require('github-injection');
gitHubInjection(() => {
const el = window.document.getElementsByClassName('header')[0];
const randomColor = '#' + ((1<<24) * Math.random()|0).toString(16);
el.style.backgroundColor = randomColor;
});
```
## License
Copyright (c) 2015 Stefan Buck. Licensed under the MIT license.
[npm-url]: https://npmjs.org/package/github-injection
[npm-image]: https://badge.fury.io/js/github-injection.svg
[travis-url]: https://travis-ci.org/octolinker/injection
[travis-image]: https://travis-ci.org/OctoLinker/injection.svg?branch=master