Skip to content

josephfrazier/injection

 
 

Repository files navigation

injection

NPM version Build Status Dependency Status Coverage Status

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.

The Github-Injection registers a listener to the dom which detects dom changes. If a significant dom node changed his content, the callback will be executed and you can reinitialize your extension. For simplicity the callback is also executed on the first script execution.

A sample implementation can be found in the Octo-Linker-Core package.

Install

Bower

$ bower install --save github-injection

Node

$ npm install --save github-injection

Usage

Browser

gitHubInjection(window, function(err) {
  if (err) {
    return console.error(err);
  }
  var el = window.document.getElementsByClassName('header')[0];
  var randomColor = '#' + ((1<<24) * Math.random()|0).toString(16);
  el.style.backgroundColor = randomColor;
});

Node (Browserify)

var gitHubInjection = require('github-injection');

gitHubInjection(window, function(err) {
  if (err) {
    throw err;
  }
  var el = window.document.getElementsByClassName('header')[0];
  var randomColor = '#' + ((1<<24) * Math.random()|0).toString(16);
  el.style.backgroundColor = randomColor;
});

License

Copyright (c) 2015 Stefan Buck. Licensed under the MIT license.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%