Skip to content

Instantly share code, notes, and snippets.

@yuizho
Last active March 5, 2016 17:29
Show Gist options
  • Save yuizho/40592d3b65c366821144 to your computer and use it in GitHub Desktop.
Save yuizho/40592d3b65c366821144 to your computer and use it in GitHub Desktop.
chrome_plugin
(function() {
var click = function() {
alert("入れ替え後のイベント");
};
var load = function() {
// htmlの書き換え
var h1 = document.createElement('h3');
h1.setAttribute("class", "message");
h1.innerHTML = "checkerが有効です";
document.body.insertBefore(h1, document.body.firstChild);
// イベントの挿入
var btns = document.querySelectorAll('button');
for(var i=0, len=btns.length; i < len; i++) {
btns[i].addEventListener("click", click, false);
}
};
document.addEventListener("DOMContentLoaded", load, false);
}());
<html>
<head>
<script>
(function() {
var click = function() {
alert("元のイベント");
}
var load = function() {
var btns = document.querySelectorAll('button');
for(var i=0, len=btns.length; i < len; i++) {
btns[i].addEventListener("click", click, false);
}
};
document.addEventListener("DOMContentLoaded", load, false);
}());
</script>
</head>
<body>
<button>OK</button>
</body>
</html>
{
"manifest_version": 2,
"name": "checker",
"description": "checker",
"version": "0.1",
"content_scripts": [{
"matches": [
"http://*/*",
"https://*/*",
"file://*/*"
],
"js": ["checker.js"],
"run_at": "document_start"
}]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment