问题描述
我遇到了一个网站,在您突出显示的任何文本的末尾注入阅读更多:行,并从其页面复制。
I ran into a a site that injects a "Read More: " line at the end of any text that you highlight and copy from it's pages.
我已经从来没有见过这个,没有严重挖掘他们的代码,我找不到执行此操作的代码。
I've never seen this before, and without severely digging into their code, I can't find the code that does this.
任何人都知道如何做到这一点?
Anyone know how this is done?
示例:
复制一段文字,并将其粘贴到另一个应用程序中,然后会有一个阅读更多之后的行。
Copy a paragraph of text, and paste it into another application, and there will be a "read more" line afterwards.
推荐答案
Suite101正在使用名为。
Suite101 is using a 3rd party service called Tynt.
Tynt的JavaScript代码段位于
Tynt's JavaScript snippet is located at http://tcr.tynt.com/javascripts/Tracer.js
我为您探索了来源(在在线JavaScript美化器)。
I explored the source for you (with some help from the Online JavaScript beautifier).
所以这就是发生的事情:
So here's what's happening:
- 代码激活关于mouseup,mousedown和copy等事件(在
startListeningForTraces
函数中) - 如果用户选择了一系列文本,那么:
- 创建归属链接的HTML,以及可选的CC许可证URL
- 将此HTML附加到选择中,将其放在零尺寸
< div>
内(以使其在屏幕上不可见) - 报告复制回来的内容Tynt的服务器
- the code activates on events like mouseup, mousedown, and copy (in the
startListeningForTraces
function) - if the user selected a range of text, then it:
- creates the HTML for an attribution link, plus optional CC license URL
- appends this HTML to the selection, placing it inside a zero-size
<div>
(to keep it invisible on-screen) - reports what was copied back to Tynt's servers
Tynt的代码做了大量的工作来使这个工作无缝地工作跨浏览器。
Tynt's code does a tremendous amount of work to make this work seamlessly across browsers.
这篇关于从网页复制内容时注入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!