티스토리 뷰

출처 및 참고 : http://blog.showjean.com/137



브라우저가 크롬일 경우 F12로 개발자 도구를 열어서

Elements 탭 아래(html 태그 바로 위)에 보면 아래 스크립트가 삽입되어 있음.



==> 

<script type="text/javascript">

var rule = /(?:(?=(?:http|https):)([a-zA-Z][-+.a-zA-Z\d]*):(?:((?:[-_.!~*'()a-zA-Z\d;?:@&=+$,]|%[a-fA-F\d]{2})(?:[-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]]|%[a-fA-F\d]{2})*)|(?:(?:\/\/(?:(?:(?:((?:[-_.!~*'()a-zA-Z\d;:&=+$,]|%[a-fA-F\d]{2})*)@)?(?:((?:(?:(?:[a-zA-Z\d](?:[-a-zA-Z\d]*[a-zA-Z\d])?)\.)*(?:[a-zA-Z](?:[-a-zA-Z\d]*[a-zA-Z\d])?)\.?|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[(?:(?:[a-fA-F\d]{1,4}:)*(?:[a-fA-F\d]{1,4}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|(?:(?:[a-fA-F\d]{1,4}:)*[a-fA-F\d]{1,4})?::(?:(?:[a-fA-F\d]{1,4}:)*(?:[a-fA-F\d]{1,4}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))?)\]))(?::(\d*))?))?|((?:[-_.!~*'()a-zA-Z\d$,;:@&=+]|%[a-fA-F\d]{2})+))|(?!\/\/))(\/(?:[-_.!~*'()a-zA-Z\d:@&=+$,]|%[a-fA-F\d]{2})*(?:;(?:[-_.!~*'()a-zA-Z\d:@&=+$,]|%[a-fA-F\d]{2})*)*(?:\/(?:[-_.!~*'()a-zA-Z\d:@&=+$,]|%[a-fA-F\d]{2})*(?:;(?:[-_.!~*'()a-zA-Z\d:@&=+$,]|%[a-fA-F\d]{2})*)*)*)?)(?:\?((?:[-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]]|%[a-fA-F\d]{2})*))?)(?:\#((?:[-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]]|%[a-fA-F\d]{2})*))?)/gim;

function makeHTML(textNode) {


var source = textNode.data;

return source.replace(rule, function() {

var url = arguments[0];

var a = jQuery('<a></a>').attr({

'href' : url,

'target' : '_blank'

}).text(url);

return url.match(/^https?:\/\/$/) ? url : jQuery('<div></div>').append(

a).html();

});

};

function eachText(node, callback) {

jQuery.each(node.childNodes, function() {

if (this.nodeType != 8 && this.nodeName != 'A') {

this.nodeType != 1 ? callback(this) : eachText(this, callback);

}

});

};

function autolink(obj) {

return obj.each(function() {

var queue = [];

eachText(this, function(e) {

var html = makeHTML(e);

if (html != e.data) {

queue.push([ e, makeHTML(e) ]);

}

});

jQuery.each(queue, function(i, x) {

jQuery(x[0]).replaceWith(x[1]);

});

});

}

</script>

<script type="text/javascript">

$(document).ready(function(){

autolink($("#contents"));

});

</script>

댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함