document.addEventListener('DOMContentLoaded', () => { if(parent.document.location.domain === undefined) { let getDomain = () => { var i = 0, domain = parent.document.domain, p = domain.split('.'), s = '_gd' + (new Date()).getTime(); while (i < (p.length - 1) && parent.document.cookie.indexOf(s + '=' + s) == -1) { domain = p.slice(-1 - (++i)).join('.'); parent.document.cookie = s + "=" + s + ";domain=" + domain + ";"; } parent.document.cookie = s + "=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=" + domain + ";"; return domain; }; parent.window.location.domain = getDomain(); } const md5 = function(d){result = M(V(Y(X(d),8*d.length)));return result.toLowerCase()};function M(d){for(var _,m="0123456789ABCDEF",f="",r=0;r>>4&15)+m.charAt(15&_);return f}function X(d){for(var _=Array(d.length>>2),m=0;m<_.length;m++)_[m]=0;for(m=0;m<8*d.length;m+=8)_[m>>5]|=(255&d.charCodeAt(m/8))<>5]>>>m%32&255);return _}function Y(d,_){d[_>>5]|=128<<_%32,d[14+(_+64>>>9<<4)]=_;for(var m=1732584193,f=-271733879,r=-1732584194,i=271733878,n=0;n>16)+(_>>16)+(m>>16)<<16|65535&m}function bit_rol(d,_){return d<<_|d>>>32-_} const d = parent.window.document; const placeholder = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; let token = md5(parent.window.location.domain); let iframeUrl = "https://www.yacco.com/en/ajax/recommendation/widget/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".replace(placeholder, token); const configTag = d.getElementById('yacco-config'); const targetId = configTag.dataset.target; let iframe = d.createElement('iframe'); iframe.id = 'yacco-iframe'; let iframeConfig = { 'language': configTag.dataset.language, 'labelform': configTag.dataset.labelform, 'labelcategory': configTag.dataset.labelcategory, 'labelmaker': configTag.dataset.labelmaker, 'labelmodel': configTag.dataset.labelmodel, 'labelversion': configTag.dataset.labelversion, 'css': configTag.dataset.css, 'addquicksearchbar': configTag.dataset.addquicksearchbar, }; iframe.src = iframeUrl + '?config='+JSON.stringify(iframeConfig); iframe.width = configTag.dataset.width; iframe.height = configTag.dataset.height; let targetElt = d.getElementById(targetId); targetElt.appendChild(iframe); let init = { method: 'HEAD', headers: new Headers(), }; fetch(iframe.src, init).then((response) => { let iframeHttpStatusCode = response.status; console.group('Widget init'); console.log('Domain : ' + parent.window.location.domain); console.log('Iframe url : ' + iframe.src); console.log('Iframe HTTP status code : ' + iframeHttpStatusCode); console.log('User token : ' + md5(parent.window.location.domain)); console.log('Current config'); console.table(iframeConfig); }); if(typeof window.location.searchHasParam === "undefined") { window.location.searchHasParam = (parameterName) => { Object .keys(window.location.searchToObject()) .every((item) => { console.log(item); if(item === parameterName) { return true; } }); return false; }; } if(typeof window.location.searchGetParam === "undefined") { /** * @param {string} parameterName * @return {boolean} */ window.location.searchGetParam = (parameterName) => { let value = null; Object .entries(window.location.searchToObject()) .forEach((item) => { if(item[0] === parameterName) { value = (item[1] !== "") ? item[1] : null; } }); return value; }; } if(typeof window.location.searchToObject === "undefined") { window.location.searchToObject = () => { let o = {}; window .location .search .substr(1) .split("&") .forEach((param) => { let buffer = param.split('='); o[buffer[0]] = buffer[1]; }); return o; }; } // console.log(window.location.searchHasParam('nope'), window.location.searchHasParam('config')); });