@@ -461,6 +461,7 @@ async function replaceYouTubeCTL (trackingElement, widget, togglePlaceholder = f
461
461
widget , trackingElement , blockingDialog , currentPlaceholder
462
462
)
463
463
showExtraUnblockIfShortPlaceholder ( shadowRoot , blockingDialog )
464
+ hideInfoTextIfNarrowPlaceholder ( shadowRoot , blockingDialog , 300 )
464
465
}
465
466
}
466
467
@@ -492,6 +493,40 @@ function showExtraUnblockIfShortPlaceholder (shadowRoot, placeholder) {
492
493
}
493
494
}
494
495
496
+ /**
497
+ * Hide the info text (and move the "Learn More" link) if the placeholder is too
498
+ * narrow.
499
+ * @param {Element } shadowRoot
500
+ * @param {Element } placeholder Placeholder for tracking element
501
+ * @param {number } narrowWidth
502
+ * Maximum placeholder width (in pixels) for the placeholder to be considered
503
+ * narrow.
504
+ */
505
+ function hideInfoTextIfNarrowPlaceholder ( shadowRoot , placeholder , narrowWidth ) {
506
+ const { height : placeholderHeight } = window . getComputedStyle ( placeholder )
507
+ if ( parseInt ( placeholderHeight , 10 ) <= narrowWidth ) {
508
+ const buttonContainer =
509
+ shadowRoot . querySelector ( '.DuckDuckGoButton.primary' ) . parentElement
510
+ const contentTitle = shadowRoot . getElementById ( 'contentTitle' )
511
+ const infoText = shadowRoot . getElementById ( 'infoText' )
512
+ const innerDiv = shadowRoot . querySelector ( '.DuckDuckGoSocialContainer' )
513
+ const learnMoreLink = shadowRoot . querySelector ( '.learnMoreLink' )
514
+
515
+ // Remove the information text.
516
+ infoText . remove ( )
517
+ learnMoreLink . remove ( )
518
+
519
+ // Append the "Learn More" link to the title.
520
+ contentTitle . innerText += '. '
521
+ learnMoreLink . style . removeProperty ( 'font-size' )
522
+ contentTitle . appendChild ( learnMoreLink )
523
+
524
+ // Improve margin/padding, to ensure as much is displayed as possible.
525
+ buttonContainer . style . removeProperty ( 'margin' )
526
+ innerDiv . style . height = 'calc(100% - 80px)'
527
+ }
528
+ }
529
+
495
530
/**
496
531
* Replace the blocked CTP elements on the page with placeholders.
497
532
* @param {Element } [targetElement]
@@ -600,6 +635,7 @@ function getLearnMoreLink (mode) {
600
635
linkElement . href = 'https://help.duckduckgo.com/duckduckgo-help-pages/privacy/embedded-content-protection/'
601
636
linkElement . target = '_blank'
602
637
linkElement . textContent = sharedStrings . learnMore
638
+ linkElement . classList . add ( 'learnMoreLink' )
603
639
return linkElement
604
640
}
605
641
@@ -1056,10 +1092,14 @@ async function createContentBlock (widget, button, textButton, img, bottomRow) {
1056
1092
const contentTitle = document . createElement ( 'div' )
1057
1093
contentTitle . style . cssText = styles . contentTitle
1058
1094
contentTitle . textContent = widget . replaceSettings . infoTitle
1095
+ contentTitle . id = 'contentTitle'
1059
1096
contentRow . appendChild ( contentTitle )
1060
1097
const contentText = document . createElement ( 'div' )
1061
1098
contentText . style . cssText = styles . contentText
1062
- contentText . textContent = widget . replaceSettings . infoText + ' '
1099
+ const contentTextSpan = document . createElement ( 'span' )
1100
+ contentTextSpan . id = 'infoText'
1101
+ contentTextSpan . textContent = widget . replaceSettings . infoText + ' '
1102
+ contentText . appendChild ( contentTextSpan )
1063
1103
contentText . appendChild ( getLearnMoreLink ( ) )
1064
1104
contentRow . appendChild ( contentText )
1065
1105
element . appendChild ( contentRow )
0 commit comments