The Battle Cats Fandom --> Miraheze

Redirects The Battle Cats Fandom wiki to the new Miraheze wiki.

  1. // ==UserScript==
  2. // @name The Battle Cats Fandom --> Miraheze
  3. // @namespace https://github.com/dinosw
  4. // @version 0.2
  5. // @description Redirects The Battle Cats Fandom wiki to the new Miraheze wiki.
  6. // @author dinosw
  7. // @match https://battle-cats.fandom.com/wiki/*
  8. // @match *://*.fandom.com/*
  9. // @grant none
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Function to check if a URL is a Battle Cats Fandom page
  17. function isFandomPage(url) {
  18. return url.startsWith("https://battle-cats.fandom.com/wiki/");
  19. }
  20.  
  21. // Function to perform the redirect to the new Miraheze URL
  22. function redirectToMiraheze(url) {
  23. const pageName = url.replace("https://battle-cats.fandom.com/wiki/", "");
  24. const newUrl = `https://battlecats.miraheze.org/wiki/${pageName}`;
  25. window.location.replace(newUrl); // Immediate redirect
  26. }
  27.  
  28. // Check if the current page is a Fandom page and redirect on load
  29. if (isFandomPage(window.location.href)) {
  30. // Stop the page from fully loading by redirecting before it does
  31. redirectToMiraheze(window.location.href);
  32. }
  33.  
  34. // Handle link clicks to redirect immediately
  35. document.addEventListener('click', function(event) {
  36. let target = event.target;
  37.  
  38. // Check if the clicked element is a link (anchor tag)
  39. if (target && target.tagName === 'A' && target.href) {
  40. const linkUrl = target.href;
  41.  
  42. // If it's a Battle Cats Fandom page, redirect
  43. if (isFandomPage(linkUrl)) {
  44. event.preventDefault(); // Prevent the default action (open the link)
  45. redirectToMiraheze(linkUrl);
  46. }
  47. }
  48. });
  49. })();

QingJ © 2025

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