StayCached

Keeps you in Google cache when you click links on cached pages.

目前为 2015-10-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name StayCached
  3. // @name:pl StayCached
  4. // @namespace mailto:szopgracz@op.pl
  5. // @author Szop Gracz
  6. // @description Keeps you in Google cache when you click links on cached pages.
  7. // @description:pl Po kliknięciu odnośnika na kopii strony od Google, przenosi do kopii strony docelowej a nie do oryginału.
  8. // @match *://webcache.googleusercontent.com/*
  9. // @version 1.2
  10. // ==/UserScript==
  11.  
  12.  
  13. const enabled_protocols = ['http','https','ftp','ftps'];
  14.  
  15. const cache_header = document.getElementById('google-cache-hdr');
  16.  
  17. document.body.addEventListener('click',
  18. function(e)
  19. {
  20. var target = e.target || e.srcElement;
  21. if ( !target || cache_header.contains(target) ) return;
  22. while ( !target.href && target.parentNode )
  23. target = target.parentNode;
  24. if ( target.href )
  25. {
  26. const target_protocol = target.href.substr(0,target.href.search(':'));
  27. if ( enabled_protocols.indexOf(target_protocol)>=0 && !target.href.match('^http://webcache.googleusercontent.com/') && !target.href.match('^https://webcache.googleusercontent.com/') )
  28. target.href = location.protocol + '//webcache.googleusercontent.com/search?q=cache:' + target.href.replace(/\+/g, '%2B');
  29. }
  30. }
  31. );