<commit_before># jquery.preempt

[![Build Status](https://travis-ci.org/boneskull/jquery.preempt.png?branch=master)](https://travis-ci.org/boneskull/jquery.preempt)
[![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/)

[jQuery](http://jquery.com) plugin to take legacy inline JS (i.e. `onclick`
and `href="javascript:..."`) and create event handlers to be run before or
after the inlined code (or both!).

> #### (Why would I need this?)
> My use case was that I was writing a [GreaseMonkey](https://addons.mozilla
.org/en-US/firefox/addon/greasemonkey/)-like [script](https://github
.com/boneskull/fb-bugmonkey-markdown) against a page with inline JS and my
jQuery events were not behaving.  Works for me; your mileage may vary.

## Usage

```javascript

// given <button onclick="doSomething()">do something</button>
// or <a href="javascript:doSomethingElse()">do something else</a>

// Basic usage:
$('button').preempt({
  attr: 'onclick',
  event: 'click',
}, function doSomethingBeforeSomething() {
  // do something else
});

// Restoring the inline JS:
$('button').preempt({
  attr: 'onclick',
  event: 'click',
  restore: true
});
<commit_msg>fixing bad links in README.md<commit_after># jquery.preempt

[![Build Status](https://travis-ci.org/boneskull/jquery.preempt.png?branch=master)](https://travis-ci.org/boneskull/jquery.preempt)
[![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/)

[jQuery](http://jquery.com) plugin to take legacy inline JS (i.e. `onclick`
and `href="javascript:..."`) and create event handlers to be run before or
after the inlined code (or both!).

> #### (Why would I need this?)
> My use case was that I was writing a [GreaseMonkey](https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/)-like [script](https://github.com/boneskull/fb-bugmonkey-markdown) against a page with inline JS and my
jQuery events were not behaving.  Works for me; your mileage may vary.

## Usage

```javascript

// given <button onclick="doSomething()">do something</button>
// or <a href="javascript:doSomethingElse()">do something else</a>

// Basic usage:
$('button').preempt({
  attr: 'onclick',
  event: 'click',
}, function doSomethingBeforeSomething() {
  // do something else
});

// Restoring the inline JS:
$('button').preempt({
  attr: 'onclick',
  event: 'click',
  restore: true
});

{'fraction_non_alphanumeric': 0.1712962962962963, 'fraction_numerical': 0.0, 'mean_word_length': 4.65952380952381, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6755475', 'n_tokens_mistral': 799, 'n_tokens_neox': 770, 'n_words': 212}