mirror of
https://github.com/jaywcjlove/wxmp.git
synced 2026-01-12 00:08:50 +08:00
高亮样式添加
This commit is contained in:
15
js/bg.js
15
js/bg.js
@@ -5,7 +5,7 @@ chrome.extension.onRequest.addListener(
|
|||||||
if(bodys&&bodys.length>0&&bodys[0].contentDocument){
|
if(bodys&&bodys.length>0&&bodys[0].contentDocument){
|
||||||
var body = bodys[0].contentDocument;
|
var body = bodys[0].contentDocument;
|
||||||
if(body){
|
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++) {
|
for (var i = 0; i < elms.length; i++) {
|
||||||
var styl = elms[i].getAttribute('style');
|
var styl = elms[i].getAttribute('style');
|
||||||
if(elms[i].tagName === 'PRE'){
|
if(elms[i].tagName === 'PRE'){
|
||||||
@@ -15,13 +15,20 @@ chrome.extension.onRequest.addListener(
|
|||||||
}else{
|
}else{
|
||||||
if(styl){
|
if(styl){
|
||||||
styl = styl.replace(/font-family\:[\s\S]*?\;/g,'');
|
styl = styl.replace(/font-family\:[\s\S]*?\;/g,'');
|
||||||
if(elms[i].tagName === 'SPAN'){
|
if(elms[i].tagName === 'SPAN') styl += 'word-wrap:normal!important;';
|
||||||
styl += 'word-wrap:normal!important;';
|
|
||||||
}
|
|
||||||
elms[i].setAttribute('style',styl);
|
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: '更改完毕!!' });
|
sendResponse({ msg: '更改完毕!!' });
|
||||||
|
|||||||
Reference in New Issue
Block a user