1/** 2 * çµ±åã¯ããã¼åæç®¡çã·ã¹ãã 3 * ã¯ããã¼åæå¾ã¾ãã¯ãã§ã«åææ¸ã¿ã®å ´åã®ã¿æå®ãããã¢ã¯ã·ã§ã³ãå®è¡ 4 * - å¤é¨ã¹ã¯ãªããã®èªã¿è¾¼ã¿ 5 * - YouTubeåç»ã®èªã¿è¾¼ã¿ 6 * - DOMè¦ç´ ã®æ´æ° 7 * - GTM/Analyticsçã®ãã©ããã³ã°ã¹ã¯ãªããã®ãããã¯å¼·å 8 */ 9(function() { 10 'use strict'; 11 12 // ããã©ã«ãè¨å® 13 const DEFAULT_CONFIG = { 14 cookieName: '_ul_cookie_consent', 15 allowValue: 'allow', 16 eventName: 'allow_cookie', 17 debug: false, 18 19 // ã¹ã¯ãªããããããã³ã°è¨å®ï¼GTM対å¿å¼·åï¼ 20 blocking: { 21 enabled: true, 22 // ãããã¯å¯¾è±¡ã®ã¹ã¯ãªãã屿§ 23 blockAttribute: 'data-cookieyes', 24 // ãããã¯å¯¾è±¡ã®ã¹ã¯ãªããsrcï¼é¨åä¸è´ï¼- GTMãã¿ã¼ã³å¼·å 25 blockPatterns: [ 26 'google-analytics.com/ga.js', 27 'google-analytics.com/analytics.js', 28 'googletagmanager.com/gtag/js', 29 'googletagmanager.com/gtm.js', 30 'www.googletagmanager.com/gtm.js', // 追å : wwwä»ããã¿ã¼ã³ 31 'googletagmanager.com/ns.html', // 追å : noscriptç¨ 32 'www.googletagmanager.com/ns.html', // 追å : wwwä»ãnoscript 33 'facebook.net/en_US/fbevents.js', 34 'connect.facebook.net', 35 'doubleclick.net', 36 'googlesyndication.com' 37 ], 38 // ãããã¯å¯¾è±¡ã®inlineã¹ã¯ãªãããã¿ã¼ã³ï¼GTM対å¿å¼·åï¼ 39 inlineBlockPatterns: [ 40 'gtag(', 41 'ga(', 42 '_gaq', 43 'fbq(', 44 'GoogleAnalyticsObject', 45 'dataLayer', // 追å : GTM dataLayer 46 'gtm_id', // 追å : GTM ID 47 'GTM-' // 追å : GTM-ã§å§ã¾ãæåå 48 ] 49 }, 50 51 // ã¹ã¯ãªããèªã¿è¾¼ã¿è¨å®ï¼æ¡ä»¶ä»ãèªã¿è¾¼ã¿å¯¾å¿ï¼ 52 scripts: [ 53 { 54 src: 'https://form.nitoms.com/web/mrcform.js', 55 dataId: 'd9xzkh', 56 delay: 0, // 次ã®ã¹ã¯ãªããèªã¿è¾¼ã¿åã®å¾ æ©æéï¼msï¼ 57 // ãã¹æ¡ä»¶è¨å® 58 pathConditions: { 59 enabled: true, 60 // 許å¯ãããã¹ãã¿ã¼ã³ï¼æ£è¦è¡¨ç¾æååï¼ 61 allowedPaths: ['^/special/linetape/.*'], 62 // æåã§æå®ãããã¹ï¼å®å ¨ä¸è´ï¼ 63 manualPaths: [], 64 // ãããã°ã¢ã¼ãï¼æ¡ä»¶ãã§ãã¯çµæããã°åºå 65 debug: true 66 } 67 }, 68 { 69 src: '//ar.mrc-s.com/web/ar.js', 70 dataId: 'd9xzkh', 71 delay: 0, 72 // åãæ¡ä»¶ãé©ç¨ 73 pathConditions: { 74 enabled: true, 75 allowedPaths: ['^/special/linetape/.*'], 76 manualPaths: [], 77 debug: true 78 } 79 } 80 // GTMãåçèªã¿è¾¼ã¿ããå ´åã¯ä»¥ä¸ã®ã³ã¡ã³ãã¢ã¦ããè§£é¤ããGTM IDãè¨å® 81 // { 82 // src: 'https://www.googletagmanager.com/gtm.js?id=GTM-XXXXXXX', 83 // delay: 0, 84 // attributes: { 85 // async: 'true' 86 // } 87 // } 88 ], 89 90 // YouTubeåç»è¨å® 91 youtube: { 92 enabled: true,
93 videoSelector: '.js-video-frame', 94 baseUrl: 'https://www.youtube.com/embed/', 95 defaultParams: '?rel=0&showinfo=0', 96 defaultAllow: 'accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture', 97 observeMutations: true 98 }, 99 100 // DOMæ´æ°è¨å®ï¼GTM noscript対å¿è¿½å ï¼ 101 domUpdates: { 102 enabled: true, 103 actions: [ 104 { 105 selector: '.contact.-notice', 106 action: 'removeClass', 107 value: '-notice' 108 }, 109 { 110 selector: '.ul_notice', 111 action: 'hide' 112 }, 113 { 114 selector: 'a[data-mrc]', 115 action: 'enableLinks' 116 }, 117 // GTMé¢é£ã®noscriptã¿ã°ãé表示ã«ãã 118 { 119 selector: 'noscript iframe[src*="googletagmanager.com"]', 120 action: 'hide' 121 } 122 ] 123 } 124 }; 125 126 // ã°ãã¼ãã«ç¶æ 管ç 127 let config = {}; 128 let isTriggeredByEvent = false; 129 let scriptsLoaded = false; 130 let youtubeInitialized = false; 131 let isSystemInitialized = false; 132 let blockedScripts = []; 133 let originalScripts = []; 134 135 // ã°ãã¼ãã«ç¶æ ãwindowãªãã¸ã§ã¯ãã«è¨å® 136 window.__has_ul_consent = false; 137 138 /** 139 * è¨å®ããã¼ã¸ 140 * @param {Object} userConfig ã¦ã¼ã¶ã¼è¨å® 141 */ 142 function mergeConfig(userConfig = {}) { 143 config = Object.assign({}, DEFAULT_CONFIG, userConfig); 144 145 // ãã¹ãããããªãã¸ã§ã¯ãããã¼ã¸ 146 if (userConfig.blocking) { 147 config.blocking = Object.assign({}, DEFAULT_CONFIG.blocking, userConfig.blocking); 148 } 149 if (userConfig.youtube) { 150 config.youtube = Object.assign({}, DEFAULT_CONFIG.youtube, userConfig.youtube); 151 } 152 if (userConfig.domUpdates) { 153 config.domUpdates = Object.assign({}, DEFAULT_CONFIG.domUpdates, userConfig.domUpdates); 154 } 155 156 // ã¹ã¯ãªããè¨å®ã®è©³ç´°ãã¼ã¸ 157 if (userConfig.scripts && Array.isArray(userConfig.scripts)) { 158 config.scripts = userConfig.scripts.map((userScript, index) => { 159 const defaultScript = DEFAULT_CONFIG.scripts[index] || {}; 160 const mergedScript = Object.assign({}, defaultScript, userScript); 161 162 // pathConditions ã®è©³ç´°ãã¼ã¸ 163 if (userScript.pathConditions && defaultScript.pathConditions) { 164 mergedScript.pathConditions = Object.assign({}, defaultScript.pathConditions, userScript.pathConditions); 165 } 166 167 return mergedScript; 168 }); 169 } 170 } 171 172 /** 173 * ãããã°ãã°åºå 174 * @param {...any} args ãã°å¼æ° 175 */ 176 function debugLog(...args) { 177 if (config.debug) { 178 console.log('[CookieConsent]', ...args); 179 } 180 } 181 182 /** 183 * ç¾å¨ã®ãã¹ãæ¡ä»¶ã«åè´ããããã§ã㯠184 * @param {Object} pathConditions ãã¹æ¡ä»¶è¨å® 185 * @returns {boolean} åè´ããå ´åtrue 186 */ 187 function checkPathConditions(pathConditions) { 188 if (!pathConditions || !pathConditions.enabled) { 189 return true; // æ¡ä»¶ãç¡å¹ãªå ´åã¯å¸¸ã«è¨±å¯ 190 } 191 192 const currentPath = window.location.pathname; 193 194 if (pathConditions.debug) { 195 debugLog(`ãã¹æ¡ä»¶ãã§ã㯠- ç¾å¨ã®ãã¹: ${currentPath}`); 196 } 197 198 // æåæå®ãã¹ã®å®å ¨ä¸è´ãã§ã㯠199 if (pathConditions.manualPaths && pathConditions.manualPaths.length > 0) { 200 const manualMatch = pathConditions.manualPaths.includes(currentPath); 201 if (pathConditions.debug) { 202 debugLog(`æåãã¹ä¸è´ãã§ãã¯: ${manualMatch}`, pathConditions.manualPaths); 203 } 204 if (manualMatch) { 205 return true; 206 } 207 } 208 209 // æ£è¦è¡¨ç¾ãã¿ã¼ã³ãã§ã㯠210 if (pathConditions.allowedPaths && pathConditions.allowedPaths.length > 0) { 211 for (const pattern of pathConditions.allowedPaths) { 212 try { 213 const regex = new RegExp(pattern); 214 const regexMatch = regex.test(currentPath); 215 if (pathConditions.debug) { 216 debugLog(`æ£è¦è¡¨ç¾ãã¿ã¼ã³ "${pattern}" ãã§ãã¯: ${regexMatch}`); 217 } 218 if (regexMatch) { 219 return true; 220 } 221 } catch (error) { 222 console.error(`ç¡å¹ãªæ£è¦è¡¨ç¾ãã¿ã¼ã³: ${pattern}`, error); 223 } 224 } 225 } 226 227 if (pathConditions.debug) { 228 debugLog(`ãã¹æ¡ä»¶ãã§ãã¯çµæ: ä¸ä¸è´`); 229 } 230 return false;
231 } 232 233 /** 234 * ã¹ã¯ãªãããèªã¿è¾¼ã¿å¯è½ããã§ã㯠235 * @param {Object} scriptConfig ã¹ã¯ãªããè¨å® 236 * @returns {boolean} èªã¿è¾¼ã¿å¯è½ãªå ´åtrue 237 */ 238 function canLoadScript(scriptConfig) { 239 if (!scriptConfig.pathConditions) { 240 return true; // ãã¹æ¡ä»¶ããªãå ´åã¯å¸¸ã«è¨±å¯ 241 } 242 243 const canLoad = checkPathConditions(scriptConfig.pathConditions); 244 245 if (scriptConfig.pathConditions.debug || config.debug) { 246 debugLog(`ã¹ã¯ãªããèªã¿è¾¼ã¿å¯å¦: ${scriptConfig.src} -> ${canLoad ? '許å¯' : 'æå¦'}`); 247 } 248 249 return canLoad; 250 } 251 252 /** 253 * ã¯ããã¼ã®å¤ãåå¾ 254 * @param {string} name ã¯ããã¼å 255 * @returns {string|null} ã¯ããã¼ã®å¤ãåå¨ããªãå ´åã¯null 256 */ 257 function getCookieValue(name) { 258 const value = `; ${document.cookie}`; 259 const parts = value.split(`; ${name}=`); 260 if (parts.length === 2) { 261 return parts 262 .pop() 263 .split(';') 264 .shift(); 265 } 266 return null; 267 } 268 269 /** 270 * ã¯ããã¼åæç¶æ ããã§ã㯠271 * @returns {boolean} åææ¸ã¿ã®å ´åtrue 272 */ 273 function isConsentGiven() { 274 const cookieConsent = getCookieValue(config.cookieName); 275 return cookieConsent === config.allowValue; 276 } 277 278 /** 279 * ã¹ã¯ãªããããããã¯å¯¾è±¡ããã§ã㯠280 * @param {HTMLScriptElement} script ãã§ãã¯å¯¾è±¡ã®ã¹ã¯ãªããè¦ç´ 281 * @returns {boolean} ãããã¯å¯¾è±¡ã®å ´åtrue 282 */ 283 function shouldBlockScript(script) { 284 if (!config.blocking.enabled) return false; 285 286 // data-cookieyes屿§ãããå ´åã¯ããã㯠287 if (script.hasAttribute(config.blocking.blockAttribute)) { 288 return true; 289 } 290 291 // src屿§ã®ãã§ã㯠292 if (script.src) { 293 for (const pattern of config.blocking.blockPatterns) { 294 if (script.src.includes(pattern)) { 295 return true; 296 } 297 } 298 } 299 300 // ã¤ã³ã©ã¤ã³ã¹ã¯ãªããã®ãã§ã㯠301 if (!script.src && script.textContent) { 302 for (const pattern of config.blocking.inlineBlockPatterns) { 303 if (script.textContent.includes(pattern)) { 304 return true; 305 } 306 } 307 } 308 309 return false; 310 } 311 312 /** 313 * æ¢åã®ã¹ã¯ãªãããããã㯠314 */ 315 function blockExistingScripts() { 316 if (!config.blocking.enabled) return; 317 318 debugLog('æ¢åã¹ã¯ãªããã®ãããã¯å¦çéå§'); 319 320 const scripts = document.querySelectorAll('script'); 321 let blockedCount = 0; 322 323 scripts.forEach(script => { 324 if (shouldBlockScript(script)) { 325 // ãªãªã¸ãã«ã®å±æ§ãä¿å 326 const originalData = { 327 element: script, 328 src: script.src, 329 textContent: script.textContent, 330 attributes: {} 331 }; 332 333 // å ¨å±æ§ãä¿å 334 Array.from(script.attributes).forEach(attr => { 335 originalData.attributes[attr.name] = attr.value; 336 }); 337 338 originalScripts.push(originalData); 339 340 // ã¹ã¯ãªãããç¡å¹å 341 if (script.src) { 342 script.removeAttribute('src'); 343 } 344 script.textContent = ''; 345 script.type = 'text/plain'; 346 347 blockedScripts.push(script); 348 blockedCount++; 349 350 debugLog(`ã¹ã¯ãªããããããã¯ãã¾ãã: ${originalData.src || 'inline script'}`); 351 } 352 }); 353 354 debugLog(`${blockedCount}åã®ã¹ã¯ãªããããããã¯ãã¾ãã`); 355 } 356 357 /** 358 * ãããã¯ãããã¹ã¯ãªããã復å ã»å®è¡ 359 */ 360 function restoreBlockedScripts() { 361 if (!config.blocking.enabled || originalScripts.length === 0) return; 362 363 debugLog('ãããã¯ãããã¹ã¯ãªããã®å¾©å éå§'); 364 365 originalScripts.forEach((originalData, index) => { 366 try { 367 // æ°ããã¹ã¯ãªããè¦ç´ ã使 368 const newScript = document.createElement('script'); 369 370 // 屿§ã復å 371 Object.entries(originalData.attributes).forEach(([name, value]) => { 372 if (name !== 'type') { 373 // typeã¯æå¾ã«è¨å® 374 newScript.setAttribute(name, value); 375 } 376 }); 377 378 // src ã¾ã㯠textContent ã復å 379 if (originalData.src) { 380 newScript.src = originalData.src; 381 } else { 382 newScript.textContent = originalData.textContent; 383 } 384 385 // typeã復å ï¼å®è¡å¯è½ã«ããï¼ 386 newScript.type = originalData.attributes.type || 'text/javascript'; 387 388 // å ã®è¦ç´ ãæ°ããè¦ç´ ã§ç½®ãæã 389 const oldScript = originalData.element; 390 if (oldScript.parentNode) { 391 oldScript.parentNode.insertBefore(newScript, oldScript); 392 oldScript.parentNode.removeChild(oldScript); 393 } 394 395 debugLog(`ã¹ã¯ãªããã復å ãã¾ãã: ${originalData.src || 'inline script'}`); 396 } catch (error) { 397 console.error('ã¹ã¯ãªãã復å ä¸ã«ã¨ã©ã¼ãçºçãã¾ãã:', error, originalData); 398 } 399 }); 400 401 // 復å å®äºå¾ã«ã¯ãªã¢ 402 originalScripts = []; 403 blockedScripts = []; 404 405 debugLog('ãããã¯ãããã¹ã¯ãªããã®å¾©å å®äº'); 406 } 407 408 /** 409 * æ°ããã¹ã¯ãªããã®è¿½å ãç£è¦ã»ããã㯠410 */ 411 function observeAndBlockNewScripts() { 412 if (!config.blocking.enabled || !window.MutationObserver) return; 413 414 const observer = new MutationObserver(mutations => { 415 if (isConsentGiven()) { 416 observer.disconnect(); 417 return; 418 } 419 420 mutations.forEach(mutation => {
421 mutation.addedNodes.forEach(node => { 422 if (node.tagName === 'SCRIPT' && shouldBlockScript(node)) { 423 debugLog('æ°ããã¹ã¯ãªããããããã¯:', node.src || 'inline'); 424 425 // ãªãªã¸ãã«ãã¼ã¿ãä¿å 426 const originalData = { 427 element: node, 428 src: node.src, 429 textContent: node.textContent, 430 attributes: {} 431 }; 432 433 Array.from(node.attributes).forEach(attr => { 434 originalData.attributes[attr.name] = attr.value; 435 }); 436 437 originalScripts.push(originalData); 438 439 // ã¹ã¯ãªãããç¡å¹å 440 if (node.src) { 441 node.removeAttribute('src'); 442 } 443 node.textContent = ''; 444 node.type = 'text/plain'; 445 446 blockedScripts.push(node); 447 } 448 }); 449 }); 450 }); 451 452 observer.observe(document, { 453 childList: true, 454 subtree: true 455 }); 456 457 debugLog('æ°ããã¹ã¯ãªããã®ç£è¦ãéå§'); 458 } 459 460 /** 461 * DOMè¦ç´ ãæ´æ° 462 */ 463 function updateDOM() { 464 if (!config.domUpdates.enabled) return; 465 466 try { 467 debugLog('DOMæ´æ°éå§'); 468 469 config.domUpdates.actions.forEach(actionConfig => { 470 const elements = document.querySelectorAll(actionConfig.selector); 471 472 elements.forEach(element => { 473 switch (actionConfig.action) { 474 case 'removeClass': 475 element.classList.remove(actionConfig.value); 476 break; 477 478 case 'addClass': 479 element.classList.add(actionConfig.value); 480 break; 481 482 case 'hide': 483 element.style.display = 'none'; 484 break; 485 486 case 'show': 487 element.style.display = ''; 488 break; 489 490 case 'enableLinks': 491 const url = element.getAttribute('data-mrc'); 492 if (url) { 493 element.href = url; 494 element.removeAttribute('style'); 495 } 496 break; 497 498 case 'setAttribute': 499 if (actionConfig.attribute && actionConfig.value !== undefined) { 500 element.setAttribute(actionConfig.attribute, actionConfig.value); 501 } 502 break; 503 504 case 'removeAttribute': 505 if (actionConfig.attribute) { 506 element.removeAttribute(actionConfig.attribute); 507 } 508 break; 509 510 default: 511 console.warn('æªç¥ã®DOMã¢ã¯ã·ã§ã³:', actionConfig.action); 512 } 513 }); 514 }); 515 516 debugLog('DOMæ´æ°å®äº'); 517 } catch (error) { 518 console.warn('DOMæ´æ°ä¸ã«ã¨ã©ã¼ãçºçãã¾ãã:', error); 519 } 520 } 521 522 /** 523 * ã¹ã¯ãªãããåçã«èªã¿è¾¼ã¿ 524 * @param {Object} scriptConfig ã¹ã¯ãªããè¨å® 525 * @returns {Promise} ã¹ã¯ãªããèªã¿è¾¼ã¿å®äºã®Promise 526 */ 527 function loadScript(scriptConfig) { 528 return new Promise((resolve, reject) => { 529 const script = document.createElement('script'); 530 script.src = scriptConfig.src; 531 532 // 追å 屿§ãè¨å® 533 if (scriptConfig.dataId) { 534 script.setAttribute('data-id', scriptConfig.dataId); 535 } 536 537 if (scriptConfig.attributes) { 538 Object.entries(scriptConfig.attributes).forEach(([key, value]) => { 539 script.setAttribute(key, value); 540 }); 541 } 542 543 script.onload = () => { 544 debugLog(`ã¹ã¯ãªããèªã¿è¾¼ã¿å®äº: ${scriptConfig.src}`); 545 resolve(); 546 }; 547 548 script.onerror = () => { 549 const error = new Error(`Failed to load script: ${scriptConfig.src}`); 550 console.error(error); 551 reject(error); 552 }; 553 554 document.body.appendChild(script); 555 }); 556 } 557 558 /** 559 * å ¨ã¹ã¯ãªãããé æ¬¡èªã¿è¾¼ã¿ï¼ç´åå®è¡ããã¹æ¡ä»¶ä»ãï¼ 560 */ 561 async function loadAllScripts() { 562 if (scriptsLoaded || config.scripts.length === 0) { 563 if (scriptsLoaded) { 564 debugLog('ã¹ã¯ãªããã¯æ¢ã«èªã¿è¾¼ã¾ãã¦ãã¾ã'); 565 } 566 return; 567 } 568 569 try {
570 debugLog('å¤é¨ã¹ã¯ãªããèªã¿è¾¼ã¿éå§ï¼é 次å®è¡ããã¹æ¡ä»¶ãã§ãã¯ä»ãï¼'); 571 572 let loadedCount = 0; 573 let skippedCount = 0; 574 575 // ã¹ã¯ãªãããé æ¬¡èªã¿è¾¼ã¿ï¼åã®ã¹ã¯ãªãããå®äºãã¦ããæ¬¡ãéå§ï¼ 576 for (let i = 0; i < config.scripts.length; i++) { 577 const scriptConfig = config.scripts[i]; 578 579 // ãã¹æ¡ä»¶ãã§ã㯠580 if (!canLoadScript(scriptConfig)) { 581 debugLog(`ã¹ã¯ãªãããã¹ããã (ãã¹æ¡ä»¶ä¸ä¸è´): ${scriptConfig.src}`); 582 skippedCount++; 583 continue; 584 } 585 586 debugLog( 587 `ã¹ã¯ãªãã ${loadedCount + 1}/${config.scripts.length - skippedCount} èªã¿è¾¼ã¿éå§: ${scriptConfig.src}` 588 ); 589 590 await loadScript(scriptConfig); 591 loadedCount++; 592 593 debugLog(`ã¹ã¯ãªãã ${loadedCount}/${config.scripts.length - skippedCount} èªã¿è¾¼ã¿å®äº: ${scriptConfig.src}`); 594 595 // 次ã®ã¹ã¯ãªããèªã¿è¾¼ã¿åã«å°ãå¾ æ©ï¼å¿ è¦ã«å¿ãã¦ï¼ 596 if (scriptConfig.delay && i < config.scripts.length - 1) { 597 debugLog(`${scriptConfig.delay}ms å¾ æ©ä¸...`); 598 await new Promise(resolve => setTimeout(resolve, scriptConfig.delay)); 599 } 600 } 601 602 scriptsLoaded = true; 603 debugLog(`ã¹ã¯ãªããèªã¿è¾¼ã¿å®äº: ${loadedCount}åèªã¿è¾¼ã¿ã${skippedCount}åã¹ããã`); 604 } catch (error) { 605 console.error('ã¹ã¯ãªããèªã¿è¾¼ã¿ä¸ã«ã¨ã©ã¼ãçºçãã¾ãã:', error); 606 } 607 } 608 609 /** 610 * YouTube iframeã使 611 * @param {HTMLElement} element 対象è¦ç´ 612 * @returns {HTMLIFrameElement|null} 使ãããiframeã失ææã¯null 613 */ 614 function createSingleYoutubeFrame(element) { 615 try { 616 const id = element.getAttribute('data-video-id'); 617 if (!id) { 618 console.warn('data-video-id屿§ãè¦ã¤ããã¾ãã:', element); 619 return null; 620 } 621 622 // æ¢ã«iframeãåå¨ããããã§ã㯠623 if (element.querySelector('iframe')) { 624 debugLog('æ¢ã«iframeãåå¨ãã¾ã:', id); 625 return null; 626 } 627 628 const frameId = element.getAttribute('data-frame-id'); 629 const style = element.getAttribute('data-style'); 630 const doClick = element.getAttribute('data-doclick'); 631 const allowed = element.getAttribute('data-allow'); 632 633 // iframeè¦ç´ ã使 634 const iframe = document.createElement('iframe'); 635 iframe.src = `${config.youtube.baseUrl}${id}${config.youtube.defaultParams}`; 636 iframe.allow = allowed || config.youtube.defaultAllow; 637 iframe.allowFullscreen = true; 638 639 // 追å 屿§ã®è¨å® 640 if (frameId && frameId.trim()) { 641 iframe.setAttribute('id', frameId); 642 } 643 644 if (style && style.trim()) { 645 iframe.setAttribute('style', style); 646 } 647 648 if (doClick && doClick.trim()) { 649 iframe.setAttribute('onclick', doClick); 650 } 651 652 element.appendChild(iframe); 653 debugLog(`YouTubeåç»ãèªã¿è¾¼ã¿ã¾ãã: ${id}`); 654 return iframe; 655 } catch (error) { 656 console.error('YouTube iframe使ä¸ã«ã¨ã©ã¼ãçºçãã¾ãã:', error, element); 657 return null; 658 } 659 } 660 661 /** 662 * å ¨ã¦ã®YouTubeåç»ãã¬ã¼ã ã使 663 */ 664 function createYoutubeFrames() { 665 if (!config.youtube.enabled) return; 666 667 const videos = document.querySelectorAll(config.youtube.videoSelector); 668 669 if (videos.length === 0) { 670 debugLog('YouTubeåç»è¦ç´ ãè¦ã¤ããã¾ããã§ãã'); 671 return; 672 } 673 674 debugLog(`${videos.length}åã®YouTubeåç»è¦ç´ ãå¦çä¸...`); 675 676 let successCount = 0; 677 videos.forEach(video => { 678 if (video.nodeType === Node.ELEMENT_NODE) { 679 const iframe = createSingleYoutubeFrame(video); 680 if (iframe) { 681 successCount++; 682 } 683 } 684 }); 685 686 debugLog(`YouTubeåç»èªã¿è¾¼ã¿å®äº: ${successCount}/${videos.length}`); 687 } 688 689 /** 690 * æ°ãã追å ãããåç»è¦ç´ ã®ç£è¦ 691 */ 692 function observeNewVideos() { 693 if (!window.MutationObserver || !window.__has_ul_consent || !config.youtube.observeMutations) { 694 return; 695 } 696 697 if (!document.body) { 698 setTimeout(observeNewVideos, 100); 699 return; 700 } 701 702 const observer = new MutationObserver(mutations => { 703 mutations.forEach(mutation => {
704 mutation.addedNodes.forEach(node => { 705 if (node.nodeType === Node.ELEMENT_NODE) { 706 const newVideos = 707 node.matches && node.matches(config.youtube.videoSelector) 708 ? [node] 709 : node.querySelectorAll 710 ? node.querySelectorAll(config.youtube.videoSelector) 711 : []; 712 713 if (newVideos.length > 0) { 714 debugLog(`æ°ããYouTubeåç»è¦ç´ ãæ¤åº: ${newVideos.length}å`); 715 newVideos.forEach(video => { 716 createSingleYoutubeFrame(video); 717 }); 718 } 719 } 720 }); 721 }); 722 }); 723 724 observer.observe(document.body, { 725 childList: true, 726 subtree: true 727 }); 728 729 debugLog('YouTubeåç»ã®åç追å ç£è¦ãéå§'); 730 } 731 732 /** 733 * åæå¾ã®å ¨ã¦ã®å¦çãå®è¡ 734 */ 735 async function executeConsentActions() { 736 if (isSystemInitialized) { 737 debugLog('æ¢ã«åæåæ¸ã¿ã§ã'); 738 return; 739 } 740 741 debugLog('ã¯ããã¼åæç¢ºèªæ¸ã¿ - å¦çéå§'); 742 743 try { 744 // DOMæ´æ° 745 updateDOM(); 746 747 // ãããã¯ãããã¹ã¯ãªããã復å ã»å®è¡ 748 restoreBlockedScripts(); 749 750 // å¤é¨ã¹ã¯ãªããèªã¿è¾¼ã¿ï¼ãã¹æ¡ä»¶ãã§ãã¯ä»ãï¼ 751 await loadAllScripts(); 752 753 // YouTubeåç»åæå 754 if (config.youtube.enabled) { 755 createYoutubeFrames(); 756 window.__UL_F_CONSENT = createYoutubeFrames; 757 758 // åç追å ã®ç£è¦ãéå§ 759 if (config.youtube.observeMutations) { 760 setTimeout(observeNewVideos, 1000); 761 } 762 } 763 764 // ã°ãã¼ãã«ç¶æ ãæ´æ° 765 window.__has_ul_consent = true; 766 isSystemInitialized = true; 767 768 debugLog('å ¨ã¦ã®å¦çãå®äºãã¾ãã'); 769 770 // ã¤ãã³ãçµç±ã§å®è¡ãããå ´åãwindow loadã¤ãã³ããçºç« 771 if (isTriggeredByEvent) { 772 debugLog('window loadã¤ãã³ããçºç«'); 773 window.dispatchEvent(new Event('load')); 774 } 775 } catch (error) { 776 console.error('åæå¦çä¸ã«ã¨ã©ã¼ãçºçãã¾ãã:', error); 777 } 778 } 779 780 /** 781 * åæã¤ãã³ãã®ãã³ãã©ã¼ 782 */ 783 function handleConsentEvent() { 784 debugLog('ã¯ããã¼åæã¤ãã³ããåä¿¡'); 785 isTriggeredByEvent = true; 786 787 // ã¤ãã³ãå¾ã«ã¯ããã¼ãæ£ããè¨å®ããã¦ãããåç¢ºèª 788 setTimeout(() => { 789 if (isConsentGiven()) { 790 executeConsentActions(); 791 } else { 792 console.warn('åæã¤ãã³ãå¾ãã¯ããã¼ãè¨å®ããã¦ãã¾ãã'); 793 } 794 }, 100); 795 } 796 797 /** 798 * ã¤ãã³ããªã¹ãã¼ãã»ããã¢ãã 799 */ 800 function setupEventListener() { 801 function waitForBody() { 802 if (document.body) { 803 debugLog('ã¯ããã¼åæã¤ãã³ããªã¹ãã¼ãè¨å®'); 804 document.body.addEventListener(config.eventName, handleConsentEvent, { 805 once: true 806 }); 807 } else { 808 setTimeout(waitForBody, 10); 809 } 810 } 811 waitForBody(); 812 } 813 814 /** 815 * DOMæºåå®äºã確å®ã«å¾ 㤠816 * @param {Function} callback å®è¡ããã³ã¼ã«ããã¯é¢æ° 817 */ 818 function ensureDOMReady(callback) { 819 if (document.readyState === 'loading') { 820 document.addEventListener('DOMContentLoaded', callback, {once: true}); 821 } else { 822 callback(); 823 } 824 } 825 826 /** 827 * åæåå¦ç 828 */ 829 function initialize() { 830 debugLog('çµ±åã¯ããã¼åæç®¡çã·ã¹ãã åæå'); 831 832 // ã¹ã¯ãªããããããã³ã°ãéå§ 833 if (config.blocking.enabled && !isConsentGiven()) { 834 blockExistingScripts(); 835 observeAndBlockNewScripts(); 836 } 837 838 if (isConsentGiven()) { 839 debugLog('ã¯ããã¼åææ¸ã¿ - å³åº§ã«å¦çå®è¡'); 840 ensureDOMReady(executeConsentActions); 841 } else { 842 debugLog('ã¯ããã¼æªåæ - åæã¤ãã³ãå¾ æ©ä¸'); 843 setupEventListener(); 844 } 845 } 846 847 /** 848 * ã·ã¹ãã éå§ 849 * @param {Object} userConfig ã¦ã¼ã¶ã¼è¨å® 850 */ 851 function start(userConfig = {}) { 852 mergeConfig(userConfig); 853 854 if (document.readyState === 'loading') { 855 document.addEventListener('DOMContentLoaded', initialize, {once: true}); 856 } else { 857 initialize(); 858 } 859 } 860 861 /**
862 * GTMãããã¯ç¶æ³ã確èªãããããã°é¢æ° 863 */ 864 function checkGTMBlocking() { 865 console.log('=== GTM ããããã³ã°ç¶æ³ ==='); 866 console.log('åæç¶æ³:', isConsentGiven()); 867 console.log('åæåç¶æ³:', isSystemInitialized); 868 console.log('ãããã¯æ¸ã¿ã¹ã¯ãªããæ°:', blockedScripts.length); 869 console.log('復å 対象ã¹ã¯ãªããæ°:', originalScripts.length); 870 871 // GTMé¢é£ã¹ã¯ãªããã®ç¢ºèª 872 const gtmScripts = document.querySelectorAll('script[src*="googletagmanager.com"]'); 873 console.log('GTMã¹ã¯ãªããè¦ç´ æ°:', gtmScripts.length); 874 875 gtmScripts.forEach((script, index) => { 876 console.log(`GTMã¹ã¯ãªãã${index + 1}:`, { 877 src: script.src, 878 type: script.type, 879 blocked: script.type === 'text/plain' 880 }); 881 }); 882 883 // noscriptå ã®GTMãç¢ºèª 884 const noscriptGTM = document.querySelectorAll('noscript iframe[src*="googletagmanager.com"]'); 885 console.log('GTM noscriptè¦ç´ æ°:', noscriptGTM.length); 886 } 887 888 // ã°ãã¼ãã«APIã¨ãã¦å ¬é 889 window.CookieConsentManager = { 890 start: start, 891 892 // è¨å®ç¨ã®ãã«ãã¼ 893 createConfig: function(options = {}) { 894 return { 895 debug: options.debug || false, 896 scripts: options.scripts || [], 897 youtube: { 898 enabled: options.youtube !== false, 899 videoSelector: options.youtubeSelector || '.js-video-frame', 900 ...options.youtubeConfig 901 }, 902 blocking: { 903 enabled: options.blocking !== false, 904 ...options.blockingConfig 905 }, 906 domUpdates: { 907 enabled: options.domUpdates !== false, 908 actions: options.domActions || DEFAULT_CONFIG.domUpdates.actions 909 }, 910 ...options 911 }; 912 }, 913 914 // ãã¹æ¡ä»¶ã®ãã«ãã¼é¢æ° 915 createPathCondition: function(allowedPaths = [], manualPaths = [], debug = false) { 916 return { 917 enabled: true, 918 allowedPaths: Array.isArray(allowedPaths) ? allowedPaths : [allowedPaths], 919 manualPaths: Array.isArray(manualPaths) ? manualPaths : [manualPaths], 920 debug: debug 921 }; 922 }, 923 924 // ç¶æ 確èªç¨ï¼ãããã°ç¨ï¼ 925 debug: { 926 isConsentGiven: () => isConsentGiven(), 927 isInitialized: () => isSystemInitialized, 928 scriptsLoaded: () => scriptsLoaded, 929 youtubeCount: () => document.querySelectorAll(config.youtube?.videoSelector || '.js-video-frame').length, 930 loadedYoutubeCount: () => 931 document.querySelectorAll(`${config.youtube?.videoSelector || '.js-video-frame'} iframe`).length, 932 blockedScriptsCount: () => blockedScripts.length, 933 originalScriptsCount: () => originalScripts.length, 934 forceExecute: executeConsentActions, 935 config: () => config, 936 currentPath: () => window.location.pathname, 937 checkPathForScript: scriptIndex => { 938 const script = config.scripts[scriptIndex]; 939 return script ? canLoadScript(script) : false; 940 }, 941 testPathCondition: checkPathConditions, 942 // GTMããããã³ã°ç¶æ³ç¢ºèªé¢æ°ã追å 943 checkGTMBlocking: checkGTMBlocking 944 } 945 }; 946 947 // ããã©ã«ãã§èªåéå§ï¼å¾æ¹äºææ§ã®ããï¼ 948 start(); 949})(); 950 951// ============================================================================= 952// GTMããããã³ã°å¼·åè¨å®ï¼ä½¿ç¨ä¾ï¼ 953// 以ä¸ã®è¨å®ã¯å¿ è¦ã«å¿ãã¦ã³ã¡ã³ãã¢ã¦ããè§£é¤ãã¦ä½¿ç¨ãã¦ãã ãã 954// ============================================================================= 955 956/* 957// ã«ã¹ã¿ã è¨å®ã§GTMããããã³ã°ãå¼·åããå ´åã®ä¾ 958const customGTMConfig = { 959 debug: true, 960 961 // æ¢åã®scriptsè¨å®ã«å ãã¦ãGTMãåçèªã¿è¾¼ã¿ãããå ´å 962 scripts: [ 963 // æ¢åã®ã¹ã¯ãªããè¨å® 964 { 965 src: 'https://form.nitoms.com/web/mrcform.js', 966 dataId: 'd9xzkh', 967 delay: 0, 968 pathConditions: { 969 enabled: true, 970 allowedPaths: ['^/special/linetape/.*'], 971 manualPaths: [], 972 debug: true 973 } 974 }, 975 { 976 src: '//ar.mrc-s.com/web/ar.js', 977 dataId: 'd9xzkh', 978 delay: 0, 979 pathConditions: { 980 enabled: true, 981 allowedPaths: ['^/special/linetape/.*'], 982 manualPaths: [], 983 debug: true 984 } 985 }, 986 // GTMãåæå¾ã«åçèªã¿è¾¼ã¿ããå ´åï¼GTM IDãå®éã®å¤ã«å¤æ´ï¼ 987 { 988 src: 'https://www.googletagmanager.com/gtm.js?id=GTM-XXXXXXX', 989 delay: 100, 990 attributes: { 991 async: 'true' 992 } 993 } 994 ], 995 996 // 追å ã®DOMæä½ãå¿ è¦ãªå ´å 997 domUpdates: { 998 enabled: true, 999 actions: [ 1000 { 1001 selector: '.contact.-notice', 1002 action: 'removeClass', 1003 value: '-notice' 1004 }, 1005 { 1006 selector: '.ul_notice', 1007 action: 'hide' 1008 }, 1009 { 1010 selector: 'a[data-mrc]', 1011 action: 'enableLinks' 1012 }, 1013 // GTM noscriptãé表示 1014 { 1015 selector: 'noscript iframe[src*="googletagmanager.com"]', 1016 action: 'hide' 1017 }, 1018 // å¿ è¦ã«å¿ãã¦ä»ã®GTMé¢é£è¦ç´ ãé表示 1019 { 1020 selector: '.gtm-blocked-notice', 1021 action: 'show' 1022 } 1023 ] 1024 } 1025}; 1026 1027// ã«ã¹ã¿ã è¨å®ã§åèµ·åãããå ´å 1028// window.CookieConsentManager.start(customGTMConfig); 1029*/ 1030 1031// =============================================================================
1032// ãããã°ç¨é¢æ°ï¼éçºæã®ã¿ä½¿ç¨ï¼ 1033// ============================================================================= 1034 1035// ã³ã³ã½ã¼ã«ã§GTMãããã¯ç¶æ³ã確èª: window.CookieConsentManager.debug.checkGTMBlocking() 1036// åæç¶æ³ã確èª: window.CookieConsentManager.debug.isConsentGiven() 1037// å¼·å¶å®è¡ï¼ãã¹ãç¨ï¼: window.CookieConsentManager.debug.forceExecute() 1038// è¨å®ç¢ºèª: window.CookieConsentManager.debug.config() 1039 1040// ============================================================================= 1041// å®è£ ã®ãã¤ã³ã 1042// ============================================================================= 1043/* 10441. GTMããããã³ã°å¼·å: 1045 - www.googletagmanager.com ãã¿ã¼ã³ã追å 1046 - ns.html (noscript) ãã¿ã¼ã³ã追å 1047 - dataLayer, GTM- ãªã©ã®ã¤ã³ã©ã¤ã³ãã¿ã¼ã³ã追å 1048 10492. noscript対å¿: 1050 - GTMã®noscriptå iframeãé表示ã«ããDOMæä½ã追å 1051 10523. ãããã°æ©è½å¼·å: 1053 - checkGTMBlocking() 颿°ã§GTMãããã¯ç¶æ³ã詳細確èªå¯è½ 1054 10554. åçèªã¿è¾¼ã¿å¯¾å¿: 1056 - å¿ è¦ã«å¿ãã¦scriptsé åã«GTMã追å ãã¦åæå¾ã«èªã¿è¾¼ã¿å¯è½ 1057 10585. æ¢åæ©è½ã®ç¶æ: 1059 - YouTubeåç»èªã¿è¾¼ã¿ 1060 - ãã¹æ¡ä»¶ä»ãã¹ã¯ãªããèªã¿è¾¼ã¿ 1061 - DOMæä½ 1062 - ãã®ä»ã®æ¢åæ©è½ã¯ãã¹ã¦ç¶æ 1063*/
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.