diff --git a/README.md b/README.md index 1aa2838..3e1a2e5 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,19 @@ Top 10 Reasons Only 90's Kids Won't Even Believe What This Extension Does! Build using professor Bill Laboon's Infinite Viral: [source](https://github.com/laboon/viral_gen), [site](http://infiniteviral.com/) -(Currently only works on the New York Times...) +Screens: -Screen: +This is your new existence: ![NYT Screenshot](/infiniteviralnytscreen.png?raw=true "New York Times") +![LA Times Screenshot](/infinitevirallatscreen.png?raw=true "LA Times") + +It even works on Buzzfeed! (Admittedly, this was hard to test for.) + +![Buzzfeed Screenshot](/infiniteviralbfscreen.png?raw=true "Buzzfeed") --- -Install +Download and install [chrome store link](https://chrome.google.com/webstore/detail/infinite-viral/gejghfapdoblkdeghocaggoalocccacg "on the chrome store") --- diff --git a/infiniteViral.js b/infiniteViral.js index 2d257ca..e15d05d 100644 --- a/infiniteViral.js +++ b/infiniteViral.js @@ -847,25 +847,33 @@ } //alright, generate the headlines! + //get a headline with: generate(); + //find the title on the page + //this is tricky, because their's no standard headlines + //so look through all likely element classes for keywords + //right now it assumes a pretty semantic DOM (function() { - //get a headline with: var headline = generate(); - //find the title on the page - //this is trick, because their's no standard for defining - // what this looks like - //so... look through all classes and elastic search? - //TODO: hard-coded for now... - //if there is a , go a level deep, if not just find the (no always h1...) - //check if the thing with the class is an h1 or div... (only find h1s?) only find a tags? Then go by news orgs? - var headings = Array.prototype.slice.call(document.querySelectorAll('.story-heading')); - - //var nodes = Array.prototype.slice.call(master.getElementsByTagName("*"), 0); - for(var i = 0; i < headings.length; i ++) { - if(headings[i].childNodes && headings[i].childNodes[0].tagName === 'A') { - headings[i].childNodes[0].textContent = generate(); - } - else { - headings[i].textContent = generate(); - } - }; + var headings = Array.prototype.slice.call(document.querySelectorAll('h1, h2, h3, h4, h5, h6, a')).map( + function(heading) { + if(heading.className.toLowerCase().indexOf('story') > -1 || + heading.className.toLowerCase().indexOf('headline') > -1 || + heading.className.toLowerCase().indexOf('title') > -1 || + heading.className.toLowerCase().indexOf('lede') > -1) { + + if(heading.tagName === 'A' && /\S/.test(heading.innerText)) { + heading.innerText = generate(); + } + 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(); + } + else { + heading.innerText = generate(); + } + } + } + }); })(); diff --git a/infiniteviralbfscreen.png b/infiniteviralbfscreen.png new file mode 100644 index 0000000..653716d Binary files /dev/null and b/infiniteviralbfscreen.png differ diff --git a/infinitevirallatscreen.png b/infinitevirallatscreen.png new file mode 100644 index 0000000..e2efbb0 Binary files /dev/null and b/infinitevirallatscreen.png differ diff --git a/manifest.json b/manifest.json index c175225..ca8f10a 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "name": "Infinite Viral", "description": "Viral news all the time.", - "version": "1.0", + "version": "1.1.0", "browser_action": { "default_icon": "icon.png",