fsteinerhm.edu / Visited Reddit Posts/Comments

// ==UserScript==
// @name         Visited_Reddit_PostsComments
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  try to take over the world!
// @author       You
// @match        https://*/*
// @match        http://*/*
// @grant        GM_getValue
// @grant        GM_setValue
// @run-at       document-end
// ==/UserScript==

////console.log(location.pathname);
//if(location.pathname.search("comments/")!=-1)
//{
//GM_setValue("redditVisisted","");
//GM_setValue("redditVisisted", GM_getValue("redditVisisted","")+window.location+";");
////console.log(GM_getValue("redditVisisted",""));
////console.log("comments")    ;
//}
//else
//{
// con = document.getElementById("siteTable");
//    con.childNodes.forEach(checkRead);
//console.log(GM_getValue("redditVisisted",""));
// console.log("subreddit");
//}


//function checkRead(element,index,array)
//{
//   if(element.classList.contains("thing"))
//   {
//       if(GM_getValue("redditVisisted","").search(element.getElementsByClassName("entry")[0].getElementsByClassName("flat-list")[0].getElementsByClassName("first")[0].getElementsByTagName("a")[0].getAttribute("href").toString())!=-1)
//       {
//           console.log("asd");
//           element.classList.add("read");
//       }
//   }
//}

//var styleNode = document.createElement("style");
//styleNode.innerHTML = ".read { background: lemonchiffon; }";
//document.body.appendChild(styleNode);



if(document.referrer.toString().indexOf("reddit.com") !=-1 && GM_getValue("redditVisisted","").indexOf(window.location.href)==-1)
{
    GM_setValue("redditVisisted", GM_getValue("redditVisisted","")+window.location.href+";");
  //  console.log("added");
    
}


if(window.location.toString().indexOf("reddit.com/r")!=-1 && window.location.toString().indexOf("comments") ==-1)
{
    if( document.getElementById("siteTable")!==null)
    {
        con = document.getElementById("siteTable");
        con.childNodes.forEach(checkRead);
    }

var styleNode = document.createElement("style");
styleNode.innerHTML = ".read { background: lemonchiffon; }";
document.body.appendChild(styleNode);
}

function checkRead(element,index,array)
{
   if(element.classList.contains("thing"))
   {
       
       //console.log(element.getAttribute("data-url").toString());
       if(GM_getValue("redditVisisted","").indexOf(element.getAttribute("data-url").toString())!=-1)
       {
           element.classList.add("read");
       }
   }
}