1// å ¨è§ã»åè§ãèæ ®ãã¦æååããã¤ãæ°ã§åãè©°ãã颿° 2const truncateTextByByte = (text, maxLength = 108) => { 3 let currentByteLength = 0; 4 let result = ""; 5 for (let i = 0; i < text.length; i++) { 6 const char = text.charAt(i); 7 const byteLength = char.charCodeAt(0) >= 0x00 && char.charCodeAt(0) <= 0x7f ? 1 : 2; 8 if (currentByteLength + byteLength > maxLength * 2) { 9 return result + "â¦"; 10 } 11 currentByteLength += byteLength; 12 result += char; 13 } 14 return result; 15}; 16 17window.addEventListener("load", function () { 18 // å¤é¨ãã¡ã¤ã«(jsonçï¼èªã¿è¾¼ã¿å¾çºç«ãã 19 const shareUrl = location.href; 20 const pageTitle = document.title; 21 const shareText = truncateTextByByte(pageTitle, 108); 22 23 // Xãã¿ã³æ¿å ¥ 24 const tw = document.getElementById("snsBtn_tw"); 25 if (tw) { 26 const a = document.createElement("a"); 27 a.className = "twitter-share-button"; 28 a.href = "https://twitter.com/share"; 29 a.setAttribute("data-url", shareUrl); 30 a.setAttribute("data-text", shareText); 31 a.setAttribute("data-hashtags", "morajp"); 32 a.setAttribute("data-lang", "ja"); 33 a.setAttribute("data-show-count", "false"); 34 a.innerText = "ãã¹ã"; 35 tw.appendChild(a); 36 37 if (window.twttr && window.twttr.widgets) { 38 window.twttr.widgets.load(tw); 39 } 40 } 41 42 // Facebookãã¿ã³ï¼ã·ã§ã¢ãã¿ã³ï¼ãæ¿å ¥ 43 const fbElement = document.getElementById("snsBtn_fb"); 44 if (fbElement) { 45 // æ¢åã®ã³ã³ãã³ããã¯ãªã¢ 46 // ããã«ãããããå¤ã<iframe>ãæ®ã£ã¦ãã¦ãåé¤ããã¾ãã 47 fbElement.innerHTML = ""; 48 49 // ã·ã§ã¢ãã¿ã³ã®ã³ã³ããã¨ãªã<div>è¦ç´ ãçæ 50 const shareButtonDiv = document.createElement("div"); 51 // â éè¦: Facebook SDKãã·ã§ã¢ãã¿ã³ã¨ãã¦èªèããã¯ã©ã¹ 52 shareButtonDiv.classList.add("fb-share-button"); 53 54 // ã·ã§ã¢å¯¾è±¡ã®URLãè¨å® 55 // `shareUrl` ã¯ããã®é¢æ°ãå¼ã³åºãããã¹ã³ã¼ãã§å®ç¾©ããã¦ããã¨ä»®å®ãã¾ãã 56 // ä¾: const shareUrl = location.href; 57 shareButtonDiv.setAttribute("data-href", shareUrl); 58 59 // ã¬ã¤ã¢ã¦ã: ã·ã§ã¢æ°ãªãã®ã·ã³ãã«ãªãã¿ã³ 60 shareButtonDiv.setAttribute("data-layout", "button"); 61 // ãµã¤ãº 62 shareButtonDiv.setAttribute("data-size", "small"); 63 64 // çæããã·ã§ã¢ãã¿ã³ã®<div>è¦ç´ ããã¼ã¸ã«è¿½å 65 fbElement.appendChild(shareButtonDiv); 66 67 // Facebook SDKããã¼ãæ¸ã¿ã§ããã°ãåçã«è¿½å ããããã¿ã³ããã¼ã¹ãã¦ã¬ã³ããªã³ã°ãã 68 // ããã«ãããJavaScriptã§è¿½å ããããã¿ã³ãFacebookã¦ã£ã¸ã§ããã¨ãã¦æ©è½ãã¾ãã 69 if (typeof FB !== "undefined" && FB.XFBML) { 70 FB.XFBML.parse(fbElement); // fbElementå ã®æ°ããXFBMLã¿ã°ããã¼ã¹ãã 71 } else { 72 // SDKãã¾ã ãã¼ãããã¦ããªããã¾ãã¯å©ç¨ã§ããªãå ´åã®è¦å 73 // async/deferã§SDKãèªã¿è¾¼ãã§ããå ´åãé常ã¯ãã®è¦åã¯åºãªãã¯ãã§ãã 74 console.warn("Facebook SDK not yet loaded or FB.XFBML is unavailable. Share button may render late."); 75 } 76 } 77});
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.