Last active
August 29, 2015 14:21
-
-
Save RustingSword/be9da1eb4c2dbb3a6e0f to your computer and use it in GitHub Desktop.
将“私信”恢复成“豆邮”
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 驱逐私信,恢复豆邮 | |
// @namespace http://fanfou.com/lzgxd | |
// @description 将“私信”恢复成“豆邮” | |
// @include http://*.douban.com/* | |
// @version 0.1 | |
// @grant none | |
// ==/UserScript== | |
// via http://stackoverflow.com/a/1512889 | |
function replaceText(oldText, newText, node){ | |
node = node || document.body; // base node | |
var childs = node.childNodes, i = 0; | |
while(node = childs[i]){ | |
if (node.nodeType == 3){ // text node found, do the replacement | |
if (node.textContent) { | |
node.textContent = node.textContent.replace(oldText, newText); | |
} else { // support to IE | |
node.nodeValue = node.nodeValue.replace(oldText, newText); | |
} | |
} else { // not a text mode, look forward | |
if (window.location.href.indexOf('doumail') > -1) //在豆邮页面,递归替换 | |
replaceText(oldText, newText, node); | |
} | |
i++; | |
} | |
} | |
if (window.location.href.indexOf('doumail') > -1){ | |
//替换豆邮页面title | |
document.title = document.title.replace('私信', '豆邮') | |
//替换豆邮页面header | |
var header = document.getElementsByTagName("h1")[0] | |
replaceText('私信', '豆邮', header) | |
//移除豆邮页面豆邮改成私信的提醒 | |
$('.pop').remove() | |
//移除发送豆邮页面底部的提醒 | |
$('.item-submit').children("span:first").remove() | |
} | |
//顺便移除导航栏下载豆瓣app的提醒 | |
$('.lnk-doubanapp').remove() | |
//替换页面所有链接 | |
var links = document.getElementsByTagName("a") | |
for (var i = 0; i < links.length; i++) | |
replaceText('私信', '豆邮', links[i]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
完成历史使命……