domdistiller.js revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file.
4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// These includes will be processed at build time by grit.
6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)<include src="../../../../third_party/dom_distiller_js/js/domdistiller.js"/>
7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)// Extracts long-form content from a page and returns an array where the first
9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// element is the article title, the second element is HTML containing the
1023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)// long-form content, the third element is the next page link, and the fourth
1123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)// element is the previous page link.
12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)(function() {
13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  var result = new Array(4);
14c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  try {
15c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    result[0] = com.dom_distiller.DocumentTitleGetter.getDocumentTitle(
16c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch        document.title, document.documentElement);
17c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    result[1] = com.dom_distiller.ContentExtractor.extractContent();
18c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    result[2] = com.dom_distiller.PagingLinksFinder.findNext(
19c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch        document.documentElement);
20c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    // TODO(shashishekhar): Add actual previous page link here.
21c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    result[3] = '';
22c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  } catch (e) {
23c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    window.console.log("Error during distillation: " + e);
24c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  }
2523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  return result;
26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)})()
27