🏠 返回首頁 

Greasy Fork is available in English.

OLD REDDIT GALLERY REDIRECT

Removes /gallery/ from old.reddit.com links and redirects to valid link.


安装此脚本?
  1. // ==UserScript==
  2. // @name OLD REDDIT GALLERY REDIRECT
  3. // @version 1.0
  4. // @description Removes /gallery/ from old.reddit.com links and redirects to valid link.
  5. // @author minnie
  6. // @match https://old.reddit.com/gallery/*
  7. // @grant none
  8. // @run-at document-start
  9. // @license MIT
  10. // @namespace https://greasyfork.org/users/1101475
  11. // ==/UserScript==
  12. /**
  13. * Updates the URL by removing "/gallery/" from the path.
  14. * @param {string} url - The URL to update.
  15. * @returns {string} - The updated URL without "/gallery/".
  16. */
  17. function removeGallery(url) {
  18. try {
  19. const target = new URL(url);
  20. // Remove "/gallery/" from the path
  21. if (target.pathname.includes('/gallery/')) {
  22. target.pathname = target.pathname.replace('/gallery/', '/');
  23. return target.href;
  24. }
  25. return url;
  26. } catch (e) {
  27. console.error('Error processing URL:', e);
  28. return url; // Return original URL on failure
  29. }
  30. }
  31. // Immediately process and redirect if necessary
  32. (function() {
  33. const currentUrl = window.location.href;
  34. const updatedUrl = removeGallery(currentUrl);
  35. // Redirect if the URL was changed
  36. if (updatedUrl !== currentUrl) {
  37. window.location.assign(updatedUrl);
  38. }
  39. })();