User:Zuohaocheng/romanCJKV.js
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
$(document).ready(function() {
$("span.comment, i, cite, em, var").each(function(){
var oldHtml=this.innerHTML+"";
var newHtml="";
var regex= /[\u0020-\u002f\u003d-\u1000]+/g;
var indexBuf;
do{
indexBuf = regex.lastIndex;
var match=regex.exec(oldHtml);
var backFlag = false;
if(match!=null) {
regex.lastIndex=match.index+match[0].length;
newHtml += oldHtml.substr(indexBuf, match.index - indexBuf);
if (oldHtml[match.index-1] === "<") {
regex.lastIndex = match.index - 1;
backFlag = true;
}
else {
newHtml += "<span class=\"halfspace\">"+match[0]+"</span>";
}
if (oldHtml[regex.lastIndex] === "<") {
var protect = new RegExp("\\<.*?\\>","g");
protect.lastIndex = regex.lastIndex;
var protectMatch = protect.exec(oldHtml);
if (protectMatch != null) {
regex.lastIndex += protectMatch[0].length;
if (backFlag) {
backFlag = false;
newHtml += protectMatch[0].substr(1, protectMatch[0].length -1);
}
else {
newHtml += protectMatch[0];
}
}
}
}
} while(match!=null)
newHtml += oldHtml.substr(indexBuf, oldHtml.length - indexBuf);
this.innerHTML=newHtml;
$(this).css("letter-spacing","-2pt");
});
});