我正在尝试创建一个扩展来禁用页面上的所有样式,但它无法正常工作。 我的javascript是有效的,以及我的清单和HTML代码。有任何想法吗? 谢谢
这是我更新的清单代码
{
"name": "Styles Disable Button",
"manifest_version": 2,
"version": "1.0",
"description": "This function will enable users to deactivate all styles from
the webpages they are opening.",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "styledisable.html"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["removestyles.js"]
}
]
}
这是我正在使用的Javascript
(在某些网站上只删除了样式)
function removeStyles(el) {
el.removeAttribute('style');
if(el.childNodes.length > 0) {
for(var child in el.childNodes) {
/* filter element nodes only */
if(el.childNodes[child].nodeType == 1)
removeStyles(el.childNodes[child]);
}
}
}
var stylesheets = document.getElementsByTagName('link'), i, sheet;
var images = document.getElementsByTagName('img');
while(images.length > 0) {
images[0].parentNode.removeChild(images[0]);
}
for(i in stylesheets) {
sheet = stylesheets[i];
if(sheet.getAttribute('type').toLowerCase() == 'text/css')
sheet.parentNode.removeChild(sheet);
}
removeStyles(document.body);
这是我的HTML 5代码
<!DOCTYPE html>
<html>
<head>
<title>Style Disable Button</title>
<style>
body {
width: 400px;
font-family: "Times New Roman", Times, serif;
}
h1 {
font-size: 30px;
text-align: center;
}
p {
font-size: 15px;
text-align: justify;
}
footer {
float: right;
}
</style>
</head>
<body>
<h1>Lighter Page Faster Download</h1>
<p>
This function will enable users to deactivate all styles from the webpages they are opening.
<br>Lighter pages for faster download and connectivity.
</p>
<p>
Esta funcion permitira a los usuarios de deactivar todos los stiles de paginas web que estan abriendo.
<br>Paginas mas legeras para una descarga y una conectivitad mas rapida.
</p>
<p>
Cette fonction permettra aux utilisateurs de desactiver tous les styles a partir des pages web, ils ouvrent.
<br>Pages plus legeres pour un telechargement et un connectivite plus rapide.
</p>
<br>
<br>
<footer>
Francesco Volpi © 2015
</footer>