moebius#57: about:support - improvements (Copy text to clipboard)

https://github.com/MoonchildProductions/moebius/pull/57
This commit is contained in:
janekptacijarabaci 2018-04-12 23:45:12 +02:00 • committed by Roy Tam
commit e7edb2cd31
2 changed files with 32 additions and 13 deletions

View file

@ -715,7 +715,8 @@ Serializer.prototype = {
let hasText = false; let hasText = false;
for (let child of elem.childNodes) { for (let child of elem.childNodes) {
if (child.nodeType == Node.TEXT_NODE) { if (child.nodeType == Node.TEXT_NODE) {
let text = this._nodeText(child); let text = this._nodeText(
child, (child.classList && child.classList.contains("endline")));
this._appendText(text); this._appendText(text);
hasText = hasText || !!text.trim(); hasText = hasText || !!text.trim();
} }
@ -742,7 +743,7 @@ Serializer.prototype = {
} }
}, },
_startNewLine: function (lines) { _startNewLine: function () {
let currLine = this._currentLine; let currLine = this._currentLine;
if (currLine) { if (currLine) {
// The current line is not empty. Trim it. // The current line is not empty. Trim it.
@ -754,7 +755,7 @@ Serializer.prototype = {
this._lines.push(""); this._lines.push("");
}, },
_appendText: function (text, lines) { _appendText: function (text) {
this._currentLine += text; this._currentLine += text;
}, },
@ -777,7 +778,8 @@ Serializer.prototype = {
let col = tableHeadingCols[i]; let col = tableHeadingCols[i];
if (col.localName != "th" || col.classList.contains("title-column")) if (col.localName != "th" || col.classList.contains("title-column"))
break; break;
colHeadings[i] = this._nodeText(col).trim(); colHeadings[i] = this._nodeText(
col, (col.classList && col.classList.contains("endline"))).trim();
} }
} }
let hasColHeadings = Object.keys(colHeadings).length > 0; let hasColHeadings = Object.keys(colHeadings).length > 0;
@ -804,7 +806,10 @@ Serializer.prototype = {
let text = ""; let text = "";
if (colHeadings[j]) if (colHeadings[j])
text += colHeadings[j] + ": "; text += colHeadings[j] + ": ";
text += this._nodeText(children[j]).trim(); text += this._nodeText(
children[j],
(children[j].classList &&
children[j].classList.contains("endline"))).trim();
this._appendText(text); this._appendText(text);
this._startNewLine(); this._startNewLine();
} }
@ -820,7 +825,10 @@ Serializer.prototype = {
if (this._ignoreElement(trs[i])) if (this._ignoreElement(trs[i]))
continue; continue;
let children = trs[i].querySelectorAll("th,td"); let children = trs[i].querySelectorAll("th,td");
let rowHeading = this._nodeText(children[0]).trim(); let rowHeading = this._nodeText(
children[0],
(children[0].classList &&
children[0].classList.contains("endline"))).trim();
if (children[0].classList.contains("title-column")) { if (children[0].classList.contains("title-column")) {
if (!this._isHiddenSubHeading(children[0])) if (!this._isHiddenSubHeading(children[0]))
this._appendText(rowHeading); this._appendText(rowHeading);
@ -834,7 +842,10 @@ Serializer.prototype = {
// queued up from querySelectorAll earlier. // queued up from querySelectorAll earlier.
this._appendText(rowHeading + ": "); this._appendText(rowHeading + ": ");
} else { } else {
this._appendText(rowHeading + ": " + this._nodeText(children[1]).trim()); this._appendText(rowHeading + ": " + this._nodeText(
children[1],
(children[1].classList &&
children[1].classList.contains("endline"))).trim());
} }
} }
this._startNewLine(); this._startNewLine();
@ -846,8 +857,16 @@ Serializer.prototype = {
return elem.classList.contains("no-copy"); return elem.classList.contains("no-copy");
}, },
_nodeText: function (node) { _nodeText: function (node, endline) {
return node.textContent.replace(/\s+/g, " "); let whiteChars = /\s+/g
let whiteCharsButNoEndline = /(?!\n)[\s]+/g;
let _node = node.cloneNode(true);
if (_node.firstElementChild &&
(_node.firstElementChild.nodeName.toLowerCase() == "button")) {
_node.removeChild(_node.firstElementChild);
}
return _node.textContent.replace(
endline ? whiteCharsButNoEndline : whiteChars, " ");
}, },
}; };
@ -919,7 +938,7 @@ function setupEventListeners() {
PlacesDBUtils.checkAndFixDatabase(function(aLog) { PlacesDBUtils.checkAndFixDatabase(function(aLog) {
let msg = aLog.join("\n"); let msg = aLog.join("\n");
$("verify-place-result").style.display = "block"; $("verify-place-result").style.display = "block";
$("verify-place-result").classList.remove("no-copy"); $("verify-place-result-parent").classList.remove("no-copy");
$("verify-place-result").textContent = msg; $("verify-place-result").textContent = msg;
}); });
}); });

View file

@ -407,16 +407,16 @@
</h2> </h2>
<table> <table>
<tr class="no-copy"> <tr id="verify-place-result-parent" class="no-copy">
<th class="column"> <th class="column">
&aboutSupport.placeDatabaseIntegrity; &aboutSupport.placeDatabaseIntegrity;
</th> </th>
<td> <td class="endline">
<button id="verify-place-integrity-button"> <button id="verify-place-integrity-button">
&aboutSupport.placeDatabaseVerifyIntegrity; &aboutSupport.placeDatabaseVerifyIntegrity;
</button> </button>
<pre id="verify-place-result" class="hidden no-copy"></pre> <pre id="verify-place-result" class="hidden"></pre>
</td> </td>
</tr> </tr>
</table> </table>