Posted By

wizard04 on 09/23/08


Tagged

javascript snipplr greasemonkey


Versions (?)

Snipplr Plain/Highlighted Text Greasemonkey Script


 / Published in: JavaScript
 

When you're viewing an older version of a snippet, the Plain Text and Highlighted Text links point back to the latest version. This greasemonkey script fixes those links to point to the version you're currently viewing.

  1. // ==UserScript==
  2. // @name Fix Snippet's Plain/Highlighted Text link
  3. // @author Andy Harrison
  4. // @namespace http://dragonzreef.com/greasemonkey/snipplr_plainhighlighted.user.js
  5. // @description When viewing a snippet, fixes the Plain/Highligted Text link to go to the version you're looking at instead of the latest version.
  6. // @include http://snipplr.com/view*
  7. // ==/UserScript==
  8.  
  9. window.addEventListener("load", function()
  10. {
  11. var viewbar = document.getElementById("viewsource");
  12. if(!viewbar) return;
  13. var a = viewbar.getElementsByTagName("a");
  14. for(var i=0; i<a.length; i++)
  15. {
  16. if(a[i].innerHTML == "Plain Text")
  17. {
  18. a[i].href += document.location.href.replace(/^http:\/\/snipplr.com\/view\/\d+(\.\d+).*$|.*/,"$1");
  19. return;
  20. }
  21. else if(a[i].innerHTML == "Highlighted Text")
  22. {
  23. var vers = document.location.href.replace(/^http:\/\/snipplr.com\/view.php\?([^#]*&)*?id=\d+(\.\d+).*$|.*/,"$2");
  24. a[i].href = a[i].href.replace(/^(http:\/\/snipplr.com\/view\/\d+)(.*)$/, "$1"+vers+"$2");
  25. return;
  26. }
  27. }
  28. }, false);

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: wizard04 on March 10, 2010

Updated.

You need to login to post a comment.