Greasy Fork 还支持 简体中文。

Wikipedia Simple Redirect with Button

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

目前為 2025-02-27 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Wikipedia Simple Redirect with Button
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  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 = '12px 18px'; // Slightly larger padding for easier tapping
  25. button.style.borderRadius = '8px'; // Slightly rounder corners for better design
  26. button.style.cursor = 'pointer';
  27. button.style.zIndex = '1000';
  28. button.style.fontSize = '14px'; // Ensure text is readable on smaller screens
  29. button.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.3)'; // Add shadow for visibility
  30.  
  31. // Adjust button size for small screens
  32. if (window.innerWidth <= 600) {
  33. button.style.padding = '10px 15px'; // Smaller padding on very small screens
  34. button.style.fontSize = '12px'; // Adjust font size for small screens
  35. }
  36.  
  37. // Function to update the button text based on the current site
  38. function updateButtonText() {
  39. const currentUrl = window.location.href;
  40. if (currentUrl.includes('https://en.wikipedia.org/wiki/')) {
  41. button.textContent = 'Switch to Simple Wikipedia';
  42. } else if (currentUrl.includes('https://simple.wikipedia.org/wiki/')) {
  43. button.textContent = 'Switch to Normal Wikipedia';
  44. }
  45. }
  46.  
  47. // Add button to the page
  48. document.body.appendChild(button);
  49.  
  50. // Update the button text when the page loads
  51. updateButtonText();
  52.  
  53. // Function to toggle between Simple and Normal Wikipedia
  54. button.addEventListener('click', () => {
  55. const currentUrl = window.location.href;
  56. if (currentUrl.includes('https://en.wikipedia.org/wiki/')) {
  57. // Redirect to Simple Wikipedia
  58. const newUrl = currentUrl.replace('en.wikipedia.org', 'simple.wikipedia.org');
  59. window.location.href = newUrl;
  60. } else if (currentUrl.includes('https://simple.wikipedia.org/wiki/')) {
  61. // Redirect to Normal Wikipedia
  62. const newUrl = currentUrl.replace('simple.wikipedia.org', 'en.wikipedia.org');
  63. window.location.href = newUrl;
  64. }
  65. });
  66. })();