Wayback Machine Favicon Fixer

Attempts to add a favicon to a site crawled by the Wayback Machine in the event one does not come up normally

当前为 2016-10-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Wayback Machine Favicon Fixer
  3. // @namespace DoomTay
  4. // @description Attempts to add a favicon to a site crawled by the Wayback Machine in the event one does not come up normally
  5. // @version 1.2.0
  6. // @include http://web.archive.org/web/*
  7. // @include http://wayback.archive.org/web/*
  8. // @include https://web.archive.org/web/*
  9. // @include https://wayback.archive.org/web/*
  10. // @exclude /\*/
  11. // @grant none
  12. // @noframes
  13.  
  14. // ==/UserScript==
  15.  
  16. var domain = window.location.href.substring(0,window.location.href.indexOf("/",window.location.href.lastIndexOf("//") + 2) + 1);
  17. var timestamp = /web\/(\d{1,14})/.exec(window.location.href)[1];
  18.  
  19. var originalDomain = domain.substring(domain.lastIndexOf("http"));
  20.  
  21. if(!document.querySelector("link[rel~='icon']") && document.contentType == "text/html") retrieveFavicon();
  22.  
  23. function retrieveFavicon()
  24. {
  25. function applyFavicon(data)
  26. {
  27. if (data.archived_snapshots && data.archived_snapshots.closest && data.archived_snapshots.closest.available)
  28. {
  29. var newFavicon = document.createElement('link');
  30. newFavicon.type = 'image/x-icon';
  31. newFavicon.rel = 'shortcut icon';
  32. newFavicon.href = data.archived_snapshots.closest.url;
  33. document.head.appendChild(newFavicon);
  34. }
  35. }
  36. var applyFaviconScript = document.createElement("script");
  37. applyFaviconScript.type = "text/javascript";
  38. applyFaviconScript.innerHTML = applyFavicon;
  39. document.head.appendChild(applyFaviconScript);
  40. var faviconScript = document.createElement("script");
  41. faviconScript.type = "application/javascript";
  42. faviconScript.src = "http://archive.org/wayback/available?url=" + encodeURI(originalDomain + "favicon.ico") + "&timestamp=" + timestamp + "&callback=applyFavicon";
  43. document.head.appendChild(faviconScript);
  44. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址