Tiny script which helps you to build better browser extensions for GitHub.com
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.
Bower
$ bower install --save github-injection
Node
$ npm install --save github-injection
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;
});
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;
});
Copyright (c) 2015 Stefan Buck. Licensed under the MIT license.