From a100b35e93d656c6f99df68afc98a1bf8341d37d Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Wed, 14 May 2025 19:02:17 +0200 Subject: [PATCH 01/21] [MWPW-173016] - block korea free trial links/buttons --- libs/utils/utils.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/utils/utils.js b/libs/utils/utils.js index 0d92e20e33..9b4fce7954 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -886,12 +886,24 @@ export function convertStageLinks({ anchors, config, hostname, href }) { }); } +export function shouldBlockFreeTrialLinks(a, prefix) { + if (prefix !== '/kr') return false; + + const freeTrialsCTATextArray = ['free-trial', 'free trial', '무료 체험판', '무료 체험하기']; + return freeTrialsCTATextArray.some((text) => a.textContent.toLowerCase() + ?.includes(text.toLowerCase())); +} + export function decorateLinks(el) { const config = getConfig(); decorateImageLinks(el); const anchors = el.getElementsByTagName('a'); const { hostname, href } = window.location; const links = [...anchors].reduce((rdx, a) => { + if (shouldBlockFreeTrialLinks(a, config.locale.prefix)) { + a.remove(); + return rdx; + } appendHtmlToLink(a); if (a.href.includes('http:')) a.setAttribute('data-http-link', 'true'); a.href = localizeLink(a.href); From ae9e6bafe6394bf31b34ae1ab810f9abebc06f89 Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Wed, 14 May 2025 19:45:57 +0200 Subject: [PATCH 02/21] [MWPW-173016] - korea text filter added --- libs/features/korea-word-filter.js | 33 ++++++++++++++++++++++++++++++ libs/utils/utils.js | 5 +++++ 2 files changed, 38 insertions(+) create mode 100644 libs/features/korea-word-filter.js diff --git a/libs/features/korea-word-filter.js b/libs/features/korea-word-filter.js new file mode 100644 index 0000000000..11d75a9db5 --- /dev/null +++ b/libs/features/korea-word-filter.js @@ -0,0 +1,33 @@ +export default function filterKoreaWords() { + const walker = document.createTreeWalker( + document.body, + NodeFilter.SHOW_TEXT, + null, + false, + ); + + const wordsToFilter = ['free-trial', 'free trial', '무료 체험판', '무료 체험하기']; + const combinedPattern = new RegExp(wordsToFilter.join('|'), 'gi'); + + let node = walker.nextNode(); + while (node) { + let parent = node.parentElement; + let shouldProcess = true; + while (parent) { + if (parent.tagName === 'A' || parent.tagName === 'BUTTON' || parent.tagName === 'BTN') { + shouldProcess = false; + break; + } + parent = parent.parentElement; + } + + if (shouldProcess) { + const text = node.nodeValue; + const modifiedText = text.replace(combinedPattern, ''); + if (modifiedText !== text) { + node.nodeValue = modifiedText; + } + } + node = walker.nextNode(); + } +} diff --git a/libs/utils/utils.js b/libs/utils/utils.js index 9b4fce7954..5d95431c75 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -1506,6 +1506,11 @@ export async function loadDeferred(area, blocks, config) { }); } + if (config.locale?.prefix === '/kr') { + const { default: filterKoreaWords } = await import('../features/korea-word-filter.js'); + filterKoreaWords(); + } + if (getMetadata('pageperf') === 'on') { import('./logWebVitals.js') .then((mod) => mod.default(getConfig().mep, { From 2874eba1730d2c750f311253a56fe20c18ee4fa9 Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Wed, 14 May 2025 20:03:39 +0200 Subject: [PATCH 03/21] [MWPW-173016] - update if --- libs/features/korea-word-filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/features/korea-word-filter.js b/libs/features/korea-word-filter.js index 11d75a9db5..4b92e2de67 100644 --- a/libs/features/korea-word-filter.js +++ b/libs/features/korea-word-filter.js @@ -14,7 +14,7 @@ export default function filterKoreaWords() { let parent = node.parentElement; let shouldProcess = true; while (parent) { - if (parent.tagName === 'A' || parent.tagName === 'BUTTON' || parent.tagName === 'BTN') { + if (parent.tagName === 'A' || parent.tagName === 'BUTTON') { shouldProcess = false; break; } From 0033641957ad63e4c0eb7cb35cdca5860e0cbfff Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Wed, 14 May 2025 20:08:15 +0200 Subject: [PATCH 04/21] [MWPW-173016] - code optimization --- libs/features/korea-word-filter.js | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/libs/features/korea-word-filter.js b/libs/features/korea-word-filter.js index 4b92e2de67..97d8013148 100644 --- a/libs/features/korea-word-filter.js +++ b/libs/features/korea-word-filter.js @@ -11,23 +11,9 @@ export default function filterKoreaWords() { let node = walker.nextNode(); while (node) { - let parent = node.parentElement; - let shouldProcess = true; - while (parent) { - if (parent.tagName === 'A' || parent.tagName === 'BUTTON') { - shouldProcess = false; - break; - } - parent = parent.parentElement; - } - - if (shouldProcess) { - const text = node.nodeValue; - const modifiedText = text.replace(combinedPattern, ''); - if (modifiedText !== text) { - node.nodeValue = modifiedText; - } - } + const text = node.nodeValue; + const modifiedText = text.replace(combinedPattern, ''); + if (modifiedText !== text) node.nodeValue = modifiedText; node = walker.nextNode(); } } From 4710c3de0222f4179d4715b528075bfe060870a8 Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Wed, 14 May 2025 20:18:19 +0200 Subject: [PATCH 05/21] [MWPW-173016] - improve import --- libs/utils/utils.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/utils/utils.js b/libs/utils/utils.js index 5d95431c75..1082342134 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -1507,8 +1507,9 @@ export async function loadDeferred(area, blocks, config) { } if (config.locale?.prefix === '/kr') { - const { default: filterKoreaWords } = await import('../features/korea-word-filter.js'); - filterKoreaWords(); + import('../features/korea-word-filter.js').then(({ default: filterKoreaWords }) => { + filterKoreaWords(); + }); } if (getMetadata('pageperf') === 'on') { From e471b2adc12e9bfad60394b2959350321c2a7a07 Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Thu, 15 May 2025 15:06:12 +0200 Subject: [PATCH 06/21] [MWPW-173016] - modal check, string check added --- libs/features/korea-word-filter.js | 2 +- libs/utils/utils.js | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/libs/features/korea-word-filter.js b/libs/features/korea-word-filter.js index 97d8013148..fd49dd8215 100644 --- a/libs/features/korea-word-filter.js +++ b/libs/features/korea-word-filter.js @@ -6,7 +6,7 @@ export default function filterKoreaWords() { false, ); - const wordsToFilter = ['free-trial', 'free trial', '무료 체험판', '무료 체험하기']; + const wordsToFilter = ['free-trial', 'free trial', '무료 체험판', '무료 체험하기', '{{free-trial}}']; const combinedPattern = new RegExp(wordsToFilter.join('|'), 'gi'); let node = walker.nextNode(); diff --git a/libs/utils/utils.js b/libs/utils/utils.js index 1082342134..43e96a0d6a 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -889,9 +889,9 @@ export function convertStageLinks({ anchors, config, hostname, href }) { export function shouldBlockFreeTrialLinks(a, prefix) { if (prefix !== '/kr') return false; - const freeTrialsCTATextArray = ['free-trial', 'free trial', '무료 체험판', '무료 체험하기']; - return freeTrialsCTATextArray.some((text) => a.textContent.toLowerCase() - ?.includes(text.toLowerCase())); + const freeTrialsCTATextArray = ['free-trial', 'free trial', '무료 체험판', '무료 체험하기', '{{free-trial}}']; + return (a.dataset.modalPath?.includes('trial-modals') || freeTrialsCTATextArray.some((text) => a.textContent.toLowerCase() + ?.includes(text.toLowerCase()))) && !a.classList.contains('fragment', 'link-block'); } export function decorateLinks(el) { @@ -900,10 +900,6 @@ export function decorateLinks(el) { const anchors = el.getElementsByTagName('a'); const { hostname, href } = window.location; const links = [...anchors].reduce((rdx, a) => { - if (shouldBlockFreeTrialLinks(a, config.locale.prefix)) { - a.remove(); - return rdx; - } appendHtmlToLink(a); if (a.href.includes('http:')) a.setAttribute('data-http-link', 'true'); a.href = localizeLink(a.href); @@ -955,6 +951,11 @@ export function decorateLinks(el) { a.setAttribute('aria-label', ariaLabel.trim()); } + if (shouldBlockFreeTrialLinks(a, config.locale.prefix)) { + a.remove(); + return rdx; + } + return rdx; }, []); convertStageLinks({ anchors, config, hostname, href }); From 6591d3dd660dd2d1b1aafc0962a4800397310d80 Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Thu, 15 May 2025 15:16:36 +0200 Subject: [PATCH 07/21] [MWPW-173016] - strings added --- libs/features/korea-word-filter.js | 5 ++++- libs/utils/utils.js | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/features/korea-word-filter.js b/libs/features/korea-word-filter.js index fd49dd8215..96fe246b92 100644 --- a/libs/features/korea-word-filter.js +++ b/libs/features/korea-word-filter.js @@ -6,7 +6,10 @@ export default function filterKoreaWords() { false, ); - const wordsToFilter = ['free-trial', 'free trial', '무료 체험판', '무료 체험하기', '{{free-trial}}']; + const wordsToFilter = [ + 'free-trial', 'free trial', '무료 체험판', '무료 체험하기', '{{free-trial}}', '{{start-free-trial}}', + '{{try-for-free}}', + ]; const combinedPattern = new RegExp(wordsToFilter.join('|'), 'gi'); let node = walker.nextNode(); diff --git a/libs/utils/utils.js b/libs/utils/utils.js index 43e96a0d6a..b77f6a5894 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -889,7 +889,10 @@ export function convertStageLinks({ anchors, config, hostname, href }) { export function shouldBlockFreeTrialLinks(a, prefix) { if (prefix !== '/kr') return false; - const freeTrialsCTATextArray = ['free-trial', 'free trial', '무료 체험판', '무료 체험하기', '{{free-trial}}']; + const freeTrialsCTATextArray = [ + 'free-trial', 'free trial', '무료 체험판', '무료 체험하기', '{{free-trial}}', '{{start-free-trial}}', + '{{try-for-free}}', + ]; return (a.dataset.modalPath?.includes('trial-modals') || freeTrialsCTATextArray.some((text) => a.textContent.toLowerCase() ?.includes(text.toLowerCase()))) && !a.classList.contains('fragment', 'link-block'); } From c8866f93db3d7fa838a76efd5efb460dfe4b9125 Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Fri, 16 May 2025 15:40:53 +0200 Subject: [PATCH 08/21] [MWPW-173470] - update logic --- libs/features/korea-word-filter.js | 22 ------------------- libs/utils/utils.js | 34 ++++++++++++++---------------- 2 files changed, 16 insertions(+), 40 deletions(-) delete mode 100644 libs/features/korea-word-filter.js diff --git a/libs/features/korea-word-filter.js b/libs/features/korea-word-filter.js deleted file mode 100644 index 96fe246b92..0000000000 --- a/libs/features/korea-word-filter.js +++ /dev/null @@ -1,22 +0,0 @@ -export default function filterKoreaWords() { - const walker = document.createTreeWalker( - document.body, - NodeFilter.SHOW_TEXT, - null, - false, - ); - - const wordsToFilter = [ - 'free-trial', 'free trial', '무료 체험판', '무료 체험하기', '{{free-trial}}', '{{start-free-trial}}', - '{{try-for-free}}', - ]; - const combinedPattern = new RegExp(wordsToFilter.join('|'), 'gi'); - - let node = walker.nextNode(); - while (node) { - const text = node.nodeValue; - const modifiedText = text.replace(combinedPattern, ''); - if (modifiedText !== text) node.nodeValue = modifiedText; - node = walker.nextNode(); - } -} diff --git a/libs/utils/utils.js b/libs/utils/utils.js index b77f6a5894..a6aa76cf8d 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -886,22 +886,25 @@ export function convertStageLinks({ anchors, config, hostname, href }) { }); } -export function shouldBlockFreeTrialLinks(a, prefix) { - if (prefix !== '/kr') return false; - - const freeTrialsCTATextArray = [ - 'free-trial', 'free trial', '무료 체험판', '무료 체험하기', '{{free-trial}}', '{{start-free-trial}}', - '{{try-for-free}}', - ]; - return (a.dataset.modalPath?.includes('trial-modals') || freeTrialsCTATextArray.some((text) => a.textContent.toLowerCase() - ?.includes(text.toLowerCase()))) && !a.classList.contains('fragment', 'link-block'); -} - export function decorateLinks(el) { const config = getConfig(); decorateImageLinks(el); const anchors = el.getElementsByTagName('a'); const { hostname, href } = window.location; + + const shouldBlockFreeTrialLinks = (a, prefix) => { + if (prefix !== '/kr') return false; + + const freeTrialsCTATextArray = [ + 'free-trial', 'free trial', + '무료 체험판', '무료 체험하기', + '{{free-trial}}', '{{start-free-trial}}', '{{try-for-free}}', + ]; + + return (a.dataset.modalPath?.includes('/kr/cc-shared/fragments/trial-modals') || freeTrialsCTATextArray.some((text) => a.textContent.toLowerCase() + ?.includes(text.toLowerCase()))) && !a.classList.contains('fragment', 'link-block'); + }; + const links = [...anchors].reduce((rdx, a) => { appendHtmlToLink(a); if (a.href.includes('http:')) a.setAttribute('data-http-link', 'true'); @@ -955,7 +958,8 @@ export function decorateLinks(el) { } if (shouldBlockFreeTrialLinks(a, config.locale.prefix)) { - a.remove(); + const elementToRemove = (a.parentElement.tagName === 'STRONG' || a.parentElement.tagName === 'EM') && a.parentElement.children.length === 1 ? a.parentElement : a; + elementToRemove.remove(); return rdx; } @@ -1510,12 +1514,6 @@ export async function loadDeferred(area, blocks, config) { }); } - if (config.locale?.prefix === '/kr') { - import('../features/korea-word-filter.js').then(({ default: filterKoreaWords }) => { - filterKoreaWords(); - }); - } - if (getMetadata('pageperf') === 'on') { import('./logWebVitals.js') .then((mod) => mod.default(getConfig().mep, { From d9d821d787dc0d6f3097f7d3db3f84c8b8bbf7e4 Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Fri, 16 May 2025 18:17:10 +0200 Subject: [PATCH 09/21] [MWPW-173470] - update logic --- libs/utils/decorate.js | 19 +++++++++++++++++++ libs/utils/utils.js | 19 ------------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index 6210cd0c2e..406d9eebac 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -23,7 +23,26 @@ export function decorateButtons(el, size) { const buttons = el.querySelectorAll('em a, strong a, p > a strong'); if (buttons.length === 0) return; const buttonTypeMap = { STRONG: 'blue', EM: 'outline', A: 'blue' }; + + const shouldBlockFreeTrialLinks = (a, prefix) => { + if (prefix !== '/kr') return false; + + const freeTrialsCTATextArray = [ + 'free-trial', 'free trial', + '무료 체험판', '무료 체험하기', + '{{free-trial}}', '{{start-free-trial}}', '{{try-for-free}}', + ]; + + return (a.dataset?.modalPath?.includes('/kr/cc-shared/fragments/trial-modals') || freeTrialsCTATextArray.some((text) => a.textContent.toLowerCase() + ?.includes(text.toLowerCase()))); + }; + buttons.forEach((button) => { + if (shouldBlockFreeTrialLinks(button, getConfig().locale.prefix)) { + const elementToRemove = (button.parentElement.tagName === 'STRONG' || button.parentElement.tagName === 'EM') && button.parentElement.children.length === 1 ? button.parentElement : button; + elementToRemove.remove(); + return; + } let target = button; const parent = button.parentElement; const buttonType = buttonTypeMap[parent.nodeName] || 'outline'; diff --git a/libs/utils/utils.js b/libs/utils/utils.js index a6aa76cf8d..9a16ca1a6c 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -892,19 +892,6 @@ export function decorateLinks(el) { const anchors = el.getElementsByTagName('a'); const { hostname, href } = window.location; - const shouldBlockFreeTrialLinks = (a, prefix) => { - if (prefix !== '/kr') return false; - - const freeTrialsCTATextArray = [ - 'free-trial', 'free trial', - '무료 체험판', '무료 체험하기', - '{{free-trial}}', '{{start-free-trial}}', '{{try-for-free}}', - ]; - - return (a.dataset.modalPath?.includes('/kr/cc-shared/fragments/trial-modals') || freeTrialsCTATextArray.some((text) => a.textContent.toLowerCase() - ?.includes(text.toLowerCase()))) && !a.classList.contains('fragment', 'link-block'); - }; - const links = [...anchors].reduce((rdx, a) => { appendHtmlToLink(a); if (a.href.includes('http:')) a.setAttribute('data-http-link', 'true'); @@ -957,12 +944,6 @@ export function decorateLinks(el) { a.setAttribute('aria-label', ariaLabel.trim()); } - if (shouldBlockFreeTrialLinks(a, config.locale.prefix)) { - const elementToRemove = (a.parentElement.tagName === 'STRONG' || a.parentElement.tagName === 'EM') && a.parentElement.children.length === 1 ? a.parentElement : a; - elementToRemove.remove(); - return rdx; - } - return rdx; }, []); convertStageLinks({ anchors, config, hostname, href }); From bcc09bd9297f7e4ef9dcdb3a0edc5623aaa438df Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Fri, 16 May 2025 18:26:48 +0200 Subject: [PATCH 10/21] [MWPW-173470] - update logic --- libs/utils/decorate.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index 406d9eebac..89c3cdb318 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -19,32 +19,35 @@ let videoLabels = { }; let videoCounter = 0; +const FREE_TRIAL_PATTERNS = [ + 'free-trial', 'free trial', + '무료 체험판', '무료 체험하기', + '{{free-trial}}', '{{start-free-trial}}', '{{try-for-free}}', +]; + +const shouldBlockFreeTrialLinks = (a, prefix) => { + if (prefix !== '/kr') return false; + if (a.dataset?.modalPath?.includes('/kr/cc-shared/fragments/trial-modals')) return true; + return FREE_TRIAL_PATTERNS.some((pattern) => a.textContent?.toLowerCase()?.includes( + pattern.toLowerCase(), + )); +}; + export function decorateButtons(el, size) { const buttons = el.querySelectorAll('em a, strong a, p > a strong'); if (buttons.length === 0) return; const buttonTypeMap = { STRONG: 'blue', EM: 'outline', A: 'blue' }; - const shouldBlockFreeTrialLinks = (a, prefix) => { - if (prefix !== '/kr') return false; - - const freeTrialsCTATextArray = [ - 'free-trial', 'free trial', - '무료 체험판', '무료 체험하기', - '{{free-trial}}', '{{start-free-trial}}', '{{try-for-free}}', - ]; - - return (a.dataset?.modalPath?.includes('/kr/cc-shared/fragments/trial-modals') || freeTrialsCTATextArray.some((text) => a.textContent.toLowerCase() - ?.includes(text.toLowerCase()))); - }; - buttons.forEach((button) => { + const parent = button.parentElement; + if (shouldBlockFreeTrialLinks(button, getConfig().locale.prefix)) { - const elementToRemove = (button.parentElement.tagName === 'STRONG' || button.parentElement.tagName === 'EM') && button.parentElement.children.length === 1 ? button.parentElement : button; + const elementToRemove = (parent.tagName === 'STRONG' || parent.tagName === 'EM') && parent.children.length === 1 ? parent : button; elementToRemove.remove(); return; } + let target = button; - const parent = button.parentElement; const buttonType = buttonTypeMap[parent.nodeName] || 'outline'; if (button.nodeName === 'STRONG') { target = parent; From 90ed66f02e272723b5d8881cc1c31796a1efab76 Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Fri, 16 May 2025 18:32:29 +0200 Subject: [PATCH 11/21] [MWPW-173470] - remove whitespace --- libs/utils/utils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/utils/utils.js b/libs/utils/utils.js index 9a16ca1a6c..0d92e20e33 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -891,7 +891,6 @@ export function decorateLinks(el) { decorateImageLinks(el); const anchors = el.getElementsByTagName('a'); const { hostname, href } = window.location; - const links = [...anchors].reduce((rdx, a) => { appendHtmlToLink(a); if (a.href.includes('http:')) a.setAttribute('data-http-link', 'true'); From 7fc5759cd8c9a41fdf23a5afc1e409967f88e821 Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Fri, 16 May 2025 18:57:08 +0200 Subject: [PATCH 12/21] [MWPW-173470] - optimize --- libs/utils/decorate.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index 89c3cdb318..17a9856b55 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -19,15 +19,16 @@ let videoLabels = { }; let videoCounter = 0; -const FREE_TRIAL_PATTERNS = [ - 'free-trial', 'free trial', - '무료 체험판', '무료 체험하기', - '{{free-trial}}', '{{start-free-trial}}', '{{try-for-free}}', -]; - const shouldBlockFreeTrialLinks = (a, prefix) => { if (prefix !== '/kr') return false; if (a.dataset?.modalPath?.includes('/kr/cc-shared/fragments/trial-modals')) return true; + + const FREE_TRIAL_PATTERNS = [ + 'free-trial', 'free trial', + '무료 체험판', '무료 체험하기', + '{{free-trial}}', '{{start-free-trial}}', '{{try-for-free}}', + ]; + return FREE_TRIAL_PATTERNS.some((pattern) => a.textContent?.toLowerCase()?.includes( pattern.toLowerCase(), )); From c4296d59e92d5944e144b265ce9b0f53ab72e04f Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Fri, 16 May 2025 18:58:58 +0200 Subject: [PATCH 13/21] [MWPW-173470] - remove variable --- libs/utils/decorate.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index 17a9856b55..d789f3dc57 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -22,16 +22,11 @@ let videoCounter = 0; const shouldBlockFreeTrialLinks = (a, prefix) => { if (prefix !== '/kr') return false; if (a.dataset?.modalPath?.includes('/kr/cc-shared/fragments/trial-modals')) return true; - - const FREE_TRIAL_PATTERNS = [ + return [ 'free-trial', 'free trial', '무료 체험판', '무료 체험하기', '{{free-trial}}', '{{start-free-trial}}', '{{try-for-free}}', - ]; - - return FREE_TRIAL_PATTERNS.some((pattern) => a.textContent?.toLowerCase()?.includes( - pattern.toLowerCase(), - )); + ].some((pattern) => a.textContent?.toLowerCase()?.includes(pattern.toLowerCase())); }; export function decorateButtons(el, size) { From 1211e9aa8b56c2930a6f8caf9d5d31287b1d9da4 Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Mon, 19 May 2025 11:08:32 +0200 Subject: [PATCH 14/21] [MWPW-173016] - optimize code --- libs/utils/decorate.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index d789f3dc57..823e1cc698 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -19,15 +19,13 @@ let videoLabels = { }; let videoCounter = 0; -const shouldBlockFreeTrialLinks = (a, prefix) => { - if (prefix !== '/kr') return false; - if (a.dataset?.modalPath?.includes('/kr/cc-shared/fragments/trial-modals')) return true; - return [ - 'free-trial', 'free trial', - '무료 체험판', '무료 체험하기', +const shouldBlockFreeTrialLinks = (a, prefix) => prefix === '/kr' && ( + a.dataset?.modalPath?.includes('/kr/cc-shared/fragments/trial-modals') + || [ + 'free-trial', 'free trial', '무료 체험판', '무료 체험하기', '{{free-trial}}', '{{start-free-trial}}', '{{try-for-free}}', - ].some((pattern) => a.textContent?.toLowerCase()?.includes(pattern.toLowerCase())); -}; + ].some((pattern) => a.textContent?.toLowerCase()?.includes(pattern.toLowerCase())) +); export function decorateButtons(el, size) { const buttons = el.querySelectorAll('em a, strong a, p > a strong'); From 46cd21f31bc228eb3accc7a3027304db78988fcd Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Mon, 19 May 2025 11:14:54 +0200 Subject: [PATCH 15/21] [MWPW-173016] - group logic --- libs/utils/decorate.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index 823e1cc698..b6adae2735 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -19,13 +19,18 @@ let videoLabels = { }; let videoCounter = 0; -const shouldBlockFreeTrialLinks = (a, prefix) => prefix === '/kr' && ( - a.dataset?.modalPath?.includes('/kr/cc-shared/fragments/trial-modals') - || [ - 'free-trial', 'free trial', '무료 체험판', '무료 체험하기', - '{{free-trial}}', '{{start-free-trial}}', '{{try-for-free}}', - ].some((pattern) => a.textContent?.toLowerCase()?.includes(pattern.toLowerCase())) -); +const shouldBlockFreeTrialLinks = (a, prefix, parent) => { + if (prefix !== '/kr' || (!a.dataset?.modalPath?.includes('/kr/cc-shared/fragments/trial-modals') + && !['free-trial', 'free trial', '무료 체험판', '무료 체험하기', + '{{free-trial}}', '{{start-free-trial}}', '{{try-for-free}}'] + .some((pattern) => a.textContent?.toLowerCase()?.includes(pattern.toLowerCase())))) { + return false; + } + + const elementToRemove = (parent.tagName === 'STRONG' || parent.tagName === 'EM') && parent.children.length === 1 ? parent : a; + elementToRemove.remove(); + return true; +}; export function decorateButtons(el, size) { const buttons = el.querySelectorAll('em a, strong a, p > a strong'); @@ -34,13 +39,7 @@ export function decorateButtons(el, size) { buttons.forEach((button) => { const parent = button.parentElement; - - if (shouldBlockFreeTrialLinks(button, getConfig().locale.prefix)) { - const elementToRemove = (parent.tagName === 'STRONG' || parent.tagName === 'EM') && parent.children.length === 1 ? parent : button; - elementToRemove.remove(); - return; - } - + if (shouldBlockFreeTrialLinks(button, getConfig().locale.prefix, parent)) return; let target = button; const buttonType = buttonTypeMap[parent.nodeName] || 'outline'; if (button.nodeName === 'STRONG') { From d57743b4e3fda107309d23eba34e250fc4b7a3a3 Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Mon, 19 May 2025 11:33:54 +0200 Subject: [PATCH 16/21] [MWPW-173016] - merch solution added --- libs/blocks/merch/merch.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libs/blocks/merch/merch.js b/libs/blocks/merch/merch.js index fbf8c1d881..181b544ee1 100644 --- a/libs/blocks/merch/merch.js +++ b/libs/blocks/merch/merch.js @@ -844,6 +844,11 @@ export async function buildCta(el, params) { cta.setAttribute('aria-label', ariaLabel); }); } + + cta.onceSettled().then(() => { + if (getConfig().locale.prefix === '/kr' && cta.value[0].offerType === OFFER_TYPE_TRIAL) cta.remove(); + }); + return cta; } From 25019a20ad5ba2c3d1735950618b03e9192e5911 Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Mon, 19 May 2025 12:14:39 +0200 Subject: [PATCH 17/21] [MWPW-173016] - merch ref comment added --- libs/blocks/merch/merch.js | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/blocks/merch/merch.js b/libs/blocks/merch/merch.js index 181b544ee1..2f7d2bc6a1 100644 --- a/libs/blocks/merch/merch.js +++ b/libs/blocks/merch/merch.js @@ -845,6 +845,7 @@ export async function buildCta(el, params) { }); } + // @see https://jira.corp.adobe.com/browse/MWPW-173470 cta.onceSettled().then(() => { if (getConfig().locale.prefix === '/kr' && cta.value[0].offerType === OFFER_TYPE_TRIAL) cta.remove(); }); From 7b81f165b977648700d90b6c8b964ad020d81ccc Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Mon, 19 May 2025 14:57:25 +0200 Subject: [PATCH 18/21] [MWPW-173470] - null safe --- libs/blocks/merch/merch.js | 2 +- libs/utils/decorate.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/blocks/merch/merch.js b/libs/blocks/merch/merch.js index 2f7d2bc6a1..02a2a8a3e1 100644 --- a/libs/blocks/merch/merch.js +++ b/libs/blocks/merch/merch.js @@ -847,7 +847,7 @@ export async function buildCta(el, params) { // @see https://jira.corp.adobe.com/browse/MWPW-173470 cta.onceSettled().then(() => { - if (getConfig().locale.prefix === '/kr' && cta.value[0].offerType === OFFER_TYPE_TRIAL) cta.remove(); + if (getConfig()?.locale?.prefix === '/kr' && cta.value[0].offerType === OFFER_TYPE_TRIAL) cta.remove(); }); return cta; diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index b6adae2735..cb8778421c 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -39,7 +39,7 @@ export function decorateButtons(el, size) { buttons.forEach((button) => { const parent = button.parentElement; - if (shouldBlockFreeTrialLinks(button, getConfig().locale.prefix, parent)) return; + if (shouldBlockFreeTrialLinks(button, getConfig()?.locale?.prefix, parent)) return; let target = button; const buttonType = buttonTypeMap[parent.nodeName] || 'outline'; if (button.nodeName === 'STRONG') { From f8c8b060745f6658111eba5de0f98970b18ca757 Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Tue, 20 May 2025 12:39:58 +0200 Subject: [PATCH 19/21] [MWPW-173470] - code optimization --- libs/blocks/merch/merch.js | 2 +- libs/utils/decorate.js | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libs/blocks/merch/merch.js b/libs/blocks/merch/merch.js index 02a2a8a3e1..42c94d6dae 100644 --- a/libs/blocks/merch/merch.js +++ b/libs/blocks/merch/merch.js @@ -847,7 +847,7 @@ export async function buildCta(el, params) { // @see https://jira.corp.adobe.com/browse/MWPW-173470 cta.onceSettled().then(() => { - if (getConfig()?.locale?.prefix === '/kr' && cta.value[0].offerType === OFFER_TYPE_TRIAL) cta.remove(); + if (getConfig()?.locale?.prefix === '/kr' && cta.value[0]?.offerType === OFFER_TYPE_TRIAL) cta.remove(); }); return cta; diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index cb8778421c..57a998e3db 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -19,15 +19,14 @@ let videoLabels = { }; let videoCounter = 0; -const shouldBlockFreeTrialLinks = (a, prefix, parent) => { - if (prefix !== '/kr' || (!a.dataset?.modalPath?.includes('/kr/cc-shared/fragments/trial-modals') - && !['free-trial', 'free trial', '무료 체험판', '무료 체험하기', - '{{free-trial}}', '{{start-free-trial}}', '{{try-for-free}}'] - .some((pattern) => a.textContent?.toLowerCase()?.includes(pattern.toLowerCase())))) { +const shouldBlockFreeTrialLinks = ({ button, localePrefix, parent }) => { + if (localePrefix !== '/kr' || (!button.dataset?.modalPath?.includes('/kr/cc-shared/fragments/trial-modals') + && !['free-trial', 'free trial', '무료 체험판', '무료 체험하기', '{{try-for-free}}'] + .some((pattern) => button.textContent?.toLowerCase()?.includes(pattern.toLowerCase())))) { return false; } - const elementToRemove = (parent.tagName === 'STRONG' || parent.tagName === 'EM') && parent.children.length === 1 ? parent : a; + const elementToRemove = (parent.tagName === 'STRONG' || parent.tagName === 'EM') && parent.children.length === 1 ? parent : button; elementToRemove.remove(); return true; }; @@ -36,10 +35,11 @@ export function decorateButtons(el, size) { const buttons = el.querySelectorAll('em a, strong a, p > a strong'); if (buttons.length === 0) return; const buttonTypeMap = { STRONG: 'blue', EM: 'outline', A: 'blue' }; + const localePrefix = getConfig()?.locale?.prefix; buttons.forEach((button) => { const parent = button.parentElement; - if (shouldBlockFreeTrialLinks(button, getConfig()?.locale?.prefix, parent)) return; + if (shouldBlockFreeTrialLinks({ button, localePrefix, parent })) return; let target = button; const buttonType = buttonTypeMap[parent.nodeName] || 'outline'; if (button.nodeName === 'STRONG') { From f481acaa1ec7318c64358581c236a801c149ba4e Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Wed, 21 May 2025 10:26:06 +0200 Subject: [PATCH 20/21] [MWPW-173470] - nav korea restrict coverage --- .../blocks/global-navigation/utilities/utilities.js | 6 ++++++ libs/utils/decorate.js | 13 +------------ libs/utils/utils.js | 12 ++++++++++++ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/libs/blocks/global-navigation/utilities/utilities.js b/libs/blocks/global-navigation/utilities/utilities.js index 64e12513a4..0b6f04499e 100644 --- a/libs/blocks/global-navigation/utilities/utilities.js +++ b/libs/blocks/global-navigation/utilities/utilities.js @@ -10,6 +10,7 @@ import { getFederatedContentRoot, getFederatedUrl, getFedsPlaceholderConfig, + shouldBlockFreeTrialLinks, } from '../../../utils/utils.js'; import { processTrackingLabels } from '../../../martech/attributes.js'; import { replaceKey, replaceText } from '../../../features/placeholders.js'; @@ -246,6 +247,11 @@ export async function loadDecorateMenu() { } export function decorateCta({ elem, type = 'primaryCta', index } = {}) { + if (shouldBlockFreeTrialLinks({ + button: elem, + localePrefix: getConfig()?.locale?.prefix, + parent: elem.parentElement, + })) return null; const modifier = type === 'secondaryCta' ? 'secondary' : 'primary'; const clone = elem.cloneNode(true); diff --git a/libs/utils/decorate.js b/libs/utils/decorate.js index 57a998e3db..3fbd83f993 100644 --- a/libs/utils/decorate.js +++ b/libs/utils/decorate.js @@ -5,6 +5,7 @@ import { createIntersectionObserver, getFederatedContentRoot, getFedsPlaceholderConfig, + shouldBlockFreeTrialLinks, } from './utils.js'; const { miloLibs, codeRoot } = getConfig(); @@ -19,18 +20,6 @@ let videoLabels = { }; let videoCounter = 0; -const shouldBlockFreeTrialLinks = ({ button, localePrefix, parent }) => { - if (localePrefix !== '/kr' || (!button.dataset?.modalPath?.includes('/kr/cc-shared/fragments/trial-modals') - && !['free-trial', 'free trial', '무료 체험판', '무료 체험하기', '{{try-for-free}}'] - .some((pattern) => button.textContent?.toLowerCase()?.includes(pattern.toLowerCase())))) { - return false; - } - - const elementToRemove = (parent.tagName === 'STRONG' || parent.tagName === 'EM') && parent.children.length === 1 ? parent : button; - elementToRemove.remove(); - return true; -}; - export function decorateButtons(el, size) { const buttons = el.querySelectorAll('em a, strong a, p > a strong'); if (buttons.length === 0) return; diff --git a/libs/utils/utils.js b/libs/utils/utils.js index 0d92e20e33..5691a9d514 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -415,6 +415,18 @@ export const getFedsPlaceholderConfig = ({ useCache = true } = {}) => { return fedsPlaceholderConfig; }; +export const shouldBlockFreeTrialLinks = ({ button, localePrefix, parent }) => { + if (localePrefix !== '/kr' || (!button.dataset?.modalPath?.includes('/kr/cc-shared/fragments/trial-modals') + && !['free-trial', 'free trial', '무료 체험판', '무료 체험하기', '{{try-for-free}}'] + .some((pattern) => button.textContent?.toLowerCase()?.includes(pattern.toLowerCase())))) { + return false; + } + + const elementToRemove = (parent?.tagName === 'STRONG' || parent?.tagName === 'EM') && parent?.children?.length === 1 ? parent : button; + elementToRemove.remove(); + return true; +}; + export function isInTextNode(node) { return (node.parentElement.childNodes.length > 1 && node.parentElement.firstChild.tagName === 'A') || node.parentElement.firstChild.nodeType === Node.TEXT_NODE; } From e39b7e71b2d8efca73e8083fdd31314dc391fc1a Mon Sep 17 00:00:00 2001 From: Dusan Kosanovic Date: Wed, 21 May 2025 12:36:27 +0200 Subject: [PATCH 21/21] [MWPW-173470] - fix eslint console error --- libs/blocks/global-navigation/utilities/utilities.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/blocks/global-navigation/utilities/utilities.js b/libs/blocks/global-navigation/utilities/utilities.js index 0b6f04499e..34016ecb10 100644 --- a/libs/blocks/global-navigation/utilities/utilities.js +++ b/libs/blocks/global-navigation/utilities/utilities.js @@ -102,7 +102,7 @@ export const logPerformance = ( sampleRate: 0.01, }); } catch (e) { - console.error(e); + // eslint-disable-next-line no-empty } };