meszyouh
2018-05-04 13:15:53 +08:00
```
(function() {
var children = $("body").children(":not(.wrap)"),
el;
var parser = /[a-zA-Z\d]{3,}/,
reg;
var filter = function(el, reg, level, counter) {
if (level > 4) {
return;
}
el.children().each(function() {
var t = $(this);
var id = el.attr("id"),
className = el.attr("class").split(/\s+/);
if (reg.test(id)) {
counter.num++;
}
if (reg.test(className)) {
counter.num++;
}
filter(t, reg, level + 1, counter);
});
if (counter.num >= 4 && level === 1) {
el.remove();
$("head").append(
"<style>#" +
el.attr("id") +
"{position:static;height:0;transform:scale(0,0);overflow:hidden;}</style>"
);
}
};
children.each(function() {
el = $(this);
var id = el.attr("id"),
match1,
match2,
className = el.attr("class");
var counter = {
num: 0
};
match1 = id.match(parser);
match2 = className.match(parser);
if (match1 || match2) {
match1 = match1 || [""];
match2 = match2 || [""];
var str = match1[0].length > match2[0].length ? match1[0] : match2[0];
reg = new RegExp(str, "i");
filter(el, reg, 1, counter);
}
});
$('[class*="hengfu"]').remove();
})();
```
试试这个