Skip to content

Instantly share code, notes, and snippets.

@arantius
Last active August 29, 2015 14:26
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/77d8a42fc3bd3a30972b to your computer and use it in GitHub Desktop.
Save arantius/77d8a42fc3bd3a30972b to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Title Mutation Logger
// @version 1
// @include *
// @grant none
// @run-at document-start
// ==/UserScript==
console.log('user script mutation observer setup ...');
console.log(document.documentElement.innerHTML);
MutationObserver = window.MutationObserver;
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
var addedNodes = mutation.addedNodes;
for (var i = 0; i < addedNodes.length; i++) {
if (addedNodes[i].nodeName == 'TITLE') {
console.log("Yes, script is active! Hurray!");
}
}
});
});
observer.observe(document, {childList: true, subtree: true, attributes: true});
<html>
<head>
<meta charset='utf-8'>
<title>Mutation Event Test Page 1</title>
<script>console.log('content of Mutation Event Test Page 1');</script>
</head>
<body>
<p>Mutation Event Test Page 1</p>
</body>
<html>
<head>
<meta charset='utf-8'>
<script>console.log('content of Mutation Event Test Page 2');</script>
<title>Mutation Event Test Page 2</title>
</head>
<body>
<p>Mutation Event Test Page 2</p>
</body>
<html>
<head>
<meta charset='utf-8'>
<title>Mutation Event Test Page 2</title>
</head>
<body>
<p>Mutation Event Test Page 2</p>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment