Skip to content

Instantly share code, notes, and snippets.

@arantius
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arantius/10079391 to your computer and use it in GitHub Desktop.
Save arantius/10079391 to your computer and use it in GitHub Desktop.
test for Greasemonkey #1904
// ==UserScript==
// @name callback stubber
// @namespace x
// @include http://localhost/cb.html
// @version 1
// @grant none
// ==/UserScript==
unsafeWindow.cb = function(a) { console.log('script cb', a); }
var obj = {
cb: function(a) { console.log('script obj.cb', a); }
};
unsafeWindow.obj = obj;
document.getElementById('event2').addEventListener(
'click', obj.cb, false);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Content Callback Test</title>
</head>
<body>
<button onclick="cb('direct')">Direct Call</button><br>
<button onclick="obj.cb('direct')">Direct Call (obj)</button></br>
<button id="event1">Event Listener</button><br>
<button id="event2">Event Listener (obj)</button><br>
</body>
<script>
function cb(a) {
console.log('in-page cb', a);
}
var obj = {
cb: function(a) {
console.log('in-page obj.cb', a);
}
}
document.getElementById('event1').addEventListener(
'click', cb, false);
document.getElementById('event2').addEventListener(
'click', obj.cb, false);
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment