mirror of
https://git.tt-rss.org/fox/tt-rss.git
synced 2026-05-05 15:46:10 +02:00
Improve 'App.getSelectedText()'.
This also drops 'String.prototype.stripTags', which is no longer used.
This commit is contained in:
parent
b888fa1032
commit
bb08b0acd5
21
js/App.js
21
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) {
|
||||
|
||||
@ -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 != "") {
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user