高亮样式添加

This commit is contained in:
jaywcjlove
2016-03-01 22:00:30 +08:00
parent 535bc44674
commit 3133f3f3e0

View File

@@ -5,7 +5,7 @@ chrome.extension.onRequest.addListener(
if(bodys&&bodys.length>0&&bodys[0].contentDocument){
var body = bodys[0].contentDocument;
if(body){
var elms = body.querySelectorAll('code,pre,h1,h2,h3,h4,h5,h6,p,div,span');
var elms = body.querySelectorAll('pre code,pre,h1,h2,h3,h4,h5,h6,p,div,span');
for (var i = 0; i < elms.length; i++) {
var styl = elms[i].getAttribute('style');
if(elms[i].tagName === 'PRE'){
@@ -15,13 +15,20 @@ chrome.extension.onRequest.addListener(
}else{
if(styl){
styl = styl.replace(/font-family\:[\s\S]*?\;/g,'');
if(elms[i].tagName === 'SPAN'){
styl += 'word-wrap:normal!important;';
}
if(elms[i].tagName === 'SPAN') styl += 'word-wrap:normal!important;';
elms[i].setAttribute('style',styl);
}
}
}
var elms = body.querySelectorAll('p code');
for (var i = 0; i < elms.length; i++) {
if(elms[i].tagName === 'CODE'){
elms[i].setAttribute('style','color: #c7254e;background-color: #f9f2f4;padding: 2px 4px;border-radius: 3px;')
}
}
}
}
sendResponse({ msg: '更改完毕!!' });