Greasy Fork 还支持 简体中文。

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

目前為 2016-01-03 提交的版本,檢視 最新版本

  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.1
  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. if(links[l].href.indexOf(window.location.href) == -1) continue;
  34. links[l].href = lastFolder + "/" + relativeToAbsolute(links[l].href);
  35. }
  36. for(var i = 0; i < pics.length; i++)
  37. {
  38. //Skip over stuff related to the Wayback Machine toolbar and data URIs
  39. if((document.getElementById("wm-ipp") && document.getElementById("wm-ipp").contains(pics[i])) || pics[i].src.indexOf("data:") > -1) continue;
  40. pics[i].src = lastFolder + "/" + relativeToAbsolute(pics[i].src);
  41. }
  42. }
  43.  
  44. function relativeToAbsolute(url)
  45. {
  46. return url.substring(url.indexOf(window.location.href) + window.location.href.length - (lastFolder.length - 1));
  47. }
  48.  
  49. var observer = new MutationObserver(function(mutations) {
  50. mutations.forEach(function(mutation) {
  51. if(mutation.type == "attributes") fixLink();
  52. });
  53. });
  54.  
  55. var config = { attributes: true, childList: true, characterData: true, subtree: true, attributeFilter: ["href"] };
  56. observer.observe(toolbarNav, config);