+// http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac
+
+function getSelectionText() {
+ 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();
+}
+
+function openUrlPopup(url) {
+ const w = window.open("");
+
+ w.opener = null;
+ w.location = url;
+}
+function openArticlePopup(id) {
+ const w = window.open("",
+ "ttrss_article_popup",
+ "height=900,width=900,resizable=yes,status=no,location=no,menubar=no,directories=no,scrollbars=yes,toolbar=no");
+
+ w.opener = null;
+ w.location = "backend.php?op=article&method=view&mode=raw&html=1&zoom=1&id=" + id + "&csrf_token=" + getInitParam("csrf_token");
+}
+
+function keyevent_to_action(e) {
+
+ const hotkeys_map = getInitParam("hotkeys");
+ const keycode = e.which;
+ const keychar = String.fromCharCode(keycode).toLowerCase();
+
+ if (keycode == 27) { // escape and drop prefix
+ hotkey_prefix = false;
+ }
+
+ if (keycode == 16 || keycode == 17) return; // ignore lone shift / ctrl
+
+ if (!hotkey_prefix && hotkeys_map[0].indexOf(keychar) != -1) {
+
+ const date = new Date();
+ const ts = Math.round(date.getTime() / 1000);
+
+ hotkey_prefix = keychar;
+ hotkey_prefix_pressed = ts;
+
+ $("cmdline").innerHTML = keychar;
+ Element.show("cmdline");
+
+ e.stopPropagation();
+
+ return false;
+ }
+
+ Element.hide("cmdline");
+
+ let hotkey_name = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")";
+
+ // ensure ^*char notation
+ if (e.shiftKey) hotkey_name = "*" + hotkey_name;
+ if (e.ctrlKey) hotkey_name = "^" + hotkey_name;
+ if (e.altKey) hotkey_name = "+" + hotkey_name;
+ if (e.metaKey) hotkey_name = "%" + hotkey_name;
+
+ const hotkey_full = hotkey_prefix ? hotkey_prefix + " " + hotkey_name : hotkey_name;
+ hotkey_prefix = false;
+
+ let action_name = false;
+
+ for (const sequence in hotkeys_map[1]) {
+ if (sequence == hotkey_full) {
+ action_name = hotkeys_map[1][sequence];
+ break;
+ }
+ }
+
+ console.log('keyevent_to_action', hotkey_full, '=>', action_name);
+
+ return action_name;
+}
\ No newline at end of file