2017-08-26 16:36:18 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const $ = require("jquery");
|
|
|
|
|
2018-07-09 18:37:52 +00:00
|
|
|
module.exports = function(chat) {
|
2017-08-26 16:36:18 +00:00
|
|
|
const selection = window.getSelection();
|
|
|
|
|
|
|
|
// If selection does not span multiple elements, do nothing
|
|
|
|
if (selection.anchorNode === selection.focusNode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const range = selection.getRangeAt(0);
|
|
|
|
const documentFragment = range.cloneContents();
|
|
|
|
const div = document.createElement("div");
|
|
|
|
|
|
|
|
$(documentFragment)
|
|
|
|
.find(".from .user")
|
|
|
|
.each((_, el) => {
|
|
|
|
el = $(el);
|
|
|
|
el.text(`<${el.text()}>`);
|
|
|
|
});
|
|
|
|
|
2018-05-30 12:55:11 +00:00
|
|
|
$(documentFragment)
|
|
|
|
.find(".content > .user")
|
|
|
|
.prepend("* ");
|
|
|
|
|
2017-08-26 16:36:18 +00:00
|
|
|
div.id = "js-copy-hack";
|
|
|
|
div.appendChild(documentFragment);
|
|
|
|
chat.appendChild(div);
|
|
|
|
|
|
|
|
selection.selectAllChildren(div);
|
|
|
|
|
|
|
|
window.setTimeout(() => {
|
|
|
|
chat.removeChild(div);
|
|
|
|
selection.removeAllRanges();
|
|
|
|
selection.addRange(range);
|
|
|
|
}, 0);
|
2018-07-09 18:37:52 +00:00
|
|
|
};
|