1
0
Эх сурвалжийг харах

Merge branch 'master' of https://github.com/gildas-lormeau/SingleFile; branch 'editor-cutting' of https://github.com/egor-duda/SingleFile

Former-commit-id: 77a935f2a734289a07d9794538927476b629ce22
Gildas 6 жил өмнө
parent
commit
44eb95cee7

+ 12 - 0
_locales/de/messages.json

@@ -507,6 +507,18 @@
 		"message": "Aktivieren/Deaktivieren des Nur-Lese-Modus",
 		"description": "Title of the button 'Enable/disable read-only' in the editor"
 	},
+	"editorCutPage": {
+		"message": "Enable/disable removing document's element on click",
+		"description": "Title of the button 'Enable/disable removing document's element on click' in the editor"
+	},
+	"editorUndoCutPage": {
+		"message": "Restore last removed element",
+		"description": "Title of the button 'Restore last removed element' in the editor"
+	},
+	"editorUndoAllCutPage": {
+		"message": "Restore all removed elements",
+		"description": "Title of the button 'Restore all removed elements' in the editor"
+	},
 	"editorSavePage": {
 		"message": "Speichern der Webseite",
 		"description": "Title of the button 'Save the page' in the editor"

+ 12 - 0
_locales/en/messages.json

@@ -507,6 +507,18 @@
 		"message": "Enable/disable read-only",
 		"description": "Title of the button 'Enable/disable read-only' in the editor"
 	},
+	"editorCutPage": {
+		"message": "Enable/disable removing document's element on click",
+		"description": "Title of the button 'Enable/disable removing document's element on click' in the editor"
+	},
+	"editorUndoCutPage": {
+		"message": "Restore last removed element",
+		"description": "Title of the button 'Restore last removed element' in the editor"
+	},
+	"editorUndoAllCutPage": {
+		"message": "Restore all removed elements",
+		"description": "Title of the button 'Restore all removed elements' in the editor"
+	},
 	"editorSavePage": {
 		"message": "Save the page",
 		"description": "Title of the button 'Save the page' in the editor"

+ 12 - 0
_locales/es/messages.json

@@ -507,6 +507,18 @@
 		"message": "Enable/disable read-only",
 		"description": "Title of the button 'Enable/disable read-only' in the editor"
 	},
+	"editorCutPage": {
+		"message": "Enable/disable removing document's element on click",
+		"description": "Title of the button 'Enable/disable removing document's element on click' in the editor"
+	},
+	"editorUndoCutPage": {
+		"message": "Restore last removed element",
+		"description": "Title of the button 'Restore last removed element' in the editor"
+	},
+	"editorUndoAllCutPage": {
+		"message": "Restore all removed elements",
+		"description": "Title of the button 'Restore all removed elements' in the editor"
+	},
 	"editorSavePage": {
 		"message": "Save the page",
 		"description": "Title of the button 'Save the page' in the editor"

+ 12 - 0
_locales/fr/messages.json

@@ -507,6 +507,18 @@
 		"message": "Activer/déactiver le mode lecture seule",
 		"description": "Title of the button 'Enable/disable read-only' in the editor"
 	},
+	"editorCutPage": {
+		"message": "Enable/disable removing document's element on click",
+		"description": "Title of the button 'Enable/disable removing document's element on click' in the editor"
+	},
+	"editorUndoCutPage": {
+		"message": "Restore last removed element",
+		"description": "Title of the button 'Restore last removed element' in the editor"
+	},
+	"editorUndoAllCutPage": {
+		"message": "Restore all removed elements",
+		"description": "Title of the button 'Restore all removed elements' in the editor"
+	},
 	"editorSavePage": {
 		"message": "Sauver la page",
 		"description": "Title of the button 'Save the page' in the editor"

+ 12 - 0
_locales/ja/messages.json

@@ -507,6 +507,18 @@
 		"message": "Enable/disable read-only",
 		"description": "Title of the button 'Enable/disable read-only' in the editor"
 	},
+	"editorCutPage": {
+		"message": "Enable/disable removing document's element on click",
+		"description": "Title of the button 'Enable/disable removing document's element on click' in the editor"
+	},
+	"editorUndoCutPage": {
+		"message": "Restore last removed element",
+		"description": "Title of the button 'Restore last removed element' in the editor"
+	},
+	"editorUndoAllCutPage": {
+		"message": "Restore all removed elements",
+		"description": "Title of the button 'Restore all removed elements' in the editor"
+	},
 	"editorSavePage": {
 		"message": "Save the page",
 		"description": "Title of the button 'Save the page' in the editor"

+ 12 - 0
_locales/pl/messages.json

@@ -507,6 +507,18 @@
 		"message": "Włącz/wyłącz tylko do odczytu",
 		"description": "Title of the button 'Enable/disable read-only' in the editor"
 	},
+	"editorCutPage": {
+		"message": "Enable/disable removing document's element on click",
+		"description": "Title of the button 'Enable/disable removing document's element on click' in the editor"
+	},
+	"editorUndoCutPage": {
+		"message": "Restore last removed element",
+		"description": "Title of the button 'Restore last removed element' in the editor"
+	},
+	"editorUndoAllCutPage": {
+		"message": "Restore all removed elements",
+		"description": "Title of the button 'Restore all removed elements' in the editor"
+	},
 	"editorSavePage": {
 		"message": "Zapisz stronę",
 		"description": "Title of the button 'Save the page' in the editor"

+ 12 - 0
_locales/ru/messages.json

@@ -507,6 +507,18 @@
 		"message": "Enable/disable read-only",
 		"description": "Title of the button 'Enable/disable read-only' in the editor"
 	},
+	"editorCutPage": {
+		"message": "Enable/disable removing document's element on click",
+		"description": "Title of the button 'Enable/disable removing document's element on click' in the editor"
+	},
+	"editorUndoCutPage": {
+		"message": "Restore last removed element",
+		"description": "Title of the button 'Restore last removed element' in the editor"
+	},
+	"editorUndoAllCutPage": {
+		"message": "Restore all removed elements",
+		"description": "Title of the button 'Restore all removed elements' in the editor"
+	},
 	"editorSavePage": {
 		"message": "Save the page",
 		"description": "Title of the button 'Save the page' in the editor"

+ 12 - 0
_locales/uk/messages.json

@@ -507,6 +507,18 @@
 		"message": "Ввімкнути/вимкнути режим 'тільки для читання'",
 		"description": "Title of the button 'Enable/disable read-only' in the editor"
 	},
+	"editorCutPage": {
+		"message": "Enable/disable removing document's element on click",
+		"description": "Title of the button 'Enable/disable removing document's element on click' in the editor"
+	},
+	"editorUndoCutPage": {
+		"message": "Restore last removed element",
+		"description": "Title of the button 'Restore last removed element' in the editor"
+	},
+	"editorUndoAllCutPage": {
+		"message": "Restore all removed elements",
+		"description": "Title of the button 'Restore all removed elements' in the editor"
+	},
 	"editorSavePage": {
 		"message": "Зберегти сторінку",
 		"description": "Title of the button 'Save the page' in the editor"

+ 12 - 0
_locales/zh_CN/messages.json

@@ -507,6 +507,18 @@
 		"message": "Enable/disable read-only",
 		"description": "Title of the button 'Enable/disable read-only' in the editor"
 	},
+	"editorCutPage": {
+		"message": "Enable/disable removing document's element on click",
+		"description": "Title of the button 'Enable/disable removing document's element on click' in the editor"
+	},
+	"editorUndoCutPage": {
+		"message": "Restore last removed element",
+		"description": "Title of the button 'Restore last removed element' in the editor"
+	},
+	"editorUndoAllCutPage": {
+		"message": "Restore all removed elements",
+		"description": "Title of the button 'Restore all removed elements' in the editor"
+	},
 	"editorSavePage": {
 		"message": "Save the page",
 		"description": "Title of the button 'Save the page' in the editor"

+ 12 - 0
_locales/zh_TW/messages.json

@@ -507,6 +507,18 @@
 		"message": "Enable/disable read-only",
 		"description": "Title of the button 'Enable/disable read-only' in the editor"
 	},
+	"editorCutPage": {
+		"message": "Enable/disable removing document's element on click",
+		"description": "Title of the button 'Enable/disable removing document's element on click' in the editor"
+	},
+	"editorUndoCutPage": {
+		"message": "Restore last removed element",
+		"description": "Title of the button 'Restore last removed element' in the editor"
+	},
+	"editorUndoAllCutPage": {
+		"message": "Restore all removed elements",
+		"description": "Title of the button 'Restore all removed elements' in the editor"
+	},
 	"editorSavePage": {
 		"message": "Save the page",
 		"description": "Title of the button 'Save the page' in the editor"

+ 21 - 0
extension/ui/bg/ui-editor.js

@@ -39,6 +39,9 @@ singlefile.extension.ui.bg.editor = (() => {
 	const addBlueNoteButton = document.querySelector(".add-note-blue-button");
 	const addGreenNoteButton = document.querySelector(".add-note-green-button");
 	const editPageButton = document.querySelector(".edit-page-button");
+	const cutPageButton = document.querySelector(".cut-page-button");
+	const undoCutPageButton = document.querySelector(".undo-cut-page-button");
+	const undoAllCutPageButton = document.querySelector(".undo-all-cut-page-button");
 	const savePageButton = document.querySelector(".save-page-button");
 
 	let tabData;
@@ -55,6 +58,9 @@ singlefile.extension.ui.bg.editor = (() => {
 	toggleHighlightsButton.title = browser.i18n.getMessage("editorToggleHighlights");
 	removeHighlightButton.title = browser.i18n.getMessage("editorRemoveHighlight");
 	editPageButton.title = browser.i18n.getMessage("editorEditPage");
+	cutPageButton.title = browser.i18n.getMessage("editorCutPage");
+	undoCutPageButton.title = browser.i18n.getMessage("editorUndoCutPage");
+	undoAllCutPageButton.title = browser.i18n.getMessage("editorUndoAllCutPage");
 	savePageButton.title = browser.i18n.getMessage("editorSavePage");
 
 	addYellowNoteButton.onclick = () => editorElement.contentWindow.postMessage(JSON.stringify({ method: "addNote", color: "note-yellow" }), "*");
@@ -137,6 +143,21 @@ singlefile.extension.ui.bg.editor = (() => {
 			editorElement.contentWindow.postMessage(JSON.stringify({ method: "disableEditPage" }), "*");
 		}
 	};
+	cutPageButton.onclick = () => {
+		if (cutPageButton.classList.contains("cut-disabled")) {
+			cutPageButton.classList.remove("cut-disabled");
+			editorElement.contentWindow.postMessage(JSON.stringify({ method: "enableCutPage" }), "*");
+		} else {
+			cutPageButton.classList.add("cut-disabled");
+			editorElement.contentWindow.postMessage(JSON.stringify({ method: "disableCutPage" }), "*");
+		}
+	};
+	undoCutPageButton.onclick = () => {
+		editorElement.contentWindow.postMessage(JSON.stringify({ method: "undoCutPage" }), "*");
+	};
+	undoAllCutPageButton.onclick = () => {
+		editorElement.contentWindow.postMessage(JSON.stringify({ method: "undoAllCutPage" }), "*");
+	};
 	savePageButton.onclick = () => {
 		savePage();
 	};

+ 38 - 1
extension/ui/content/content-ui-editor-web.js

@@ -53,7 +53,8 @@
 	const DISABLED_NOSCRIPT_ATTRIBUTE_NAME = "data-single-file-disabled-noscript";
 
 	let NOTES_WEB_STYLESHEET, MASK_WEB_STYLESHEET, HIGHLIGHTS_WEB_STYLESHEET;
-	let selectedNote, anchorElement, maskNoteElement, maskPageElement, highlightSelectionMode, removeHighlightMode, resizingNoteMode, movingNoteMode, highlightColor, collapseNoteTimeout;
+	let selectedNote, anchorElement, maskNoteElement, maskPageElement, highlightSelectionMode, removeHighlightMode, resizingNoteMode, movingNoteMode, highlightColor, collapseNoteTimeout, cuttingMode;
+	let removedElements = [];
 
 	window.onmessage = async event => {
 		const message = JSON.parse(event.data);
@@ -117,6 +118,26 @@
 		if (message.method == "disableEditPage") {
 			document.body.contentEditable = false;
 		}
+		if (message.method == "enableCutPage") {
+			cuttingMode = true;
+			document.body.addEventListener("mouseover", highlightElementToCut);
+			document.body.addEventListener("mouseout", highlightElementToCut);
+		}
+		if (message.method == "disableCutPage") {
+			cuttingMode = false;
+			document.body.removeEventListener("mouseover", highlightElementToCut);
+			document.body.removeEventListener("mouseout", highlightElementToCut);
+		}
+		if (message.method == "undoCutPage") {
+			if (removedElements.length) {
+				removedElements.pop().classList.remove("single-file-removed");
+			}
+		}
+		if (message.method == "undoAllCutPage") {
+			while (removedElements.length) {
+				removedElements.pop().classList.remove("single-file-removed");
+			}
+		}
 		if (message.method == "getContent") {
 			serializeShadowRoots(document);
 			const doc = document.cloneNode(true);
@@ -400,6 +421,13 @@
 			clearTimeout(collapseNoteTimeout);
 			collapseNoteTimeout = null;
 		}
+		if (cuttingMode) {
+			let element = event.target;
+			if (document.documentElement != element) {
+				element.classList.add("single-file-removed");
+				removedElements.push(element);
+			}
+		}
 	}
 
 	function anchorNote(event, noteElement, deltaX, deltaY) {
@@ -529,6 +557,15 @@
 		}
 	}
 
+	function highlightElementToCut(event) {
+		if (event.type != "mouseover" && event.type != "mouseout") return;
+		var target = event.target;
+		if ("classList" in target) {
+			target.classList.toggle("single-file-hover");
+		}
+		event.stopPropagation();
+	}
+
 	function reflowNotes() {
 		document.querySelectorAll(NOTE_TAGNAME).forEach(containerElement => {
 			const noteElement = containerElement.shadowRoot.querySelector("." + NOTE_CLASS);

+ 11 - 0
extension/ui/editor/editor-frame-web.css

@@ -35,4 +35,15 @@
 single-file-note {
     all: initial !important;
     display: contents !important;
+}
+
+.single-file-hover {
+    outline: 1px solid red !important;
+}
+
+.single-file-removed {
+    display: none !important;
+    float: none !important;
+    position: static !important;
+    visibility: collapse !important;
 }

+ 1 - 0
extension/ui/editor/editor.css

@@ -38,6 +38,7 @@ img[type=button]:hover {
 }
 
 img[type=button].edit-disabled,
+img[type=button].cut-disabled,
 img[type=button].highlight-disabled,
 img[type=button].remove-highlight-disabled {
     background-color: #7b7b7b;

+ 8 - 1
extension/ui/editor/editor.html

@@ -34,7 +34,14 @@
 				src="/extension/ui/resources/button_highlighter_visible.png">
 			<img type="button" class="remove-highlight-button remove-highlight-disabled"
 				src="/extension/ui/resources/button_highlighter_delete.png">
-			<img type="button" class="edit-page-button edit-disabled" src="/extension/ui/resources/button_note_edit.png">
+			<img type="button" class="edit-page-button edit-disabled"
+				src="/extension/ui/resources/button_note_edit.png">
+			<div class="separator"></div>
+		</div>
+		<div class="buttons">
+			<img type="button" class="cut-page-button cut-disabled" src="/extension/ui/resources/button_cut.png">
+			<img type="button" class="undo-cut-page-button" src="/extension/ui/resources/button_undo_cut.png">
+			<img type="button" class="undo-all-cut-page-button" src="/extension/ui/resources/button_undo_all_cut.png">
 			<div class="separator"></div>
 		</div>
 		<div class="buttons">

BIN
extension/ui/resources/button_cut.png


BIN
extension/ui/resources/button_undo_all_cut.png


BIN
extension/ui/resources/button_undo_cut.png