Wikipedia Simple Redirect with Button

Provide a button to switch to Simple Wikipedia and back to Normal Wikipedia

当前为 2025-02-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Wikipedia Simple Redirect with Button
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Provide a button to switch to Simple Wikipedia and back to Normal Wikipedia
  6. // @author Drewby123
  7. // @match https://en.wikipedia.org/*
  8. // @match https://simple.wikipedia.org/*
  9. // @grant GM_addStyle
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Create a button to toggle between Simple and Normal Wikipedia
  17. const button = document.createElement('button');
  18. button.style.position = 'fixed';
  19. button.style.bottom = '20px';
  20. button.style.right = '20px';
  21. button.style.backgroundColor = '#007bff';
  22. button.style.color = '#fff';
  23. button.style.border = 'none';
  24. button.style.padding = '10px 15px';
  25. button.style.borderRadius = '5px';
  26. button.style.cursor = 'pointer';
  27. button.style.zIndex = '1000';
  28.  
  29. // Function to update the button text based on the current site
  30. function updateButtonText() {
  31. const currentUrl = window.location.href;
  32. if (currentUrl.includes('https://en.wikipedia.org/wiki/')) {
  33. button.textContent = 'Switch to Simple Wikipedia';
  34. } else if (currentUrl.includes('https://simple.wikipedia.org/wiki/')) {
  35. button.textContent = 'Switch to Normal Wikipedia';
  36. }
  37. }
  38.  
  39. // Add button to the page
  40. document.body.appendChild(button);
  41.  
  42. // Update the button text when the page loads
  43. updateButtonText();
  44.  
  45. // Function to toggle between Simple and Normal Wikipedia
  46. button.addEventListener('click', () => {
  47. const currentUrl = window.location.href;
  48. if (currentUrl.includes('https://en.wikipedia.org/wiki/')) {
  49. // Redirect to Simple Wikipedia
  50. const newUrl = currentUrl.replace('en.wikipedia.org', 'simple.wikipedia.org');
  51. window.location.href = newUrl;
  52. } else if (currentUrl.includes('https://simple.wikipedia.org/wiki/')) {
  53. // Redirect to Normal Wikipedia
  54. const newUrl = currentUrl.replace('simple.wikipedia.org', 'en.wikipedia.org');
  55. window.location.href = newUrl;
  56. }
  57. });
  58. })();