问题专家
火狐狸
火狐狸
  • UID5440
  • 注册日期2005-04-24
  • 最后登录2006-02-08
  • 发帖数231
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
阅读:1133回复:0

这段代码怎么样把汉字变成***?

楼主#
更多 发布于:2005-09-28 22:46
// ==UserScript==
// @name          Clean Language
// @namespace     http://www.arantius.com/article/arantiu ... +language/
// @description  Keep bad words off of the web.  Edit the array badwords to control which words are removed from pages and replaced with ***.
// ==/UserScript==

//
// Originally written by Anthony Lieuallen of http://www.arantius.com/
// Licensed for unlimited modification and redistribution as long as
// this notice is kept intact.
//
// If possible, please contact me regarding new features, bugfixes
// or changes that I could integrate into the existing code instead of
// creating a different script.  Thank you
//

(function() {
//edit the words here but ...
var badwords=['whoar','whore','wtf','bitch','bastard','damn','shit','fuck','ass','asshole','jackass'];

//do not touch anything below here
var bw="\\b("+badwords.join("|")+")\\b";
bw=new RegExp(bw, "gi");
 
var els = document.evaluate('//*', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var el,i=0;
while (el=els.snapshotItem(i++)) {
//don't mess with these tags
if ('SCRIPT'==el.tagName) continue;
if ('STYLE'==el.tagName) continue;

for (var j=0; j<el.childNodes.length; j++) {
if ('#text'==el.childNodes[j].nodeName) {
el.childNodes[j].textContent=el.childNodes[j].textContent.replace(bw, '***');
}
}
}
document.title=document.title.replace(bw, '***');
})
();


把下面单引号内的单词换成欲屏蔽的中文词组后只能替换单独的词(好象是前后有空格的才行),对句子里的词没反应,谁会给改一下?
badwords=['whoar','whore','wtf','bitch','bastard','damn','shit','fuck','ass','asshole','jackass'];
游客

返回顶部