使用用户脚本删除 <body>

Removing <body> with a userscript

对不起,我不太擅长编程。我正在尝试通过用户脚本修复我学校网站上的这个恼人的错误。我已经在几个页面上测试了 RegEx,至少是有效的。我需要让用户脚本删除我不想看到的部分。这是网站源码的一个片段,我用'//'标记了需要删除的内容。

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
//<html><head>
//<title>404 Not Found</title>
//</head><body>
//<h1>Not Found</h1>
//<p>The requested URL /get.php was not found on this server.</p>
//</body></html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" >
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="robots" content="index, follow" />

我的用户脚本不起作用。我知道它反映了我作为程序员的技能,请不要讨厌。

var REGEX = /<HTML>(.*?)([^\n]*?\n+?)+?<\/BODY><\/HTML>/ig;
document.body.innerHTML=document.body.innerHTML.replace(REGEX, '');

这个标记显然是无效的,但是浏览器(至少 Chrome 和 Firefox)将把这两个 <html> 部分合并到一起。所以与 document.body 互动可能不是你想要的。

这样做可以直观地解决问题:

document.querySelector('h1').remove() // remove first h1 "Not Found"
document.querySelector('p').remove() // remove first p "The requested..."