2016-06-10 6 views
0

Google 사이트에서 채팅을하고 개선하기를 원합니다. 사용자는 종종 뉴스 사이트, 기사, YouTube 동영상 등 서로 링크를 보내는URL 구문 분석으로 멋진 스 니펫 만들기 (WhatsApp, Viber, Skype 등)

우리는 약간의 정보와 함께 일명 "조각" 여기 예를 좋은 이미지에 해당 링크를 변환 할

예, 페이스 북의 채팅 : http://c2n.me/3z442bv.jpg 스카이프 : http://c2n.me/3z44a60.jpg

하지만 복잡한 작업 인 자체 파서를 프로그래밍하는 것을 의미합니다. 준비된 도서관, 그러한 서비스를 제공하는 사이트가 있습니까?

감사합니다.

+0

(플러그인 코드 GitHub의 저장소 위에서) 사람하십시오! 우리는이 기능이 정말로 필요합니다. – wannaknow

답변

0

당신은 예를 오픈 그래프 파서
(JQuery와의 오픈 그래프 파서)를 사용할 수 있으며 다른 많은 파서 https://github.com/fiann/jquery.ogp

요즘 대부분 모든 웹 사이트 오픈 그래프 태그를 사용
을 찾을 수 있습니다.

편집

(function($) { 

    var checkNamespacePresent = function (node) { 
    console.log("Checking for namespace on node", node); 
    var i, attr, attributes = node.attributes || {}; 
    // we're looking for xmlns:og="http://opengraphprotocol.org/schema/" 
    for (i = 0; i < attributes.length; i++) { 
     attr = attributes[i]; 
     if (attr.nodeName.substring(0,5) === "xmlns" && 
      attr.nodeValue === "http://opengraphprotocol.org/schema/") { 
     return attr.nodeName.substring(6); 
     } 
    } 
    return null; 
    } 

    $.fn.ogp = function() { 
    var ns = null, data = {}; 
    $(this).each(function() { 
     $(this).parents().andSelf().each(function() { 
     ns = checkNamespacePresent(this); 
     console.log("Found %s on", ns, this); 
     if (ns !== null) { 
      return false; 
     } 
     }); 

     // give up if no namespace 
     if (ns === null) { 
     console.log("No namespace found"); 
     return null; 
     } 

     // look for OGP data 
     ns = ns + ":"; 
     $('meta', this).each(function() { 
     console.log("Looking for data in element", this); 
     var prop = $(this).attr("property"), key, value; 
     if (prop && prop.substring(0, ns.length) === ns) { 
      key = prop.substring(ns.length); 
      value = $(this).attr("content"); 
      console.log("Found OGP data %s=%s", key, value); 
      data[key] = data[key] || []; 
      data[key].push(value); 
     } 
     }); 
    }); 

    // this is the total of everything 
    console.log("All the data is ", data); 

    return data; 
    } 
})(jQuery); 
+0

이 링크가 질문에 대답 할 수 있지만 여기에 답변의 핵심 부분을 포함시키고 참조 용 링크를 제공하는 것이 좋습니다. 링크 된 페이지가 변경되면 링크 전용 답변이 유효하지 않게 될 수 있습니다. – ekad

+0

감사합니다. 플러그인 코드가 추가되었습니다. –