Skip to content

Instantly share code, notes, and snippets.

@tyru
Created September 23, 2010 03:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tyru/593030 to your computer and use it in GitHub Desktop.
--- appendAnchor.js.bak 2010-09-23 12:03:00.000000000 +0900
+++ appendAnchor.js 2010-09-23 12:23:29.000000000 +0900
@@ -36,7 +36,7 @@
// Array.prototype.uniq = function() this.reduceRight( function (a, b) (a[0] === b || a.unshift(b), a), []);
// [ 'TITLE', 'STYLE', 'SCRIPT', 'TEXTAREA', 'XMP', 'A', ].join('').split('').sort().uniq().join('');
const xpathQueryPlainText = '/descendant::*[not(contains(" TITLE STYLE SCRIPT TEXTAREA XMP A ", concat(" ", translate(local-name(), "aceilmprstxy", "ACEILMPRSTXY"), " ")))]/child::text()';
- const regexpLikeURL = new RegExp("h?(ttps?):/+([a-zA-Z0-9][-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]+[-_~*(a-zA-Z0-9;/?@&=+$%#])");
+ const regexpLikeURL = new RegExp("(h?ttps?|ftp):/+([a-zA-Z0-9][-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]+[-_~*(a-zA-Z0-9;/?@&=+$%#])");
// process global variable
if (stringToBoolean(liberator.globalVariables.auto_append_anchor, false)) {
@@ -72,11 +72,13 @@
result++;
// build URL
- let href = 'h' + RegExp.$1 + '://' + RegExp.$2;
+ let scheme = RegExp.$1, host = RegExp.$2, lastMatch = RegExp.lastMatch;
+ if (/^ttps?$/(scheme)) scheme = 'h' + scheme;
+ let href = scheme + '://' + host;
// reset range
range.setStart(node, start);
- range.setEnd(node, start + RegExp.lastMatch.length);
+ range.setEnd(node, start + lastMatch.length);
// build anchor element
let anchor = doc.createElement('a');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment