const sleep = waitTime => new Promise( resolve => setTimeout(resolve, waitTime)); // var headByAdtasukaru = document.getElementsByTagName('head'); var script = document.createElement('script'); script.src = 'https://cdn.jsdelivr.net/npm/axios@1.1.2/dist/axios.min.js'; headByAdtasukaru[0].appendChild(script); var metaByAdtasukaru = document.createElement('meta'); metaByAdtasukaru.name = 'referrer'; metaByAdtasukaru.content = 'no-referrer-when-downgrade'; headByAdtasukaru[0].appendChild(metaByAdtasukaru); // window.addEventListener('DOMContentLoaded', async function() { var referrerByAdtasukaru = location.href // let squadbeyondUidByAdtasukaru = window.sb_tu_id; var fbcValueAT = 'empty'; var fbpValueAT = 'empty'; var ipAddressByAdtasukaru = '18.118.205.55'; var userAgentByAdtasukaru = navigator.userAgent; // ↓↓↓ fbc, fbpの取得 ↓↓↓ if(referrerByAdtasukaru.indexOf('fbclid=') !== -1) { for (let fbCookieSearchCount = 0; fbCookieSearchCount < 20; fbCookieSearchCount++) { if (fbCookieSearchCount > 10 || (document.cookie.indexOf('_fbp') !== -1 && document.cookie.indexOf('_fbc') !== -1)) { console.log(`'_fbp', '_fbc' cookies assigned!(count: ${fbCookieSearchCount})`) break; }else { await sleep( 100 ); } } }else { // through. } var cookiesStringAT = document.cookie; var cookieStringListAT = cookiesStringAT.split(';'); for (var cookieStringAT of cookieStringListAT) { var cookieNameValueListAT = cookieStringAT.split('='); var cookieNameAT = cookieNameValueListAT[0].trim(); // if(referrerByAdtasukaru.indexOf('fbclid=') !== -1) { // FB if (cookieNameAT === '_fbc') { fbcValueAT = cookieNameValueListAT[1].trim(); } if (cookieNameAT === '_fbp') { fbpValueAT = cookieNameValueListAT[1].trim(); } }else if(referrerByAdtasukaru.indexOf('ldtag_cl=') !== -1) { // LAP if (cookieNameAT === '__lt__cid') { fbpValueAT = cookieNameValueListAT[1].trim(); } }else if(referrerByAdtasukaru.indexOf('yj_r=') !== -1) { // YDA if (cookieNameAT === '_yjr_yjad') { fbcValueAT = cookieNameValueListAT[1].trim(); } }else { // no action. } } // ↑↑↑ fbc, fbpの取得 ↑↑↑ //↓↓↓ adtasukaruIdの発行 ↓↓↓ let params = new URLSearchParams(); params.append('user_id', '625'); params.append('password', ''); params.append('tag_version', ''); params.append('unit_token', ''); params.append('page_type', 'article'); params.append('fbc', fbcValueAT); params.append('ip_address', ipAddressByAdtasukaru); params.append('user_agent', userAgentByAdtasukaru); params.append('fbp', fbpValueAT); params.append('referrer', referrerByAdtasukaru); params.append('squadbeyond_uid', squadbeyondUidByAdtasukaru); axios .post(`https://adtasukaru.com/api/tools02/get-adtasukaru-id.php`, params) .then((getAdtasukaruIdResponse) => { console.log(getAdtasukaruIdResponse); if(getAdtasukaruIdResponse.data.status === 200) { if(getAdtasukaruIdResponse.data.adtasukaruId !== 'empty') { // 「adtasukaruId !== 'empty'」⇒「$page_type === 'article'」 if( referrerByAdtasukaru.indexOf('atid=') === -1 && // 「$page_type === 'article'」⇒「location.href」in「referrerByAdtasukaru」 referrerByAdtasukaru.indexOf('atid_') === -1 ) { // let atidIndex = undefined; if( referrerByAdtasukaru.indexOf('gclid=') !== -1 || referrerByAdtasukaru.indexOf('wbraid=') !== -1 || referrerByAdtasukaru.indexOf('gbraid=') !== -1 ) { // google if(referrerByAdtasukaru.indexOf('spAT=') !== -1) { atidIndex = referrerByAdtasukaru.indexOf('spAT='); }else { // no action. } }else if(referrerByAdtasukaru.indexOf('fbclid=') !== -1) { // facebook if(referrerByAdtasukaru.indexOf('utAT=') !== -1) { atidIndex = referrerByAdtasukaru.indexOf('utAT='); }else { atidIndex = referrerByAdtasukaru.indexOf('fbclid='); } }else if(referrerByAdtasukaru.indexOf('msclkid=') !== -1) { // microsoft if(referrerByAdtasukaru.indexOf('spAT=') !== -1) { atidIndex = referrerByAdtasukaru.indexOf('spAT='); }else { // no action. } }else if(referrerByAdtasukaru.indexOf('ttclid=') !== -1) { // tiktok if(referrerByAdtasukaru.indexOf('sbidAT=') !== -1) { atidIndex = referrerByAdtasukaru.indexOf('sbidAT='); }else { atidIndex = referrerByAdtasukaru.indexOf('ttclid='); } }else if(referrerByAdtasukaru.indexOf('ldtag_cl=') !== -1) { // lap atidIndex = referrerByAdtasukaru.indexOf('ldtag_cl='); }else if(referrerByAdtasukaru.indexOf('yclid=') !== -1) { if(referrerByAdtasukaru.indexOf('yj_r=') !== -1) { // yda atidIndex = referrerByAdtasukaru.indexOf('yclid='); }else { // yahoo! if(referrerByAdtasukaru.indexOf('spAT=') !== -1) { atidIndex = referrerByAdtasukaru.indexOf('spAT='); }else { // no action. } } }else { // no action. } // if(atidIndex !== undefined) { referrerByAdtasukaru = referrerByAdtasukaru.slice(0, atidIndex) + 'atid=' + getAdtasukaruIdResponse.data.adtasukaruId + '&' + referrerByAdtasukaru.slice(atidIndex); }else { if(referrerByAdtasukaru.indexOf('?') !== -1) { referrerByAdtasukaru += '&atid=' + getAdtasukaruIdResponse.data.adtasukaruId; }else { referrerByAdtasukaru += '?atid=' + getAdtasukaruIdResponse.data.adtasukaruId; } } // history.replaceState(null, null, referrerByAdtasukaru); }else { console.log('\'atid\' already exists in URL.'); } }else { if('article' === 'directlp') { // let adtasukaruParameterJoint = '?'; if(referrerByAdtasukaru.indexOf('?') !== -1) { adtasukaruParameterJoint = '&'; }else { // no action. } // referrerByAdtasukaru += adtasukaruParameterJoint + 'exrdAT=true'; // history.replaceState(null, null, referrerByAdtasukaru); }else { // no action. } } //==================== ↓↓ ページ内のaタグを全て取得→パラメータ付与 ↓↓ ==================== var targetElementListByAdtasukaru = document.getElementsByTagName('a'); let adtasukaruAtagCount = 0; Array.prototype.forEach.call(targetElementListByAdtasukaru, function (targetElementDataByAdtasukaru) { adtasukaruAtagCount++; //rawAffiliatelinkByAdtasukaru→パラメータ付与前のアフィリエイトリンク //toByAdtasukaru→パラメータ付与後のアフィリエイトリンク let rawAffiliatelinkByAdtasukaru = targetElementDataByAdtasukaru.href; targetElementDataByAdtasukaru.addEventListener('click',event => { // ------------ ↓↓ 「new URL(toByAdtasukaru)」対策 ↓↓ ------------ if(event.target.href !== '') { // ok! }else { console.log('no action. because no href.'); return; } // ------------ ↑↑ 「new URL(toByAdtasukaru)」対策 ↑↑ ------------ //---------------------- ↓↓ lightbox対策 ↓↓ ---------------------- if(event.target.href !== undefined) { if( event.target.href.indexOf('.jpg') === -1 && event.target.href.indexOf('.JPG') === -1 && event.target.href.indexOf('.jpeg') === -1 && event.target.href.indexOf('.JPEG') === -1 && event.target.href.indexOf('.jpe') === -1 && event.target.href.indexOf('.JPE') === -1 && event.target.href.indexOf('.jfif') === -1 && event.target.href.indexOf('.JFIF') === -1 && event.target.href.indexOf('.pjpeg') === -1 && event.target.href.indexOf('.PJPEG') === -1 && event.target.href.indexOf('.pjp') === -1 && event.target.href.indexOf('.PJP') === -1 && event.target.href.indexOf('.png') === -1 && event.target.href.indexOf('.PNG') === -1 && event.target.href.indexOf('.gif') === -1 && event.target.href.indexOf('.GIF') === -1 && event.target.href.indexOf('.tiff') === -1 && event.target.href.indexOf('.TIFF') === -1 && event.target.href.indexOf('.tif') === -1 && event.target.href.indexOf('.TIF') === -1 && event.target.href.indexOf('.webp') === -1 && event.target.href.indexOf('.WEBP') === -1 && event.target.href.indexOf('.svg') === -1 && event.target.href.indexOf('.SVG') === -1 && event.target.href.indexOf('.svgz') === -1 && event.target.href.indexOf('.SVGZ') === -1 ) { if( event.target.className !== 'lb-prev' && event.target.className !== 'lb-next' && event.target.className !== 'lb-close' ) { //no action. }else { return; } }else { return; } }else { //no action. } //---------------------- ↑↑ lightbox対策 ↑↑ ---------------------- event.preventDefault(); var initialTimerByAdtasukaru = setTimeout(function() {location.href = rawAffiliatelinkByAdtasukaru;}, 1500); var eventTargetByAdtasukaru = event.target; for (let tagSearchCount = 0; tagSearchCount < 30; tagSearchCount++) { if(eventTargetByAdtasukaru.tagName.toLowerCase() === 'a') { break; }else { eventTargetByAdtasukaru = eventTargetByAdtasukaru.parentNode; } } var toByAdtasukaru = eventTargetByAdtasukaru.href; var urlByAdtasukaru = new URL(toByAdtasukaru); var fromByAdtasukaru = urlByAdtasukaru.origin + urlByAdtasukaru.pathname + urlByAdtasukaru.search; var checkByAdtasukaru = toByAdtasukaru.replace(fromByAdtasukaru,''); var blankByAdtasukaru = eventTargetByAdtasukaru.target; var windowOpenResponse = null; var winByAdtasukaru; if(blankByAdtasukaru === '_blank') { winByAdtasukaru = window.open('about:blank'); }else { // no action. } let params = new URLSearchParams(); params.append('user_id', '625'); params.append('password', ''); params.append('tool_id', getAdtasukaruIdResponse.data.toolId); params.append('unit_token', ''); params.append('page_type', 'article_clicked'); params.append('user_agent', userAgentByAdtasukaru); params.append('referrer', referrerByAdtasukaru); params.append('execution_page_url', location.href); params.append('affiliate_link', rawAffiliatelinkByAdtasukaru); params.append('clicked_url', toByAdtasukaru); axios .post(`https://adtasukaru.com/api/tools02/add-referer-query-to-affiliate-link.php`, params) .then(async function(addRefRes) { // console.log(addRefRes); clearTimeout(initialTimerByAdtasukaru); if(addRefRes.data.status === 200) { // create parameter passing log let params = new URLSearchParams(); params.append('parameter_name', addRefRes.data.parameterName); params.append('user_id', addRefRes.data.userId); params.append('tool_id', getAdtasukaruIdResponse.data.toolId); params.append('log_type', addRefRes.data.logType); params.append('user_agent', navigator.userAgent); params.append('referrer', referrerByAdtasukaru); params.append('complete_link', addRefRes.data.completedAffiliateLink); axios.post(`https://adtasukaru.com/l/api/tools02/parameter-passing/create-log`, params); // redirect if(blankByAdtasukaru === '_blank') { winByAdtasukaru.location.href = toByAdtasukaru; } else { location.href = toByAdtasukaru; } }else { // 相対パスの内部リンク(href="#aiueo")はココを通ります location.href = toByAdtasukaru; } }) .catch((err) => { console.log(err); }); }, false); let params = new URLSearchParams(); params.append('user_id', '625'); params.append('password', ''); params.append('tool_id', getAdtasukaruIdResponse.data.toolId); params.append('unit_token', ''); params.append('page_type', 'article'); params.append('user_agent', userAgentByAdtasukaru); params.append('referrer', referrerByAdtasukaru); params.append('execution_page_url', location.href); params.append('affiliate_link', rawAffiliatelinkByAdtasukaru); axios .post(`https://adtasukaru.com/api/tools02/add-referer-query-to-affiliate-link.php`, params) .then((addRefRes) => { // console.log(addRefRes); if(addRefRes.data.status === 200) { // create parameter passing log if(addRefRes.data.logType === 3) { let params = new URLSearchParams(); params.append('parameter_name', addRefRes.data.parameterName); params.append('user_id', addRefRes.data.userId); params.append('tool_id', getAdtasukaruIdResponse.data.toolId); params.append('log_type', addRefRes.data.logType); params.append('user_agent', navigator.userAgent); params.append('referrer', referrerByAdtasukaru); params.append('complete_link', addRefRes.data.completedAffiliateLink); axios.post(`https://adtasukaru.com/l/api/tools02/parameter-passing/create-log`, params); }else { // no action. } //↓↓ Caution! ↓↓ targetElementDataByAdtasukaru.href = addRefRes.data.completedAffiliateLink; //↑↑ Caution! ↑↑ }else { console.log("無効なURLが生成されました。"); } }) .catch((err) => { console.log(err); }); }); //==================== ↑↑ ページ内のaタグを全て取得→パラメータ付与 ↑↑ ==================== }else { console.log('adtasukaruId取得でエラーが発生しました。'); } }) .catch((err) => { console.log(err); }); //↑↑↑ adtasukaruIdの発行 ↑↑↑ });