3

I am writing a userscript for myself and i have a list of permalinks and i'd like to hide the ones i already visited. I was thinking i can use jquery and check if the link has been visited (default color=purple) and if so hide the element.

However... i cant figure out how to actually check this. .attr('style'); only gets me border: none while .css() is invalid.

How might i check if the link has been clicked on? I am testing on firefox 4.0.1 with greasemonkey but i'll be using it on chrome.

3 Answers3

5

The color checking shouldn't work anymore. Since this security flaw is fixed.

Johni
  • 2,933
  • 4
  • 28
  • 47
  • 1
    Thats a security flaw!?! even in a userscript? i know firefox lets certain things slide with userscripts –  Aug 16 '11 at 15:14
  • 1
    I think Johni means privacy issue. AFAIK, there was no security issues with this, it just exposes your personal information. – sligocki Dec 05 '12 at 18:18
4

a:visited is the selector you are looking for. This will return all visited links in the document.

a:visited {display: none;}
Josh
  • 376
  • 1
  • 8
  • And `a:visited { display: none; }` or `:link:visited { display: none; }` will hide them. – feeela Aug 16 '11 at 15:08
  • How would i do that with jquery? cc @feeela –  Aug 16 '11 at 15:14
  • 1
    @Josh: Nice but I notice two problems. 1) Firefox doesnt seem to allow me to do this. 2nd) I need some type of rule to hide the block when the link has been visited rather then the link itself. –  Aug 16 '11 at 15:32
  • "How would i do that with jquery?" you get 1 lulz. – Knu Aug 16 '11 at 19:25
0

Would it be easier to inject a a:visited { display: none; } rule?

Something like this in your Greasemonkey script:

var head = document.getElementsByTagName('head')[0];

var style = document.createElement('style');

style.type = 'text/css';
style.innerHTML = 'a:visited { display: none }';

head.appendChild(style);
Dave Ward
  • 59,815
  • 13
  • 117
  • 134
  • oh yeah d'uh that would be much easier. Ok so how do i inject it to the page? Do i write it in? i'd want `div.box a.item:visited {display: none; }`. How would i insert that with jquery –  Aug 16 '11 at 15:13
  • Cool. I notice two problems. 1) Firefox doesnt seem to allow me to do this. `style.innerHTML = 'a { display: none }';` works but :visited does not. 2nd) I need the block to hide rather then the link itself. –  Aug 16 '11 at 15:31
  • What do you mean by it doesn't allow you? What do you mean by hiding the "block"? Something outside the link itself? Can you update your question with more detail? – Dave Ward Aug 16 '11 at 15:35
  • I think i may just inject code to call a function when i click a link and use local storage to check if a link has been clicked. I mean the div that holds the title, desc, etc of the link should disappear when i click the link. But i dont think i can do this anymore. css color in firefox gives me the same value if its clicked or not. When i say it wont allow me to do it i mean a:visited { display:none; } doesnt match any results thus hides nothing –  Aug 16 '11 at 15:45
  • The reason you can't test for the CSS color is that Firefox proactively blocks access to the computed style of links. Otherwise, a site can hide hundreds or thousands of links on their pages, test the computed style of them, and effectively have access to your browsing history. Not good. – Dave Ward Aug 16 '11 at 16:34
  • I dont really see a harm in that but i understand why that may be blocked. I just have to do more work for my script which is a pity –  Aug 16 '11 at 18:50