click_confirm

Confirm if you want to follow certain links.

  1. // ==UserScript==
  2. // @name click_confirm
  3. // @namespace links
  4. // @description Confirm if you want to follow certain links.
  5. // @include *
  6. // @version 1
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. // here's the message that will popup asking if you really want to go there
  11. var que = 'You clicked on a link to a stupid site. \nDo you really want to go there?'
  12. // gets all links on the page
  13. var links = document.getElementsByTagName('a');
  14.  
  15. // iterate through links on the page
  16. for (var i = 0; i < links.length; i++) {
  17. var link = links[i];
  18. // if site1 OR site2 OR etc., you can also use fancier regex if you only want to avoid certain parts of the site
  19. if (
  20. (/dailykos/.test(link.href))
  21. || (/democraticunderground/.test(link.href))
  22. // || (/insertregexhere/.test(link.href))
  23. ) {
  24. link.addEventListener('click', function(clk) {
  25. var b = confirm(que);
  26. // if the link matches one of the regex strings above
  27. if (b==true) {/* do nothing, i.e., follow the link */}
  28. else {
  29. clk.preventDefault(/* prevent your click from opening the link */);
  30. }
  31. }, false);
  32. }
  33. }