0
은 당신이 당신이 대부분의 페이지에서 작동하는 userscript에서 ''에 "nestedmost"DIV의 내용을 설정하는 방법이div의 grand-grand -...- children의 콘텐츠 만 어떻게 설정합니까?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>
</title>
</head>
<body>
<div>
<div>
How are you?
</div>
<div>
<div>
<div>
<p>
Hello
</p>
</div>
</div>
</div>
</div>
<div>
</div>
</body>
</html>
같은 HTML? 이 컨텍스트에서 How are you
은 유지되지만 <p>Hello</p>
은 제거됩니다.
컨텍스트 : 목표는 자동으로 포럼 게시물 (즉, 가장 작은 단위) 또는 특정 키워드가 포함되어 있지만 전체 페이지가 아닌 기사가 키워드가 중첩되어 있기 때문에 필터링하는 것입니다.
function find_deepest_div() {
var deepest_div;
var deepest_div_depth = -1;
function search(current, depth) {
if (current.tagName === "DIV" && depth > deepest_div_depth) {
deepest_div = current;
deepest_div_depth = depth;
}
for (var i = 0, len = current.children.length; i < len; i++)
search(current.children[i], depth + 1);
}
search(document.body, 0);
return deepest_div;
}
당신은의 내용을 삭제하는 데 사용할 수 있습니다 :