https://github.com/mozilla/readability(readability.js用于创建网页的阅读 View )

如何在此测试网页上实现readability.js
问题是,readability.js删除了我要保留的该网站的元素,并保留了应删除的那些元素。我希望有一个人可以帮助我。谢谢!是否有任何有关如何使用readability.js的文档?

<html><head>
<title>Reader View shows only the browser in reader view</title>
    <script src="https://raw.githack.com/mozilla/readability/master/Readability.js"></script>
</head>
<body>
Everything outside the main div tag vanishes in Reader View<br>
<img class="no-print" src="http://dummyimage.com/1024x100/000/ffffff&text=This+banner+should+vanish+in+print+view">
<div>
   <h1>H1 tags outside ot a p tag are hidden in reader view</h1>
   <img class="no-print" src="http://dummyimage.com/1024x100/000/ffffff&text=This+banner+is resized+in+print+view">
   <p>
 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
 123456789 123456
</p>
</div>
</body>
    <script>
    var article = new Readability(document).parse();
    </script>
</html>

测试页面的来源:Optimize website to show reader view in Firefox

最佳答案

你有尝试过吗?
从他们的github页面:
“Readability的parse()通过修改DOM起作用。这删除了网页中的某些元素。您可以通过在创建Readability对象时传递文档对象的克隆来避免这种情况。”

var documentClone = document.cloneNode(true);
var article = new Readability(documentClone).parse();
您可以复制dom对象,这样就不会真正修改真实的dom。

08-03 23:43