Skip to content

Instantly share code, notes, and snippets.

@linusyu
Created December 3, 2014 03:52
Show Gist options
  • Save linusyu/1716079c91e864ad91dd to your computer and use it in GitHub Desktop.
Save linusyu/1716079c91e864ad91dd to your computer and use it in GitHub Desktop.
replaceTitle.user.js
// ==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