您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
A JavaScript library for linkification stuff. Used by linkify-plus-plus.
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/27630/213494/linkify-plus-plus-core.js
A JavaScript library for linkification stuff. Used by linkify-plus-plus.
https://rawgit.com/eight04/linkify-plus-plus-core/master/demo/demo.html
This module exports 2 classes.
npm install -S linkify-plus-plus-core
var {UrlMatcher, Linkifier} = require("linkify-plus-plus-core");
// or use the matcher only
var {UrlMatcher} = require("linkify-plus-plus-core/lib/url-matcher")
There is also a browserified standalone build in dist
folder, which can be included in your html directly.
<script src="path/to/linkify-plus-plus-core.js"></script>
<script>
// access the module with "linkifyPlusPlusCore" global
var {UrlMatcher, Linkifier} = linkifyPlusPlusCore;
</script>
CDN
<script src="https://unpkg.com/linkify-plus-plus-core/dist/linkify-plus-plus-core.js"></script>
// create a matcher
var matcher = new UrlMatcher();
for (var link of matcher.match(text)) {
// matcher.match() returns a generator, yielding an object for each match result
console.log(link.start, link.end, link.text, link.url);
}
// Linkifier needs a matcher to work
var linkifier = new Linkifier(document.body, {matcher: matcher});
// Linkifier will walk through the DOM tree, match url against all text nodes, and replace them with anchor element.
linkifier.on("complete", elapse => {
console.log(`finished in ${elapse}ms`);
});
linkifier.on("error", err => {
console.log("failed with error:", err);
});
linkifier.start();
// It is suggested to use `linkify()` function which wraps Linkifier to a promise.
linkify(document.body, {matcher}).then(onComplete, onError);
This module exports
<a>
element.The options object, all properties are optional:
["file:///\\S+", "magnet:\\?\\S+"]
standalone
option. Allow some characters to be placed between whitespace and link. Some common characters are {[("'
.standalone
option. Allow some characters to be placed between whitespace and link. Some common characters are '")]},.;?!
.This generator yields matched result. The result object:
.url
doesn't always equal .text
, that .text
might lack of the protocol but .url
is always a full URL.There are also some properties for each parts of the URL: .protocol
, .auth
, .domain
, .port
, .path
.
This class extends event-lite
.
The options object:
Any object having a .match
method, which accepts a string and returns an iterable of matched result, should work.
The match result must have .start
, .end
, .text
, and .url
properties described above.
A function recieving an element and returning a boolean to decide if the element should be linkified. Note that the elements in INVALID_TAGS
are already filtered out before the validator.
target="_blank"
to the link.rel="noopener"
to the link.root
argument is omitted, this value is adopted.<img>
for the link if the url looks like an image.Start linkification. The linkifier would walk through the DOM tree, collect text nodes and <wbr>
tags, match URLs with matcher, and convert them into links.
Abort linkification.
Linkifier emits following events, which could be listened with .on
:
complete - emitted when the linkification completed. Listener arguments:
error - emitted when the linkification failed. Listener arguments:
link - emitted when a link is created. You can alter the style, or implement your link builder to replace the default one. Listener arguments:
UrlMatcher.match()
<wbr>
tags) extract from matched text range, which is usually used as the content of the link.A convenient function to setup Linkifier. See Linkifier for the arguments. Additionally, if option object has some keys starting with on
, the function treats them as event listeners. You can register event listeners like:
linkify({
root,
matcher,
onlink: ({link}) => {...}
}).then(...);
In the very old days, the script is based on Linkify Plus. Although it has been rewritten multiple times, the original license can be found here.
TLD list is grabbed from http://data.iana.org/TLD/tlds-alpha-by-domain.txt.
TLD count is grabbed from http://research.domaintools.com/statistics/tld-counts/.
Version 0.3.0 (Aug 23, 2017):
Version 0.2.0 (Mar 4, 2017):
Version 0.1.0 (Feb 23, 2017):