Created
December 3, 2014 03:52
-
-
Save linusyu/1716079c91e864ad91dd to your computer and use it in GitHub Desktop.
replaceTitle.user.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Replace Title | |
// @run-at document-end | |
// @author 2ke | |
// @grant none | |
// @version 1 | |
// @include * | |
// ==/UserScript== | |
;(function(){ | |
"use strict"; | |
var replaceTitle = { | |
keywords : [ | |
["易亚媛","歪歪"], | |
["文科","老科"] | |
], | |
replacekw : function(){ | |
this.keywords.forEach(function(i){ | |
if(document.title.search(i[0]) !== -1){ | |
document.title = document.title.replace(new RegExp(i[0],'gi'),i[1]); | |
} | |
}); | |
}, | |
init : function(){ | |
this.replacekw(); | |
var target = document.querySelector("title"); | |
var MutationObserver = window.MutationObserver || | |
window.WebKitMutationObserver || window.MozMutationObserver; | |
var observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function() { | |
replaceTitle.replacekw(); | |
}); | |
}); | |
var config = { attributes: true, childList: true, characterData: true }; | |
observer.observe(target, config); | |
} | |
} | |
replaceTitle.init(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment