Edytuj Strone Librus

Pozwala edytować każdą stronę na żywo i zapisywać zmiany!

  1. // ==UserScript==
  2. // @name Edytuj Strone Librus
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Pozwala edytować każdą stronę na żywo i zapisywać zmiany!
  6. // @author Ty
  7. // @match *://*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Tworzy przyciski: aktywacja edycji, zapis zmian
  15. let buttonEdit = document.createElement("button");
  16. buttonEdit.innerHTML = "Włącz edycję";
  17. buttonEdit.style.position = "fixed";
  18. buttonEdit.style.top = "10px";
  19. buttonEdit.style.right = "10px";
  20. buttonEdit.style.zIndex = "9999";
  21. buttonEdit.style.padding = "10px";
  22. buttonEdit.style.background = "#ff0000";
  23. buttonEdit.style.color = "#fff";
  24. buttonEdit.style.border = "none";
  25. buttonEdit.style.cursor = "pointer";
  26. buttonEdit.style.fontSize = "16px";
  27. document.body.appendChild(buttonEdit);
  28.  
  29. let buttonSave = document.createElement("button");
  30. buttonSave.innerHTML = "Zapisz zmiany";
  31. buttonSave.style.position = "fixed";
  32. buttonSave.style.top = "10px";
  33. buttonSave.style.right = "120px";
  34. buttonSave.style.zIndex = "9999";
  35. buttonSave.style.padding = "10px";
  36. buttonSave.style.background = "#00cc00";
  37. buttonSave.style.color = "#fff";
  38. buttonSave.style.border = "none";
  39. buttonSave.style.cursor = "pointer";
  40. buttonSave.style.fontSize = "16px";
  41. document.body.appendChild(buttonSave);
  42.  
  43. // Funkcja włączająca tryb edycji
  44. buttonEdit.addEventListener("click", function() {
  45. document.body.contentEditable = (document.body.contentEditable === "true") ? "false" : "true";
  46. buttonEdit.innerHTML = (document.body.contentEditable === "true") ? "Wyłącz edycję" : "Włącz edycję";
  47. buttonEdit.style.background = (document.body.contentEditable === "true") ? "#00cc00" : "#ff0000";
  48. });
  49.  
  50. // Funkcja zapisująca zmiany
  51. buttonSave.addEventListener("click", function() {
  52. if (document.body.contentEditable === "true") {
  53. // Zapisz zmieniony HTML do localStorage
  54. localStorage.setItem("savedContent", document.body.innerHTML);
  55. alert("Zmiany zostały zapisane!");
  56. } else {
  57. alert("Musisz włączyć tryb edycji, aby zapisać zmiany.");
  58. }
  59. });
  60.  
  61. // Sprawdź, czy są zapisane zmiany w localStorage
  62. if (localStorage.getItem("savedContent")) {
  63. // Przywróć zapisane zmiany po załadowaniu strony
  64. document.body.innerHTML = localStorage.getItem("savedContent");
  65. }
  66. })();