(function (root, factory) { var api = factory(); if (typeof module === 'object' && module.exports) { module.exports = api; } if (root) { root.TaberebaAffiliateLinkValidators = api; } }(typeof window !== 'undefined' ? window : globalThis, function () { 'use strict'; function decodeAttribute(value) { return String(value || '').replace(/&/gi, '&').replace(/"/gi, '"') .replace(/�*39;|'/gi, "'").replace(/</gi, '<').replace(/>/gi, '>'); } function attributes(html, tag, name) { var expression = new RegExp('<' + tag + '\\b[^>]*\\b' + name + '\\s*=\\s*(?:"([^"]*)"|\'([^\']*)\')', 'gi'); var values = []; var match; while ((match = expression.exec(String(html || ''))) !== null) { values.push(decodeAttribute(match[1] || match[2] || '')); } return values; } function url(value) { value = String(value || ''); return new URL(value.indexOf('//') === 0 ? 'https:' + value : value); } function allowedHttps(value, allowedHosts) { try { var parsed = url(value); return parsed.protocol === 'https:' && allowedHosts.indexOf(parsed.hostname) !== -1 && !parsed.username && !parsed.password && !parsed.hash; } catch (error) { return false; } } function valueCommerce(html, allowedHosts) { if (typeof html !== 'string' || html.length < 1 || html.length > 8192) { return false; } try { var hrefs = attributes(html, 'a', 'href'); var sources = attributes(html, 'img', 'src'); if (hrefs.length !== 1 || sources.length !== 1) { return false; } var referral = url(hrefs[0]); var pixel = url(sources[0]); var sid = referral.searchParams.getAll('sid'); var pid = referral.searchParams.getAll('pid'); var destination = referral.searchParams.getAll('vc_url'); return referral.protocol === 'https:' && referral.hostname === 'ck.jp.ap.valuecommerce.com' && referral.pathname === '/servlet/referral' && !referral.hash && pixel.protocol === 'https:' && pixel.hostname === 'ad.jp.ap.valuecommerce.com' && pixel.pathname === '/servlet/gifbanner' && !pixel.hash && sid.length === 1 && pid.length === 1 && destination.length === 1 && /^[0-9]{1,20}$/.test(sid[0]) && /^[0-9]{1,20}$/.test(pid[0]) && sid[0] === (pixel.searchParams.get('sid') || '') && pid[0] === (pixel.searchParams.get('pid') || '') && pixel.searchParams.getAll('sid').length === 1 && pixel.searchParams.getAll('pid').length === 1 && allowedHttps(destination[0], allowedHosts); } catch (error) { return false; } } function linkshare(html, allowedHosts) { if (typeof html !== 'string' || html.length < 1 || html.length > 8192) { return false; } try { var hrefs = attributes(html, 'a', 'href'); var sources = attributes(html, 'img', 'src'); if (hrefs.length !== 1 || sources.length !== 1) { return false; } var referral = url(hrefs[0]); var pixel = url(sources[0]); var id = referral.searchParams.getAll('id'); var mid = referral.searchParams.getAll('mid'); var destination = referral.searchParams.getAll('murl'); var pixelId = pixel.searchParams.getAll('id'); var bids = pixel.searchParams.getAll('bids'); return referral.protocol === 'https:' && referral.hostname === 'click.linksynergy.com' && referral.pathname === '/deeplink' && !referral.hash && pixel.protocol === 'https:' && pixel.hostname === 'ad.linksynergy.com' && pixel.pathname === '/fs-bin/show' && !pixel.hash && id.length === 1 && mid.length === 1 && destination.length === 1 && pixelId.length === 1 && bids.length === 1 && /^[A-Za-z0-9._~-]{1,200}$/.test(id[0]) && id[0] === pixelId[0] && /^[0-9]{1,20}$/.test(mid[0]) && /^[0-9.]{1,40}$/.test(bids[0]) && allowedHttps(destination[0], allowedHosts); } catch (error) { return false; } } return {valueCommerce: valueCommerce, linkshare: linkshare}; }));