Greasy Fork is available in English.

Wayback Machine Small Bug Fixes

Fixes encoded ampersands on Wayback Machine's captures graph and problems that arise when trailing slashes are missing in an URL

Fra 03.01.2016. Se den seneste versjonen.

  1. // ==UserScript==
  2. // @name Wayback Machine Small Bug Fixes
  3. // @namespace DoomTay
  4. // @description Fixes encoded ampersands on Wayback Machine's captures graph and problems that arise when trailing slashes are missing in an URL
  5. // @version 1.1.0
  6. // @include http://web.archive.org/web/*
  7. // @include https://web.archive.org/web/*
  8. // @grant none
  9.  
  10. // ==/UserScript==
  11.  
  12. var toolbarNav = document.getElementById("wm-graph-anchor");
  13. var shouldHaveTrailingSlash = window.location.href.lastIndexOf("/") > -1 && window.location.href.lastIndexOf(".") < window.location.href.lastIndexOf("/");
  14. var hasTrailingSlash = window.location.href.lastIndexOf("/") == window.location.href.length - 1;
  15. var pics = document.images;
  16. var links = document.links;
  17. var lastFolder = window.location.href.substring(window.location.href.lastIndexOf("/") + 1);
  18.  
  19. function fixLink()
  20. {
  21. while(toolbarNav.href.indexOf("&amp;") > -1) toolbarNav.href = toolbarNav.href.replace("&amp;","&");
  22. }
  23.  
  24. if(toolbarNav) fixLink();
  25.  
  26. if(shouldHaveTrailingSlash && !hasTrailingSlash)
  27. {
  28. for(var l = 0; l < links.length; l++)
  29. {
  30. //Skip over stuff related to the Wayback Machine toolbar and data URIs
  31. if((document.getElementById("wm-ipp") && document.getElementById("wm-ipp").contains(links[l]))) continue;
  32. if(links[l].hash) continue;
  33. links[l].href = lastFolder + "/" + relativeToAbsolute(links[l].href);
  34. }
  35. for(var i = 0; i < pics.length; i++)
  36. {
  37. //Skip over stuff related to the Wayback Machine toolbar and data URIs
  38. if((document.getElementById("wm-ipp") && document.getElementById("wm-ipp").contains(pics[i])) || pics[i].src.indexOf("data:") > -1) continue;
  39. pics[i].src = lastFolder + "/" + relativeToAbsolute(pics[i].src);
  40. }
  41. }
  42.  
  43. function relativeToAbsolute(url)
  44. {
  45. return url.substring(url.indexOf(window.location.href) + window.location.href.length - (lastFolder.length - 1));
  46. }
  47.  
  48. var observer = new MutationObserver(function(mutations) {
  49. mutations.forEach(function(mutation) {
  50. if(mutation.type == "attributes") fixLink();
  51. });
  52. });
  53.  
  54. var config = { attributes: true, childList: true, characterData: true, subtree: true, attributeFilter: ["href"] };
  55. observer.observe(toolbarNav, config);