diff --git a/src/Menu/CopyTextLink.coffee b/src/Menu/CopyTextLink.coffee new file mode 100644 index 000000000..a1c705f7c --- /dev/null +++ b/src/Menu/CopyTextLink.coffee @@ -0,0 +1,25 @@ +CopyTextLink = + init: -> + return unless g.VIEW in ['index', 'thread'] and Conf['Menu'] and Conf['Copy Text Link'] + + a = $.el 'a', + className: 'copy-text-link' + href: 'javascript:;' + textContent: 'Copy Text' + $.on a, 'click', CopyTextLink.copy + + Menu.menu.addEntry + el: a + open: (post) -> + CopyTextLink.text = post.nodes.commentClean.innerText + true + + copy: -> + el = $.el 'textarea', + className: 'copy-text-element', + value: CopyTextLink.text + $.add d.body, el + el.select() + try + d.execCommand 'copy' + $.rm el diff --git a/src/config/Config.coffee b/src/config/Config.coffee index 8d2f5f417..df0d794d1 100644 --- a/src/config/Config.coffee +++ b/src/config/Config.coffee @@ -307,6 +307,11 @@ Config = 'Add a report link to the menu.' 1 ] + 'Copy Text Link': [ + true + 'Add a link to copy the post\'s text.' + 1 + ] 'Thread Hiding Link': [ true 'Add a link to hide entire threads.' diff --git a/src/css/style.css b/src/css/style.css index c6ded5821..5cd1ba9db 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -1012,6 +1012,14 @@ div[data-checked="false"] > .suboption-list { left: calc(110px - .5px * var(--tn-w)); } +/* Copy Text Link's textarea element */ +textarea.copy-text-element { + height: 0; + width: 0; + position: absolute; + top: -10000px; +} + /* Announcement Hiding */ :root.hide-announcement #globalMessage { display: none; diff --git a/src/main/Main.coffee b/src/main/Main.coffee index 21fda05e2..bc8037d9e 100644 --- a/src/main/Main.coffee +++ b/src/main/Main.coffee @@ -461,6 +461,7 @@ Main = ['Menu', Menu] ['Index Generator (Menu)', Index.menu] ['Report Link', ReportLink] + ['Copy Text Link', CopyTextLink] ['Thread Hiding (Menu)', ThreadHiding.menu] ['Reply Hiding (Menu)', PostHiding.menu] ['Delete Link', DeleteLink]