Google Colab Redirect Bypass

Bypass redirect notice in Google Colab to access external links directly

  1. // ==UserScript==
  2. // @name Google Colab Redirect Bypass
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @description Bypass redirect notice in Google Colab to access external links directly
  6. // @author kalin, ChatGPT
  7. // @match https://www.google.com/url?*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Check if the current page is the "Redirect Notice" page
  16. const isRedirectPage = () => {
  17. return document.title === 'Redirect Notice' &&
  18. document.body.innerHTML.includes('The previous page is sending you to');
  19. };
  20.  
  21. // Jump to the target link automatically
  22. const redirectToTargetLink = () => {
  23. const linkElement = document.querySelectorAll('a[href^="http://"], a[href^="https://"]');
  24. if (linkElement.length > 0) {
  25. window.location.href = linkElement[0].href; // 自动跳转
  26. }
  27. };
  28.  
  29. // Detect the change of the page
  30. const observer = new MutationObserver(() => {
  31. if (isRedirectPage()) {
  32. redirectToTargetLink();
  33. }
  34. });
  35.  
  36. // Initialize the observation
  37. window.addEventListener('load', () => {
  38. if (isRedirectPage()) {
  39. redirectToTargetLink();
  40. }
  41. observer.observe(document.body, { childList: true, subtree: true });
  42. });
  43. })();