Skip to content
This repository has been archived by the owner on Mar 28, 2021. It is now read-only.

Commit

Permalink
Much improved functionality! Now works with the Wash Post!
Browse files Browse the repository at this point in the history
  • Loading branch information
vonbearshark committed Sep 19, 2015
1 parent 52cce10 commit c6e8acc
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions infiniteViral.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@
//so look through all likely element classes for keywords
//right now it assumes a pretty semantic DOM
(function() {
var headings = Array.prototype.slice.call(document.querySelectorAll('h1, h2, h3, h4, h5, h6, a')).map(
var headings = Array.prototype.slice.call(document.querySelectorAll('div, h1, h2, h3, h4, h5, h6, a')).map(
function(heading) {
if(heading.className.toLowerCase().indexOf('story') > -1 ||
heading.className.toLowerCase().indexOf('headline') > -1 ||
Expand All @@ -865,11 +865,22 @@
}
else if (heading.tagName !== 'A'){
//TODO: Assumes first child link is the article heading
var links = Array.prototype.slice.call(heading.querySelectorAll('a'));
if(links.length > 0) {
links[0].innerText = generate();
var immediateLinkChild = Array.prototype.slice.call(heading.querySelectorAll('a'))[0];
if(immediateLinkChild) {
//Shouldn't alter inner text if there's an child image tag
var immediateImgChildren = Array.prototype.slice.call(immediateLinkChild.querySelectorAll('img'));
if(!immediateImgChildren.length > 0) {
console.log('no nested image in link child!');
console.log(immediateImgChildren);
immediateLinkChild.innerText = generate();
}
else {
console.log('nested image in link child!');
console.log(immediateImgChildren);
}
}
else {
else if (heading.tagName !== 'DIV') {
console.log('not div!');
heading.innerText = generate();
}
}
Expand Down

0 comments on commit c6e8acc

Please sign in to comment.