Wikipedia Simple Redirect with Button

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

  1. // ==UserScript==
  2. // @name Wikipedia Simple Redirect with Button
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  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. // @match https://en.m.wikipedia.org/*
  10. // @match https://simple.m.wikipedia.org/*
  11. // @grant GM_addStyle
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // Create a button to toggle between Simple and Normal Wikipedia
  19. const button = document.createElement('button');
  20. button.style.position = 'fixed';
  21. button.style.bottom = '20px';
  22. button.style.right = '20px';
  23. button.style.backgroundColor = '#007bff';
  24. button.style.color = '#fff';
  25. button.style.border = 'none';
  26. button.style.padding = '12px 18px'; // Slightly larger padding for easier tapping
  27. button.style.borderRadius = '8px'; // Slightly rounder corners for better design
  28. button.style.cursor = 'pointer';
  29. button.style.zIndex = '1000';
  30. button.style.fontSize = '14px'; // Ensure text is readable on smaller screens
  31. button.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.3)'; // Add shadow for visibility
  32.  
  33. // Adjust button size for small screens
  34. if (window.innerWidth <= 600) {
  35. button.style.padding = '10px 15px'; // Smaller padding on very small screens
  36. button.style.fontSize = '12px'; // Adjust font size for small screens
  37. }
  38.  
  39. // Function to update the button text based on the current site
  40. function updateButtonText() {
  41. const currentUrl = window.location.href;
  42. if (currentUrl.includes('https://en.wikipedia.org/wiki/')) {
  43. button.textContent = 'Switch to Simple Wikipedia';
  44. } else if (currentUrl.includes('https://simple.wikipedia.org/wiki/')) {
  45. button.textContent = 'Switch to Normal Wikipedia';
  46. } else if (currentUrl.includes('https://en.m.wikipedia.org/wiki/')) {
  47. button.textContent = 'Switch to Simple Wikipedia Mobile';
  48. } else if (currentUrl.includes('https://simple.m.wikipedia.org/wiki/')) {
  49. button.textContent = 'Switch to Normal Wikipedia Mobile';
  50. }
  51. }
  52.  
  53. // Add button to the page
  54. document.body.appendChild(button);
  55.  
  56. // Update the button text when the page loads
  57. updateButtonText();
  58.  
  59. // Function to toggle between Simple and Normal Wikipedia
  60. button.addEventListener('click', () => {
  61. const currentUrl = window.location.href;
  62. if (currentUrl.includes('https://en.wikipedia.org/wiki/')) {
  63. // Redirect to Simple Wikipedia
  64. const newUrl = currentUrl.replace('en.wikipedia.org', 'simple.wikipedia.org');
  65. window.location.href = newUrl;
  66. } else if (currentUrl.includes('https://simple.wikipedia.org/wiki/')) {
  67. // Redirect to Normal Wikipedia
  68. const newUrl = currentUrl.replace('simple.wikipedia.org', 'en.wikipedia.org');
  69. window.location.href = newUrl;
  70. } else if (currentUrl.includes('https://en.m.wikipedia.org/wiki/')) {
  71. // Redirect to Simple Wikipedia Mobile
  72. const newUrl = currentUrl.replace('en.m.wikipedia.org', 'simple.m.wikipedia.org');
  73. window.location.href = newUrl;
  74. } else if (currentUrl.includes('https://simple.m.wikipedia.org/wiki/')) {
  75. // Redirect to Normal Wikipedia Mobile
  76. const newUrl = currentUrl.replace('simple.m.wikipedia.org', 'en.m.wikipedia.org');
  77. window.location.href = newUrl;
  78. }
  79. });
  80. })();