1

I am trying to make a small JavaScript code meant to be put in a bookmark on Google Chrome (So that it can easily be used on the console).

1) It is intended to look at a specific forum-type website I use where new posts appear dynamically on the page at a managably slow rate (1 every 5 or so minutes usually). I mainly want the script to check the page every few seconds for new posts that I haven't visited yet, and then navigate to a single unvisited post.

2) On the post's page I want it to click or otherwise activate an html button (each page will have the same button with an example id="enbut")

3) And afterwards go back to the main (static) page and wait for another post.

I am rather new to JavaScript, and I have a basic knowledge of html, but this type of thing is beyond me. (Sorry if my formatting is horrible, I'm still figuring it out)

I have come as far as:

javascript:
setInterval(function(){
    window.location.href = 'http://theforum.com/new-posts';

    document.getElementById('enbut').click()
}, 60000);

My main issue is recognizing and navigating to a single post on the page that I haven't visited yet, if anyone has a method to recognize unclicked/unvisited links and then navigate to them that would be the answer.

EDIT:

I have found a way to change the color of unvisited links to cyan using this code:

function addGlobalStyle(css) {
try {
    var elmHead, elmStyle;
    elmHead = document.getElementsByTagName('head')[0];
    elmStyle = document.createElement('style');
    elmStyle.type = 'text/css';
    elmHead.appendChild(elmStyle);
    elmStyle.innerHTML = css;
} catch (e) {
    if (!document.styleSheets.length) {
        document.createStyleSheet();
    }
    document.styleSheets[0].cssText += css;
}}

addGlobalStyle('a:visited { color: #837768 } a:link {color: #00adeb');

So now I need to find a way to navigate (in the same tab) to a link in the color #00ADEB. I am also worried with how it will decide which link to go to, since there will inevitably be situations where there is more than one unvisited link on the page.

SimpleMan
  • 23
  • 6
  • You can recognize unvisited posts the same way it is represented to you visually, through specific CSS classes placed on the DOM node. Inspect the DOM and see what classes differentiate visited vs unvisited nodes, then use javascript to find the node based on that class. – user2867288 Jun 23 '14 at 02:26
  • Err... I guess I'm assuming this forum is already keeping track of which posts you've visited for you. If not, CSS provides a pseudo-selector ":visited" for differentiating visited links. You can use this with a framework like jQuery. http://stackoverflow.com/questions/1210871/use-jquery-to-select-visited-links – user2867288 Jun 23 '14 at 02:33

0 Answers0