Improve 'App.getSelectedText()'.

This also drops 'String.prototype.stripTags', which is no longer used.
This commit is contained in:
supahgreg 2025-10-10 23:30:34 +00:00
parent b888fa1032
commit bb08b0acd5
No known key found for this signature in database
3 changed files with 4 additions and 23 deletions

View File

@ -441,26 +441,9 @@ const App = {
}
});
},
// http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac
getSelectedText: function() {
let text = "";
if (typeof window.getSelection != "undefined") {
const sel = window.getSelection();
if (sel.rangeCount) {
const container = document.createElement("div");
for (let i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents());
}
text = container.innerHTML;
}
} else if (typeof document.selection != "undefined") {
if (document.selection.type == "Text") {
text = document.selection.createRange().textText;
}
}
return text.stripTags();
const sel = window.getSelection();
return sel ? sel.toString().trim() : "";
},
displayIfChecked: function(checkbox, elemId) {
if (checkbox.checked) {

View File

@ -527,6 +527,8 @@ const Filters = {
`);
if (!App.isPrefs()) {
// TODO: This section isn't working as expected (under Firefox 143, at least).
// `selectedText` is always empty at this point (tested by selecting some article text).
const selectedText = App.getSelectedText();
if (selectedText != "") {

View File

@ -167,10 +167,6 @@ Array.prototype.uniq = function() {
return this.filter((v, i, a) => a.indexOf(v) === i);
};
String.prototype.stripTags = function() {
return this.replace(/<\w+(\s+("[^"]*"|'[^']*'|[^>])+)?(\/)?>|<\/\w+>/gi, '');
}
/* exported xhr */
const xhr = {
_ts: 0,