Last active
September 12, 2017 22:55
-
-
Save N0taN3rd/5943a5d727caf2ac0651d119e2e9673d to your computer and use it in GitHub Desktop.
Internet Archive Incorrectly Wrapping Valid HTML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <script type="text/javascript" src="/static/js/analytics.js?v=1504952612.0" charset="utf-8"></script> | |
| <script type="text/javascript">archive_analytics.values.service = 'wb'; | |
| archive_analytics.values.server_name = 'wwwb-app42.us.archive.org'; | |
| archive_analytics.values.server_ms = 557;</script> | |
| <script type="text/javascript" src="/static/js/wbhack.js?v=1504952612.0" charset="utf-8"></script> | |
| <script type="text/javascript"> | |
| __wbhack.init('http://web.archive.org/web'); | |
| </script> | |
| <link rel="stylesheet" type="text/css" href="/static/css/banner-styles.css?v=1504952612.0"/> | |
| <link rel="stylesheet" type="text/css" href="/static/css/iconochive.css?v=1504952612.0"/> | |
| <!-- End Wayback Rewrite JS Include --> | |
| <link rel="import" href="../bower_components/polymer/polymer.html"> | |
| </head> | |
| <body> | |
| <dom-module id="news-data"> | |
| <script>(function () { | |
| var b = document.createElement('textarea'); | |
| Polymer({ | |
| is: 'news-data', | |
| properties: { | |
| categories: { | |
| type: Array, | |
| value: [ { name: 'top_stories', title: 'Top Stories' }, { | |
| name: 'doodles', | |
| title: 'Doodles' | |
| }, { name: 'chrome', title: 'Chrome' }, { name: 'search', title: 'Search' }, { | |
| name: 'shopping_payments', | |
| title: 'Shopping & Payments' | |
| }, { name: 'nonprofits', title: 'Nonprofits' } ], | |
| readOnly: !0, | |
| notify: !0 | |
| }, | |
| categoryName: String, | |
| articleId: String, | |
| offline: Boolean, | |
| loading: { type: Boolean, readOnly: !0, notify: !0 }, | |
| category: { type: Object, computed: '_computeCategory(categoryName)', notify: !0 }, | |
| article: { type: Object, computed: '_computeArticle(category.items, articleId)', notify: !0 }, | |
| failure: { type: Boolean, readOnly: !0, notify: !0 } | |
| }, | |
| observers: [ '_fetchCategory(category, offline)', '_fetchArticle(article, offline)' ], | |
| _computeArticle: function (d, f) { | |
| for (var h, g = 0; g < d.length; ++g) if (h = d[ g ], h.id === f) return h; | |
| return null | |
| }, | |
| _fetchArticle: function (d, f) {return f && d && d.html || !d || this.loading ? void this._setFailure(!1) : void this._fetch('data/articles/' + d.id + '.html', function (g) {this.set('article.html', this._formatHTML(g))}.bind(this), 1, !0)}, | |
| _computeCategory: function (d) { | |
| for (var g, f = 0; g = this.categories[ f ]; ++f) if (g.name === d) return g; | |
| return null | |
| }, | |
| _fetchCategory: function (d, f, g) {return f && d && d.items || !d || this.loading ? void this._setFailure(!1) : void this._fetch('/tests/polymer/data/' + d.name + '.json', function (h) {this.set('category.items', this._parseCategoryItems(h))}.bind(this), g || 1)}, | |
| _parseCategoryItems: function (d) { | |
| for (var h, f = [], g = 0; h = d[ g ]; ++g) f.push({ | |
| headline: this._unescapeText(h.title), | |
| href: this._getItemHref(h), | |
| id: h.id, | |
| imageUrl: this._getItemImage(h), | |
| placeholder: h.placeholder, | |
| category: h.category, | |
| timeAgo: this._timeAgo(new Date(h.time).getTime()), | |
| author: h.author, | |
| summary: this._trimRight(h.summary, 100), | |
| readTime: Math.max(2, Math.round(h.contentLength / 3e3)) + ' min read' | |
| }); | |
| return f | |
| }, | |
| _unescapeText: function (d) {return b.innerHTML = d, b.textContent}, | |
| _getItemHref: function (d) {return d.id ? '/article/' + this.categoryName + '/' + encodeURIComponent(d.id) : null}, | |
| _getItemImage: function (d) {return d.imgSrc ? 'data/' + d.imgSrc : ''}, | |
| _timeAgo: function (d) { | |
| if (!d) return ''; | |
| var f = (Date.now() - d) / 1e3 / 60; | |
| if (2 > f) return '1 min ago'; | |
| if (60 > f) return Math.floor(f) + ' mins ago'; | |
| if (120 > f) return '1 hour ago'; | |
| var g = f / 60; | |
| return 24 > g ? Math.floor(g) + ' hours ago' : 48 > g ? '1 day ago' : Math.floor(g / 24) + ' days ago' | |
| }, | |
| _trimRight: function (d, f) { | |
| var g = d.indexOf(' ', f); | |
| return -1 === g ? d : d.substr(0, g) + '...' | |
| }, | |
| _formatHTML: function (d) { | |
| var f = document.createElement('template'); | |
| f.innerHTML = d; | |
| for (var j, g = f.content.querySelectorAll('img'), h = 0; h < g.length; ++h) j = g[ h ], j.removeAttribute('width'), j.removeAttribute('height'); | |
| return f.content.querySelector('.content').innerHTML | |
| }, | |
| _fetch: function (d, f, g, h) { | |
| var j = new XMLHttpRequest; | |
| j.addEventListener('load', function (k) {this._setLoading(!1), h ? f(k.target.responseText) : f(JSON.parse(k.target.responseText))}.bind(this)), j.addEventListener('error', function () {1 < g ? this.debounce('_fetch', this._fetch.bind(this, d, f, g - 1), 200) : (this._setLoading(!1), this._setFailure(!0))}.bind(this)), this._setLoading(!0), this._setFailure(!1), j.open('GET', d), j.send() | |
| }, | |
| refresh: function () {this.categoryName && this._fetchCategory(this.category, this.offline, 3)} | |
| }) | |
| })();</script> | |
| </dom-module> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- | |
| @license | |
| Copyright (c) 2016 The Polymer Project Authors. All rights reserved. | |
| This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt | |
| The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | |
| The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt | |
| Code distributed by Google as part of the polymer project is also | |
| subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | |
| --> | |
| <link rel="import" href="../bower_components/polymer/polymer.html"> | |
| <dom-module id="news-data"> | |
| <script> | |
| (function() { | |
| var categoryList = [ | |
| {name: 'top_stories', title: 'Top Stories'}, | |
| {name: 'doodles', title: 'Doodles'}, | |
| {name: 'chrome', title: 'Chrome'}, | |
| {name: 'search', title: 'Search'}, | |
| {name: 'shopping_payments', title: 'Shopping & Payments'}, | |
| {name: 'nonprofits', title: 'Nonprofits'} | |
| ]; | |
| var textarea = document.createElement('textarea'); | |
| Polymer({ | |
| is: 'news-data', | |
| properties: { | |
| categories: { | |
| type: Array, | |
| value: categoryList, | |
| readOnly: true, | |
| notify: true | |
| }, | |
| categoryName: String, | |
| articleId: String, | |
| offline: Boolean, | |
| loading: { | |
| type: Boolean, | |
| readOnly: true, | |
| notify: true | |
| }, | |
| category: { | |
| type: Object, | |
| computed: '_computeCategory(categoryName)', | |
| notify: true | |
| }, | |
| article: { | |
| type: Object, | |
| computed: '_computeArticle(category.items, articleId)', | |
| notify: true | |
| }, | |
| failure: { | |
| type: Boolean, | |
| readOnly: true, | |
| notify: true | |
| } | |
| }, | |
| observers: [ | |
| '_fetchCategory(category, offline)', | |
| '_fetchArticle(article, offline)' | |
| ], | |
| _computeArticle: function(categoryItems, articleId) { | |
| for (var i = 0; i < categoryItems.length; ++i) { | |
| var article = categoryItems[i]; | |
| if (article.id === articleId) { | |
| return article; | |
| } | |
| } | |
| return null; | |
| }, | |
| _fetchArticle: function(article, offline) { | |
| // Don't fail if we become offline but already have a cached version, or if there's | |
| // nothing to fetch, or if already loading. | |
| if ((offline && article && article.html) || !article || this.loading) { | |
| this._setFailure(false); | |
| return; | |
| } | |
| this._fetch('data/articles/' + article.id + '.html', | |
| function(response) { | |
| this.set('article.html', this._formatHTML(response)); | |
| }.bind(this), | |
| 1 /* attempts */, true /* isRaw */); | |
| }, | |
| _computeCategory: function(categoryName) { | |
| for (var i = 0, c; c = this.categories[i]; ++i) { | |
| if (c.name === categoryName) { | |
| return c; | |
| } | |
| } | |
| return null; | |
| }, | |
| _fetchCategory: function(category, offline, attempts) { | |
| // Don't fail if we become offline but already have a cached version, or if there's | |
| // nothing to fetch, or if already loading. | |
| if ((offline && category && category.items) || !category || this.loading) { | |
| this._setFailure(false); | |
| return; | |
| } | |
| this._fetch('/tests/polymer/data/' + category.name + '.json', | |
| function(response) { | |
| this.set('category.items', this._parseCategoryItems(response)); | |
| }.bind(this), | |
| attempts || 1 /* attempts */); | |
| }, | |
| _parseCategoryItems: function(response) { | |
| var items = []; | |
| for (var i = 0, item; item = response[i]; ++i) { | |
| items.push({ | |
| headline: this._unescapeText(item.title), | |
| href: this._getItemHref(item), | |
| id: item.id, | |
| imageUrl: this._getItemImage(item), | |
| placeholder: item.placeholder, | |
| category: item.category, | |
| timeAgo: this._timeAgo(new Date(item.time).getTime()), | |
| author: item.author, | |
| summary: this._trimRight(item.summary, 100), | |
| readTime: Math.max(2, Math.round(item.contentLength / 3000)) + ' min read' | |
| }); | |
| } | |
| return items; | |
| }, | |
| _unescapeText: function(text) { | |
| textarea.innerHTML = text; | |
| return textarea.textContent; | |
| }, | |
| _getItemHref: function(item) { | |
| return item.id ? '/article/' + this.categoryName + '/' + encodeURIComponent(item.id) : null; | |
| }, | |
| _getItemImage: function(item) { | |
| return item.imgSrc ? 'data/' + item.imgSrc : ''; | |
| }, | |
| _timeAgo: function(timestamp) { | |
| if (!timestamp) | |
| return '' | |
| var minutes = (Date.now() - timestamp) / 1000 / 60; | |
| if (minutes < 2) | |
| return '1 min ago'; | |
| if (minutes < 60) | |
| return Math.floor(minutes) + ' mins ago'; | |
| if (minutes < 120) | |
| return '1 hour ago'; | |
| var hours = minutes / 60; | |
| if (hours < 24) | |
| return Math.floor(hours) + ' hours ago'; | |
| if (hours < 48) | |
| return '1 day ago'; | |
| return Math.floor(hours / 24) + ' days ago'; | |
| }, | |
| _trimRight: function(text, maxLength) { | |
| var breakIdx = text.indexOf(' ', maxLength); | |
| return breakIdx === -1 ? text : text.substr(0, breakIdx) + '...'; | |
| }, | |
| _formatHTML: function(html) { | |
| var template = document.createElement('template'); | |
| template.innerHTML = html; | |
| // Remove h1, .kicker, and .date from content. | |
| // var h1 = template.content.querySelector('h1'); | |
| // h1 && h1.remove(); | |
| // var kicker = template.content.querySelector('.kicker'); | |
| // kicker && kicker.remove(); | |
| // var date = template.content.querySelector('.date'); | |
| // date && date.remove(); | |
| // Remove the first image if it's the same as the item image. | |
| // var image = template.content.querySelector('img'); | |
| // if (image && this._isSameImageSrc(image.src, this.article.imageUrl)) { | |
| // image.remove(); | |
| // } | |
| // Remove width/height attributes from all images. | |
| var images = template.content.querySelectorAll('img'); | |
| for (var i = 0; i < images.length; ++i) { | |
| var img = images[i]; | |
| img.removeAttribute('width'); | |
| img.removeAttribute('height'); | |
| } | |
| return template.content.querySelector('.content').innerHTML; | |
| }, | |
| // _isSameImageSrc: function(a, b) { | |
| // var regex = /[^/]+\.(jpg|png|gif)/; | |
| // var aMatch = regex.exec(a); | |
| // var bMatch = regex.exec(b); | |
| // return aMatch && bMatch && aMatch[0] === bMatch[0]; | |
| // }, | |
| _fetch: function(url, callback, attempts, isRaw) { | |
| var xhr = new XMLHttpRequest(); | |
| xhr.addEventListener('load', function(e) { | |
| this._setLoading(false); | |
| if (isRaw) { | |
| callback(e.target.responseText); | |
| } else { | |
| callback(JSON.parse(e.target.responseText)); | |
| } | |
| }.bind(this)); | |
| xhr.addEventListener('error', function(e) { | |
| // Flaky connections might fail fetching resources | |
| if (attempts > 1) { | |
| this.debounce('_fetch', this._fetch.bind(this, url, callback, attempts - 1), 200); | |
| } else { | |
| this._setLoading(false); | |
| this._setFailure(true); | |
| } | |
| }.bind(this)); | |
| this._setLoading(true); | |
| this._setFailure(false); | |
| xhr.open('GET', url); | |
| xhr.send(); | |
| }, | |
| refresh: function() { | |
| if (this.categoryName) { | |
| // Try at most 3 times to get the items. | |
| this._fetchCategory(this.category, this.offline, 3); | |
| } | |
| } | |
| }); | |
| })(); | |
| </script> | |
| </dom-module> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment