Skip to content

Instantly share code, notes, and snippets.

@arantius arantius/mut.user.js
Last active Aug 29, 2015

Embed
What would you like to do?
// ==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
You can’t perform that action at this time.