const BASE_URL = "https://profileapi.liebertpub.com"; !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).browserFingerPrint=t()}(this,function(){return function(e){var t,n=window||global,r=(t=(navigator.mimeTypes.length+navigator.userAgent.length).toString(36)+function(e){var t=[];for(var r in n)t.push(r);return t.length.toString(36)}(),(new Array(5).join("0")+t).slice(-4)),i=n.screen.width.toString(36),o=n.screen.height.toString(36),g=n.screen.availWidth.toString(36),a=n.screen.availHeight.toString(36),s=n.screen.colorDepth.toString(36),c=n.screen.pixelDepth.toString(36);return btoa(r+i+o+g+a+s+c)}}); class GenTag { constructor(termId, slug, termType, source, name) { // Public properties this.termId = termId; this.slug = slug; this.termType = termType; this.source = source; this.name = name; } } function getCookiesValue(name) { const cookieMatch = document.cookie.match(`(^|;)\\s*${name}=([^;]+)`); return cookieMatch ? cookieMatch[2] : undefined; } function setCookie(name, value, days) { let expires = ""; if (days) { const date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toGMTString(); } value = value.replace(/"/g, ''); // Remove double quotes from the value document.cookie = name + "=" + value + expires + "; path=/"; } async function generateGuid(signature) { try { const response = await fetch(`${BASE_URL}/api/wp/generateGuid?signature=${signature}`); if (!response.ok) { throw new Error('Failed to generate GUID'); } return await response.text(); } catch (error) { console.log('Error:', error.message); return null; } } function extractGenTags() { const genTagElements = document.querySelectorAll('.gen-tags a'); const genTags = []; genTagElements.forEach(tagElement => { const termId = tagElement.getAttribute('data-termid'); const slug = tagElement.getAttribute('data-slug'); const termType = tagElement.getAttribute('data-termtype'); const source = tagElement.getAttribute('data-source'); const name = tagElement.innerText.trim(); // Create a new GenTag instance and add it to the collection const genTag = new GenTag(termId, slug, termType, source, name); genTags.push(genTag); }); return JSON.stringify(genTags); } function collectTaxonomy() { const taxonomy = ['NONE|']; document.querySelectorAll(".gen-tags .tag-button, .core-classifications a").forEach(e => { taxonomy.push(e.innerHTML + '|'); }); return taxonomy.join(','); } async function makeRecord(guid, postId, postType, source, sign) { const bid = getCookiesValue('BCSessionID') || 'not available'; const url = `${BASE_URL}/api/wp/history/makeRecord`; const data = { PostId: postId, PostType: postType, Source: source, BId: bid, Guid: guid, Url: encodeURIComponent(location.href), Title: encodeURIComponent(document.title), Taxonomy: collectTaxonomy(), Email: '', // Assuming emailB2C is defined elsewhere Signature: sign, GenTags : extractGenTags() }; try { const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); if (!response.ok) { throw new Error('Failed to make record'); } const responseData = await response.json(); console.log(responseData); } catch (error) { console.log('Error:', error.message); } } async function handleSession() { const sign = browserFingerPrint(); const guid = getCookiesValue('Profile.Cookies.Guid'); const postIdMeta = document.querySelector('meta[id="mal-postId"]'); const sourceMeta = document.querySelector('meta[id="mal-source"]'); const postTypeMeta = document.querySelector('meta[id="mal-postType"]'); const postId = postIdMeta ? postIdMeta.getAttribute('content') : 0; const source = sourceMeta ? sourceMeta.getAttribute('content') : ''; const postType = postTypeMeta ? postTypeMeta.getAttribute('content') : ''; if (!guid || guid=='00000000-0000-0000-0000-000000000000') { const newGuid = await generateGuid(sign); if (newGuid) { setCookie('Profile.Cookies.Guid', newGuid, 3650); await makeRecord(newGuid, postId, postType, source, sign); } } else { await makeRecord(guid, postId, postType, source, sign); } } handleSession();