deAMP

AMP sucks, thus no AMP thanks.

目前为 2022-09-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name deAMP
  3. // @description AMP sucks, thus no AMP thanks.
  4. // @author Jason Kwok
  5. // @namespace https://jasonhk.dev/
  6. // @version 1.0.0
  7. // @license MIT
  8. // @match http*://*/*
  9. // @run-at document_end
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. const isAmp = (document.querySelector("html[⚡], html[amp]") !== null);
  14. const canonical = document.head.querySelector("link[rel=canonical][href]");
  15.  
  16. if (isAmp && (canonical !== null))
  17. {
  18. const lastVisit = sessionStorage.getItem("deAmp.lastVisit");
  19.  
  20. if (location.href !== lastVisit)
  21. {
  22. sessionStorage.setItem("deAmp.lastVisit", location.href);
  23. location.replace(canonical.href);
  24. }
  25. else
  26. {
  27. sessionStorage.removeItem("deAmp.lastVisit");
  28. }
  29. }
  30. else
  31. {
  32. console.debug("[deAMP] Not a valid AMP page.");
  33. sessionStorage.removeItem("deAmp.lastVisit");
  34. }