Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // These includes will be processed at build time by grit. | 5 // These includes will be processed at build time by grit. |
| 6 <include src="../../../../third_party/dom_distiller_js/package/js/domdistiller.j s"/> | 6 <include src="../../../../third_party/dom_distiller_js/package/js/domdistiller.j s"/> |
| 7 | 7 |
| 8 // Extracts long-form content from a page and returns an array where the first | 8 // Applies DomDistillerJs to the content of the page and returns a |
| 9 // element is the article title, the second element is HTML containing the | 9 // DomDistillerResults (as a javascript object/dict). |
| 10 // long-form content, the third element is the next page link, and the fourth | |
| 11 // element is the previous page link. | |
| 12 (function() { | 10 (function() { |
| 13 var result = new Array(4); | |
| 14 try { | 11 try { |
| 15 result[0] = com.dom_distiller.DocumentTitleGetter.getDocumentTitle( | 12 // The OPTIONS placeholder will be replaced with the DomDistillerOptions at |
| 16 document.title, document.documentElement); | 13 // runtime. |
| 17 result[1] = com.dom_distiller.ContentExtractor.extractContent(); | 14 res = com.dom_distiller.DomDistiller.applyWithOptions($$OPTIONS); |
|
Yaron
2014/05/09 01:00:55
jsut inline in the return (or add a "var" if you w
| |
| 18 result[2] = com.dom_distiller.PagingLinksFinder.findNext( | 15 return res; |
| 19 document.documentElement); | |
| 20 // TODO(shashishekhar): Add actual previous page link here. | |
| 21 result[3] = ''; | |
| 22 | |
| 23 /** | |
| 24 * // Properties from markup tags. | |
| 25 * | |
| 26 * var parser = new com.dom_distiller.MarkupParser(document.documentElement) ; | |
| 27 * if (!parser.optOut()) { | |
| 28 * // Basic properties. | |
| 29 * var title = parser.getTitle(); // String type. | |
| 30 * var pageType = parser.getType(); // String type. | |
| 31 * var pageUrl = parser.getUrl(); // String type. | |
| 32 * var author = parser.getAuthor(); // String type. | |
| 33 * var description = parser.getDescription(); // String type. | |
| 34 * var publisher = parser.getPublisher(); // String type. | |
| 35 * var copyright = parser.getCopyright(); // String type. | |
| 36 * | |
| 37 * // Structured Image's. | |
| 38 * var images = parser.getImages(); | |
| 39 * for (var i = 0; i < images.length; i++) { | |
| 40 * var image = images[i]; | |
| 41 * var url = image.getUrl(); // String type. | |
| 42 * var secureUrl = image.getSecureUrl(); // String type. | |
| 43 * var type = image.getType(); // String type. | |
| 44 * var caption = image.getCaption(); // String type. | |
| 45 * var width = image.getWidth(); // int type. | |
| 46 * var height = image.getHeight(); // int type. | |
| 47 * } | |
| 48 * | |
| 49 * // Structured Article. | |
| 50 * var article = parser.getArticle(); | |
| 51 * if (article != null) { | |
| 52 * var publishedTime = article.getPublishedTime(); // String type. | |
| 53 * var modifiedTime = article.getModifiedTime(); // String type. | |
| 54 * var expirationTime = article.getExpirationTime(); // String type. | |
| 55 * var sectionName = article.getSection(); // String type. | |
| 56 * var authors = article.getAuthors(); | |
| 57 * for (var i = 0; i < authors.length; i++) { | |
| 58 * var author = authors[i]; // String type. | |
| 59 * } | |
| 60 * } | |
| 61 * } | |
| 62 */ | |
| 63 | |
| 64 } catch (e) { | 16 } catch (e) { |
| 65 window.console.log("Error during distillation: " + e); | 17 window.console.error("Error during distillation: " + e); |
| 18 if (e.stack != undefined) window.console.error(e.stack); | |
| 66 } | 19 } |
| 67 return result; | 20 return undefined; |
| 68 })() | 21 })() |
| OLD | NEW |