PageSourceSearch

https://www.kimsoonim.com/addons/autolink/autolink.js?t=1790053829

js kimsoonim.com collected 2026-10-08 22:56:08 UTC 3,576 bytes, 117 lines download raw bytes

1/**
2 * @file autolink.js
3 * @brief javascript code for autolink addon
4 * @author NAVER ([email protected])
5 */
6(function($){
7	var protocol_re = '(?:(?:https?|ftp|news|telnet|irc|mms)://)';
8	var domain_re   = '(?:[^\\s./\'"&;)>]+\\.)+[^\\s./\'"&;)>]+';
9	var max_255_re  = '(?:1[0-9]{2}|2[0-4][0-9]|25[0-5]|[1-9]?[0-9])';
10	var ip_re       = '(?:'+max_255_re+'\\.){3}'+max_255_re;
11	var port_re     = '(?::([0-9]+))?';
12	var user_re     = '(?:/~\\w+)?';
13	var path_re     = '(?:/[^\\s]*)?';
14	var hash_re     = '(?:#[^\\s]*)?';
15
16	var url_regex = new RegExp('('+protocol_re+'('+domain_re+'|'+ip_re+'|localhost'+')'+port_re+user_re+path_re+hash_re+')', 'ig');
17
18	var AutoLink = xe.createPlugin("autolink", {
19		targets : [],
20		init : function() {
21			this.targets = [];
22		},
23		API_ONREADY : function() {
24			var thisPlugin = this;
25
26			// extract target text nodes
27			this.extractTargets($('.rhymix_content, .xe_content'));
28
29			$(this.targets).each(function(){
30				thisPlugin.cast('AUTOLINK', [this]);
31			});
32		},
33		API_AUTOLINK : function(oSender, params) {
34			var textNode = params[0];
35			if(!$(textNode).parent().length || $(textNode).parent().get(0).nodeName.toLowerCase() == 'a') return;
36			var content  = textNode.nodeValue;
37			var dummy    = $('<span>');
38
39			content = content.escape();
40			content = content.replace(url_regex, function(match, p1, offset, string) {
41				var match;
42				var suffix = '';
43				var attribute = '';
44				if (p1.indexOf('(') < 0 && p1.match(/\)$/)) {
45					p1 = p1.replace(/\)$/, '');
46					suffix = ')';
47				} else if (p1.indexOf('[') < 0 && p1.match(/\]$/)) {
48					p1 = p1.replace(/\]$/, '');
49					suffix = ']';
50				} else if (p1.indexOf('&lt;') < 0 && p1.match(/&gt;$/)) {
51					p1 = p1.replace(/&gt;$/, '');
52					suffix = '&gt;';
53				}
54				if (match = /^([\x21-\x7E]+\.[a-z]+)([가-힣]{1,3})$/.exec(p1)) {
55					p1 = match[1];
56					suffix = match[2] + suffix;
57				}
58				if (match = /^(.*?)(&(lt|gt|quot);.*)$/i.exec(p1)) {
59					p1 = match[1];
60					suffix = match[2] + suffix;
61				}
62				console.log(p1, suffix);
63				if(!isSameOrigin(location.href, p1)) {
64					attribute = ' target="_blank"';
65				}
66				return '<a href="' + p1 + '"' + attribute + '>' + p1 + '</a>' + suffix;
67			});
68
69			$(textNode).before(dummy);
70			$(textNode).replaceWith(content);
71			params[0] = dummy.next('a');
72			dummy.remove();
73		},
74		extractTargets : function(obj) {
75			var thisPlugin = this;
76			var wrap = $('.rhymix_content, .xe_content', obj);
77			if(wrap.length) {
78				this.extractTargets(wrap);
79				return;
80			}
81
82			$(obj).contents().each(function(){
83				var node_name = this.nodeName.toLowerCase();
84				if($.inArray(node_name, ['a', 'pre', 'xml', 'textarea', 'input', 'select', 'option', 'code', 'script', 'style', 'iframe', 'button', 'img', 'embed', 'object', 'ins']) != -1) return;
85
86				// FIX ME : When this meanless code wasn't executed, url_regex do not run correctly. why?
87				url_regex.exec('');
88
89				if(this.nodeType == 3) { // text node
90					var content = this.nodeValue;
91
92					if(content.length < 5) return;
93
94					if(!/(http|https|ftp|news|telnet|irc|mms):\/\//i.test(content)) return;
95
96					thisPlugin.targets.push(this);
97				} else {
98					thisPlugin.extractTargets(this);
99				}
100			});
101		}
102	});
103
104	xe.registerPlugin(new AutoLink());
105
106	$(document).on('click', '.rhymix_content a, .xe_content a', function() {
107		var $this = $(this);
108		var href = $this.attr('href');
109		if(!href || /^(?:javascript|mailto):|#/.test(href)) {
110			return;
111		}
112		if (!$this.attr("target") && !isSameOrigin(location.href, href)) {
113			$this.attr("target", "_blank");
114		}
115	});
116
117})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.