@@ -589,6 +589,7 @@ function replaceYouTubeCTL (trackingElement, widget) {
589
589
resizeElementToMatch ( oldPlaceholder || trackingElement , blockingDialog )
590
590
replaceTrackingElement ( widget , trackingElement , blockingDialog )
591
591
showExtraUnblockIfShortPlaceholder ( shadowRoot , blockingDialog )
592
+ hideInfoTextIfNarrowPlaceholder ( shadowRoot , blockingDialog , 460 )
592
593
}
593
594
}
594
595
@@ -628,6 +629,44 @@ function showExtraUnblockIfShortPlaceholder (shadowRoot, placeholder) {
628
629
}
629
630
}
630
631
632
+ /**
633
+ * Hide the info text (and move the "Learn More" link) if the placeholder is too
634
+ * narrow.
635
+ * @param {ShadowRoot } shadowRoot
636
+ * @param {HTMLElement } placeholder Placeholder for tracking element
637
+ * @param {number } narrowWidth
638
+ * Maximum placeholder width (in pixels) for the placeholder to be considered
639
+ * narrow.
640
+ */
641
+ function hideInfoTextIfNarrowPlaceholder ( shadowRoot , placeholder , narrowWidth ) {
642
+ const { width : placeholderWidth } = placeholder . getBoundingClientRect ( )
643
+ if ( placeholderWidth > 0 && placeholderWidth <= narrowWidth ) {
644
+ const buttonContainer =
645
+ shadowRoot . querySelector ( '.DuckDuckGoButton.primary' ) ?. parentElement
646
+ const contentTitle = shadowRoot . getElementById ( 'contentTitle' )
647
+ const infoText = shadowRoot . getElementById ( 'infoText' )
648
+ /** @type {HTMLElement? } */
649
+ const learnMoreLink = shadowRoot . getElementById ( 'learnMoreLink' )
650
+
651
+ // These elements will exist, but this check keeps TypeScript happy.
652
+ if ( ! buttonContainer || ! contentTitle || ! infoText || ! learnMoreLink ) {
653
+ return
654
+ }
655
+
656
+ // Remove the information text.
657
+ infoText . remove ( )
658
+ learnMoreLink . remove ( )
659
+
660
+ // Append the "Learn More" link to the title.
661
+ contentTitle . innerText += '. '
662
+ learnMoreLink . style . removeProperty ( 'font-size' )
663
+ contentTitle . appendChild ( learnMoreLink )
664
+
665
+ // Improve margin/padding, to ensure as much is displayed as possible.
666
+ buttonContainer . style . removeProperty ( 'margin' )
667
+ }
668
+ }
669
+
631
670
/**
632
671
* Replace the blocked CTL elements on the page with placeholders.
633
672
* @param {HTMLElement } [targetElement]
@@ -749,6 +788,7 @@ function getLearnMoreLink (mode = 'lightMode') {
749
788
linkElement . href = 'https://help.duckduckgo.com/duckduckgo-help-pages/privacy/embedded-content-protection/'
750
789
linkElement . target = '_blank'
751
790
linkElement . textContent = sharedStrings . learnMore
791
+ linkElement . id = 'learnMoreLink'
752
792
return linkElement
753
793
}
754
794
@@ -1302,10 +1342,14 @@ function createContentBlock (widget, button, textButton, img, bottomRow) {
1302
1342
const contentTitle = document . createElement ( 'div' )
1303
1343
contentTitle . style . cssText = styles . contentTitle
1304
1344
contentTitle . textContent = widget . replaceSettings . infoTitle
1345
+ contentTitle . id = 'contentTitle'
1305
1346
contentRow . appendChild ( contentTitle )
1306
1347
const contentText = document . createElement ( 'div' )
1307
1348
contentText . style . cssText = styles . contentText
1308
- contentText . textContent = widget . replaceSettings . infoText + ' '
1349
+ const contentTextSpan = document . createElement ( 'span' )
1350
+ contentTextSpan . id = 'infoText'
1351
+ contentTextSpan . textContent = widget . replaceSettings . infoText + ' '
1352
+ contentText . appendChild ( contentTextSpan )
1309
1353
contentText . appendChild ( getLearnMoreLink ( ) )
1310
1354
contentRow . appendChild ( contentText )
1311
1355
element . appendChild ( contentRow )
0 commit comments