Mythos Webpage Editor

The "Mythos Webpage Editor" script adds a Greek mythology-themed floating toolbar to webpages, enabling text editing with undo/redo options and customizable button positions. It also reveals font family details on copy, ideal for website designers and branding professionals seeking a unique, efficient editing tool.

当前为 2024-08-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Mythos Webpage Editor
  3. // @namespace https://aveusaid.wordpress.com
  4. // @version 1.x
  5. // @description The "Mythos Webpage Editor" script adds a Greek mythology-themed floating toolbar to webpages, enabling text editing with undo/redo options and customizable button positions. It also reveals font family details on copy, ideal for website designers and branding professionals seeking a unique, efficient editing tool.
  6. // @author Usaid bin Khalid Khan
  7. // @match *://*/*
  8. // @grant none
  9. // @license CC BY-NC-ND 4.0 - https://creativecommons.org/licenses/by-nc-nd/4.0/
  10.  
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const websiteUrl = 'https://aveusaid.wordpress.com';
  17. let isEditingEnabled = false;
  18. let editButton;
  19. let toolbar;
  20.  
  21. // Enable editing mode
  22. const enableEditing = () => {
  23. document.querySelectorAll('*').forEach(elem => elem.setAttribute('contenteditable', 'true'));
  24. document.addEventListener('copy', handleCopy); // Add copy event listener
  25. isEditingEnabled = true;
  26. editButton.textContent = 'Deactivate Mythos';
  27. editButton.style.backgroundColor = '#ff6347'; // Hades' Flame
  28. showToolbar(); // Show toolbar when enabling editing
  29. };
  30.  
  31. // Disable editing mode
  32. const disableEditing = () => {
  33. document.querySelectorAll('*').forEach(elem => elem.setAttribute('contenteditable', 'false'));
  34. document.removeEventListener('copy', handleCopy); // Remove copy event listener
  35. isEditingEnabled = false;
  36. editButton.textContent = 'Activate Mythos';
  37. editButton.style.backgroundColor = '#1e90ff'; // Athena's Wisdom
  38. hideToolbar(); // Hide toolbar when disabling editing
  39. };
  40.  
  41. // Toggle between enabling and disabling editing
  42. const toggleEditing = () => {
  43. if (isEditingEnabled) {
  44. disableEditing();
  45. } else {
  46. enableEditing();
  47. }
  48. };
  49.  
  50. // Handle copy event to include font family in clipboard
  51. const handleCopy = (event) => {
  52. const selection = window.getSelection();
  53. const selectedText = selection.toString();
  54.  
  55. if (selectedText) {
  56. const range = selection.getRangeAt(0);
  57. const fontFamily = getComputedStyle(range.startContainer.parentElement).fontFamily;
  58. const textWithFont = `${selectedText}\n\nFont Family: ${fontFamily}`;
  59.  
  60. // Modify clipboard data to include font family
  61. event.clipboardData.setData('text/plain', textWithFont);
  62. event.preventDefault();
  63. }
  64. };
  65.  
  66. // Create and style the edit button
  67. const createEditButton = () => {
  68. editButton = document.createElement('button');
  69. editButton.textContent = 'Activate Mythos'; // Reference to Mythology
  70. editButton.id = 'edit-text-button';
  71. editButton.style.position = 'fixed';
  72. editButton.style.zIndex = '10000';
  73. editButton.style.backgroundColor = '#1e90ff'; // Athena's Wisdom
  74. editButton.style.color = 'white';
  75. editButton.style.border = 'none';
  76. editButton.style.padding = '10px 15px';
  77. editButton.style.borderRadius = '8px';
  78. editButton.style.fontSize = '16px';
  79. editButton.style.cursor = 'pointer';
  80. editButton.style.boxShadow = '0 4px 8px rgba(0,0,0,0.3)';
  81. editButton.style.transition = 'background-color 0.3s';
  82.  
  83. // Position the button based on user preference
  84. const position = localStorage.getItem('editButtonPosition') || 'top-right';
  85. setButtonPosition(position);
  86.  
  87. editButton.onclick = function() {
  88. toggleEditing(); // Toggle editing mode
  89. };
  90.  
  91. document.body.appendChild(editButton);
  92. };
  93.  
  94. // Set the button position
  95. const setButtonPosition = (position) => {
  96. switch (position) {
  97. case 'top-left':
  98. editButton.style.top = '10px';
  99. editButton.style.left = '10px';
  100. editButton.style.right = '';
  101. editButton.style.bottom = '';
  102. break;
  103. case 'bottom-right':
  104. editButton.style.bottom = '10px';
  105. editButton.style.right = '10px';
  106. editButton.style.top = '';
  107. editButton.style.left = '';
  108. break;
  109. case 'bottom-left':
  110. editButton.style.bottom = '10px';
  111. editButton.style.left = '10px';
  112. editButton.style.top = '';
  113. editButton.style.right = '';
  114. break;
  115. default: // top-right
  116. editButton.style.top = '10px';
  117. editButton.style.right = '10px';
  118. editButton.style.bottom = '';
  119. editButton.style.left = '';
  120. break;
  121. }
  122. };
  123.  
  124. // Create and style the floating toolbar
  125. const createToolbar = () => {
  126. toolbar = document.createElement('div');
  127. toolbar.id = 'edit-toolbar';
  128. toolbar.style.position = 'fixed';
  129. toolbar.style.zIndex = '10001';
  130. toolbar.style.backgroundColor = '#333'; // Underworld's Darkness
  131. toolbar.style.color = 'white';
  132. toolbar.style.borderRadius = '8px';
  133. toolbar.style.padding = '10px';
  134. toolbar.style.boxShadow = '0 4px 8px rgba(0,0,0,0.3)';
  135. toolbar.style.display = 'none'; // Initially hidden
  136. toolbar.style.top = '50px'; // Adjust position as needed
  137. toolbar.style.right = '10px'; // Adjust position as needed
  138.  
  139. const undoButton = createToolbarButton('↻ Undo - Mnemosyne', undoAction); // Mnemosyne, goddess of memory
  140. const redoButton = createToolbarButton('↺ Redo - Clio', redoAction); // Clio, muse of history
  141. const visitButton = createToolbarButton('🌟 Visit Delphi', visitWebsite); // Delphi, the oracle
  142.  
  143. const positionSelect = createPositionSelect();
  144.  
  145. toolbar.appendChild(undoButton);
  146. toolbar.appendChild(redoButton);
  147. toolbar.appendChild(visitButton);
  148. toolbar.appendChild(positionSelect);
  149.  
  150. document.body.appendChild(toolbar);
  151. };
  152.  
  153. // Create a button for the toolbar with Greek-themed icons
  154. const createToolbarButton = (text, action) => {
  155. const button = document.createElement('button');
  156. button.innerHTML = text; // Using innerHTML to include Unicode symbols
  157. button.style.backgroundColor = '#555'; // Hermes' Shade
  158. button.style.color = 'white';
  159. button.style.border = 'none';
  160. button.style.padding = '5px 10px';
  161. button.style.borderRadius = '5px';
  162. button.style.margin = '2px';
  163. button.style.cursor = 'pointer';
  164. button.style.fontSize = '14px';
  165. button.onclick = action;
  166.  
  167. return button;
  168. };
  169.  
  170. // Create a select element for choosing button position
  171. const createPositionSelect = () => {
  172. const select = document.createElement('select');
  173. select.style.backgroundColor = '#555'; // Hermes' Shade
  174. select.style.color = 'white';
  175. select.style.border = 'none';
  176. select.style.padding = '5px';
  177. select.style.borderRadius = '5px';
  178. select.style.margin = '2px';
  179. select.style.fontSize = '14px';
  180.  
  181. const positions = ['top-right', 'top-left', 'bottom-right', 'bottom-left'];
  182. positions.forEach(pos => {
  183. const option = document.createElement('option');
  184. option.value = pos;
  185. option.textContent = `Position: ${pos.replace('-', ' ')}`;
  186. select.appendChild(option);
  187. });
  188.  
  189. select.value = localStorage.getItem('editButtonPosition') || 'top-right';
  190. select.onchange = (event) => {
  191. const newPosition = event.target.value;
  192. localStorage.setItem('editButtonPosition', newPosition);
  193. setButtonPosition(newPosition);
  194. };
  195.  
  196. return select;
  197. };
  198.  
  199. // Show the toolbar
  200. const showToolbar = () => {
  201. if (!toolbar) createToolbar();
  202. toolbar.style.display = 'block';
  203. };
  204.  
  205. // Hide the toolbar
  206. const hideToolbar = () => {
  207. if (toolbar) toolbar.style.display = 'none';
  208. };
  209.  
  210. // Undo action
  211. const undoAction = () => {
  212. document.execCommand('undo');
  213. };
  214.  
  215. // Redo action
  216. const redoAction = () => {
  217. document.execCommand('redo');
  218. };
  219.  
  220. // Open author's website
  221. const visitWebsite = () => {
  222. window.open(websiteUrl, '_blank');
  223. };
  224.  
  225. // Initialize the button and toolbar
  226. const initializeScript = () => {
  227. if (document.readyState === 'loading') {
  228. document.addEventListener('DOMContentLoaded', () => {
  229. createEditButton();
  230. createToolbar();
  231. });
  232. } else {
  233. createEditButton();
  234. createToolbar();
  235. }
  236. };
  237.  
  238. // Run initialization function
  239. initializeScript();
  240.  
  241. // Prevent toolbar from being editable
  242. document.addEventListener('keydown', (event) => {
  243. if (isEditingEnabled) {
  244. if (event.target === toolbar) {
  245. event.preventDefault();
  246. }
  247. }
  248. });
  249.  
  250. })();