summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorsupahgreg <supahgreg@users.noreply.github.com>2025-10-10 23:30:34 +0000
committersupahgreg <supahgreg@users.noreply.github.com>2025-10-10 23:30:34 +0000
commitbb08b0acd5dbdfba068fad5332ddf51b485fc477 (patch)
treedd36e91e8d40aaa2efa170ab116bcc28466700d2 /js
parentb888fa10328219d4eb5bec3fd0c69fa859a8c43b (diff)
Improve 'App.getSelectedText()'.
This also drops 'String.prototype.stripTags', which is no longer used.
Diffstat (limited to 'js')
-rw-r--r--js/App.js21
-rw-r--r--js/CommonFilters.js2
-rwxr-xr-xjs/common.js4
3 files changed, 4 insertions, 23 deletions
diff --git a/js/App.js b/js/App.js
index 5df313491..33bd81d9a 100644
--- a/js/App.js
+++ b/js/App.js
@@ -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) {
diff --git a/js/CommonFilters.js b/js/CommonFilters.js
index f6cc5a4e7..6d40373d6 100644
--- a/js/CommonFilters.js
+++ b/js/CommonFilters.js
@@ -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 != "") {
diff --git a/js/common.js b/js/common.js
index 9635ab492..99cf52fa1 100755
--- a/js/common.js
+++ b/js/common.js
@@ -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,