@playpilot/tpi 8.28.0 → 8.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/editorial.mount.js +7 -7
- package/dist/link-injections.js +1 -1
- package/dist/mount.js +6 -6
- package/package.json +1 -1
- package/src/lib/injection.ts +14 -1
- package/src/lib/types/config.d.ts +122 -122
- package/src/tests/lib/injection.test.js +20 -0
package/package.json
CHANGED
package/src/lib/injection.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { clearAfterArticlePlaylinks, insertAfterArticlePlaylinks } from './after
|
|
|
7
7
|
import { clearInTextDisclaimer, insertInTextDisclaimer } from './disclaimer'
|
|
8
8
|
import { exploreTitleUrl, titleUrl } from './routes'
|
|
9
9
|
import { clearInTextWidgets, insertInTextWidgets } from './inTextWidgets'
|
|
10
|
+
import { decodeHtmlEntities, encodeHtmlEntities } from './html'
|
|
10
11
|
|
|
11
12
|
export const keyDataAttribute = 'data-playpilot-injection-key'
|
|
12
13
|
export const keySelector = `[${keyDataAttribute}]`
|
|
@@ -84,9 +85,21 @@ export function injectLinksInDocument(elements: HTMLElement[], injections: LinkI
|
|
|
84
85
|
// We insert the html here separately from below, where it's done with replacementIndex because we need to capture all html
|
|
85
86
|
// that may have been inside of the match.
|
|
86
87
|
if (replacementIndex === -1) {
|
|
87
|
-
|
|
88
|
+
let match = findShortestMatchBetweenPhrases(element.innerHTML, injection.title, phrase_before || '', phrase_after || '')
|
|
88
89
|
|
|
89
90
|
if (match) {
|
|
91
|
+
// This is a crude way of checking if a match contains HTML elements
|
|
92
|
+
// If the title is directly inside of an element we discard the rest.
|
|
93
|
+
// This happens sometimes in lists that consists of nothing but titles and may contain special characters
|
|
94
|
+
if (match.match.includes(">") && match.match.includes("<")) {
|
|
95
|
+
const encodedTitle = encodeHtmlEntities(injection.title)
|
|
96
|
+
const matchInsideHTMLIndex = match.match.search(new RegExp(`>\s*${encodedTitle}\s*<`)) + 1
|
|
97
|
+
|
|
98
|
+
if (matchInsideHTMLIndex > 0) {
|
|
99
|
+
match = { match: match.match.slice(matchInsideHTMLIndex, matchInsideHTMLIndex + encodedTitle.length), index: matchInsideHTMLIndex }
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
90
103
|
const { leadingSpaces, trailingSpaces } = getNumberOfLeadingAndTrailingSpaces(match.match)
|
|
91
104
|
|
|
92
105
|
linkElement.innerHTML = match.match.trim()
|
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
import type { InsertPosition } from './position'
|
|
2
|
-
|
|
3
|
-
export type ConfigResponse = {
|
|
4
|
-
/**
|
|
5
|
-
* Used to exclude URL matching a regex pattern. If a url matches, nothing is executed beyond fetching the config.
|
|
6
|
-
* The url should never be indexed.
|
|
7
|
-
*/
|
|
8
|
-
exclude_urls_pattern?: string
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Used to inject custom styling for the links, modal, and popover. All styling is done via CSS variables. The passed
|
|
12
|
-
* string should not contain a selector.
|
|
13
|
-
* For example:
|
|
14
|
-
* `--some-variable: some-value;`
|
|
15
|
-
*
|
|
16
|
-
* rather than:
|
|
17
|
-
* `body { --some-variable: some-value; }`
|
|
18
|
-
*/
|
|
19
|
-
custom_style?: string
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The primary selector for the entire article from which text will be selected. Should contain as little content as
|
|
23
|
-
* possible. Should match all pages. May contain multiple selectors like `.article, .listicle`.
|
|
24
|
-
*/
|
|
25
|
-
html_selector?: string
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Some pages contain elements that can't easily be excluded via the `html_selector`. These elements can instead be
|
|
29
|
-
* excluded via this property. May contain multiple selectors like `.footer, .ad`.
|
|
30
|
-
*/
|
|
31
|
-
exclude_elements_selector?: string
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Disable all injections from showing on pages without editorial mode enabled
|
|
35
|
-
*/
|
|
36
|
-
disable_public_injections?: boolean
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Region to fall back on if other methods of getting the region fail. This should be equal to the region most relevant
|
|
40
|
-
* to the partner. Should be lowercase.
|
|
41
|
-
*/
|
|
42
|
-
fallback_region?: string
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Disclaimer text that is shown above playlinks in title cards used to replace the default text
|
|
46
|
-
*/
|
|
47
|
-
playlinks_disclaimer_text?: string
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Some partners may want to display titles without affiliate links, which currently comes down to no playlinks.
|
|
51
|
-
* This can also be set via the config on the script itself.
|
|
52
|
-
*/
|
|
53
|
-
no_affiliate?: boolean
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Whether or not we can insert retargeting pixels. Not all third parties allow this and it is disabled by default
|
|
57
|
-
*/
|
|
58
|
-
allow_retargeting_pixels?: boolean
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* By default affiliate links (playlinks) will render as links even without consent, as a disclaimer is given. Set to true to require explicit consent, rendering as static text without consent.
|
|
62
|
-
*/
|
|
63
|
-
require_affiliate_consent?: boolean
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Scroll reveal posters that show on mobile are enabled by default. Use this option to disable them.
|
|
67
|
-
*/
|
|
68
|
-
disable_scroll_reveal_posters?: boolean
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Playlinks are merged by default, when this option is enabled playlinks will instead be shown categorized.
|
|
72
|
-
*/
|
|
73
|
-
categorize_playlinks?: boolean
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* By default no user identifiable data is tracked. This can be changed using this option. User ids are stored in localStorage and sent along with any tracking request.
|
|
77
|
-
*/
|
|
78
|
-
allow_user_id_tracking?: boolean
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* The sid for the current domain, used for tracking
|
|
82
|
-
*/
|
|
83
|
-
domain_sid?: string
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* The sid for the organization the domain belongs to, used for tracking. Can be empty.
|
|
87
|
-
*/
|
|
88
|
-
organization_sid?: string
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* The following options are all relevant for in text disclaimers, which renders as a disclaimer text within the article,
|
|
92
|
-
* rather than only inside of title cards.
|
|
93
|
-
* Change the text content using `in_text_disclaimer_text`.
|
|
94
|
-
* Change where the element is inserted using `in_text_disclaimer_selector`, by default it will insert before the first text element.
|
|
95
|
-
* Change the insert position using `in_text_disclaimer_insert_position`, by default it will insert before the given selector.
|
|
96
|
-
*/
|
|
97
|
-
in_text_disclaimer_enabled?: boolean
|
|
98
|
-
in_text_disclaimer_text?: string
|
|
99
|
-
in_text_disclaimer_selector?: string
|
|
100
|
-
in_text_disclaimer_insert_position?: InsertPosition
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Open TPI links in explore rather than in modals in the article
|
|
104
|
-
*/
|
|
105
|
-
open_tpi_links_in_explore?: boolean
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* These options are all relevant for the Explore component, which can be inserted as a widget on any page or as a modal.
|
|
109
|
-
* `explore_navigation_selector` is used to select the navigation element that should be copied and inserted _after_.
|
|
110
|
-
* `explore_navigation_label` will end up being the label of the navigation item, defaults to `Streaming Guide`.
|
|
111
|
-
* `explore_navigation_path` is the path that the navigation item will lead to, this will be set up by the third party.
|
|
112
|
-
* `explore_navigation_insert_position` is used to determine if the navigation item should be inserted before or after the given selector.
|
|
113
|
-
* `explore_insert_cta_in_tpi` is used to insert a call to action in modals which opens the explore page as a modal.
|
|
114
|
-
*/
|
|
115
|
-
explore_navigation_selector?: string
|
|
116
|
-
explore_navigation_label?: string
|
|
117
|
-
explore_navigation_path?: string
|
|
118
|
-
explore_navigation_insert_position?: InsertPosition
|
|
119
|
-
explore_insert_cta_in_tpi?: boolean
|
|
120
|
-
explore_custom_style?: string
|
|
121
|
-
explore_use_router?: boolean
|
|
122
|
-
}
|
|
1
|
+
import type { InsertPosition } from './position'
|
|
2
|
+
|
|
3
|
+
export type ConfigResponse = {
|
|
4
|
+
/**
|
|
5
|
+
* Used to exclude URL matching a regex pattern. If a url matches, nothing is executed beyond fetching the config.
|
|
6
|
+
* The url should never be indexed.
|
|
7
|
+
*/
|
|
8
|
+
exclude_urls_pattern?: string
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Used to inject custom styling for the links, modal, and popover. All styling is done via CSS variables. The passed
|
|
12
|
+
* string should not contain a selector.
|
|
13
|
+
* For example:
|
|
14
|
+
* `--some-variable: some-value;`
|
|
15
|
+
*
|
|
16
|
+
* rather than:
|
|
17
|
+
* `body { --some-variable: some-value; }`
|
|
18
|
+
*/
|
|
19
|
+
custom_style?: string
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The primary selector for the entire article from which text will be selected. Should contain as little content as
|
|
23
|
+
* possible. Should match all pages. May contain multiple selectors like `.article, .listicle`.
|
|
24
|
+
*/
|
|
25
|
+
html_selector?: string
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Some pages contain elements that can't easily be excluded via the `html_selector`. These elements can instead be
|
|
29
|
+
* excluded via this property. May contain multiple selectors like `.footer, .ad`.
|
|
30
|
+
*/
|
|
31
|
+
exclude_elements_selector?: string
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Disable all injections from showing on pages without editorial mode enabled
|
|
35
|
+
*/
|
|
36
|
+
disable_public_injections?: boolean
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Region to fall back on if other methods of getting the region fail. This should be equal to the region most relevant
|
|
40
|
+
* to the partner. Should be lowercase.
|
|
41
|
+
*/
|
|
42
|
+
fallback_region?: string
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Disclaimer text that is shown above playlinks in title cards used to replace the default text
|
|
46
|
+
*/
|
|
47
|
+
playlinks_disclaimer_text?: string
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Some partners may want to display titles without affiliate links, which currently comes down to no playlinks.
|
|
51
|
+
* This can also be set via the config on the script itself.
|
|
52
|
+
*/
|
|
53
|
+
no_affiliate?: boolean
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Whether or not we can insert retargeting pixels. Not all third parties allow this and it is disabled by default
|
|
57
|
+
*/
|
|
58
|
+
allow_retargeting_pixels?: boolean
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* By default affiliate links (playlinks) will render as links even without consent, as a disclaimer is given. Set to true to require explicit consent, rendering as static text without consent.
|
|
62
|
+
*/
|
|
63
|
+
require_affiliate_consent?: boolean
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Scroll reveal posters that show on mobile are enabled by default. Use this option to disable them.
|
|
67
|
+
*/
|
|
68
|
+
disable_scroll_reveal_posters?: boolean
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Playlinks are merged by default, when this option is enabled playlinks will instead be shown categorized.
|
|
72
|
+
*/
|
|
73
|
+
categorize_playlinks?: boolean
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* By default no user identifiable data is tracked. This can be changed using this option. User ids are stored in localStorage and sent along with any tracking request.
|
|
77
|
+
*/
|
|
78
|
+
allow_user_id_tracking?: boolean
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The sid for the current domain, used for tracking
|
|
82
|
+
*/
|
|
83
|
+
domain_sid?: string
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The sid for the organization the domain belongs to, used for tracking. Can be empty.
|
|
87
|
+
*/
|
|
88
|
+
organization_sid?: string
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The following options are all relevant for in text disclaimers, which renders as a disclaimer text within the article,
|
|
92
|
+
* rather than only inside of title cards.
|
|
93
|
+
* Change the text content using `in_text_disclaimer_text`.
|
|
94
|
+
* Change where the element is inserted using `in_text_disclaimer_selector`, by default it will insert before the first text element.
|
|
95
|
+
* Change the insert position using `in_text_disclaimer_insert_position`, by default it will insert before the given selector.
|
|
96
|
+
*/
|
|
97
|
+
in_text_disclaimer_enabled?: boolean
|
|
98
|
+
in_text_disclaimer_text?: string
|
|
99
|
+
in_text_disclaimer_selector?: string
|
|
100
|
+
in_text_disclaimer_insert_position?: InsertPosition
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Open TPI links in explore rather than in modals in the article
|
|
104
|
+
*/
|
|
105
|
+
open_tpi_links_in_explore?: boolean
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* These options are all relevant for the Explore component, which can be inserted as a widget on any page or as a modal.
|
|
109
|
+
* `explore_navigation_selector` is used to select the navigation element that should be copied and inserted _after_.
|
|
110
|
+
* `explore_navigation_label` will end up being the label of the navigation item, defaults to `Streaming Guide`.
|
|
111
|
+
* `explore_navigation_path` is the path that the navigation item will lead to, this will be set up by the third party.
|
|
112
|
+
* `explore_navigation_insert_position` is used to determine if the navigation item should be inserted before or after the given selector.
|
|
113
|
+
* `explore_insert_cta_in_tpi` is used to insert a call to action in modals which opens the explore page as a modal.
|
|
114
|
+
*/
|
|
115
|
+
explore_navigation_selector?: string
|
|
116
|
+
explore_navigation_label?: string
|
|
117
|
+
explore_navigation_path?: string
|
|
118
|
+
explore_navigation_insert_position?: InsertPosition
|
|
119
|
+
explore_insert_cta_in_tpi?: boolean
|
|
120
|
+
explore_custom_style?: string
|
|
121
|
+
explore_use_router?: boolean
|
|
122
|
+
}
|
|
@@ -867,6 +867,26 @@ describe('injection.ts', () => {
|
|
|
867
867
|
expect(document.querySelectorAll('a')).toHaveLength(4)
|
|
868
868
|
})
|
|
869
869
|
|
|
870
|
+
it('Should properly inject into lists of titles that contain special characters', () => {
|
|
871
|
+
document.body.innerHTML = `<section>
|
|
872
|
+
<ul>
|
|
873
|
+
<li>Daisy Jones & The Six</li>
|
|
874
|
+
<li>Love & Death</li>
|
|
875
|
+
</ul>
|
|
876
|
+
</section>
|
|
877
|
+
`
|
|
878
|
+
|
|
879
|
+
const elements = getLinkInjectionElements(/** @type {HTMLElement} */ (document.querySelector('section')))
|
|
880
|
+
const injections = [
|
|
881
|
+
generateInjection('Daisy Jones & The Six', 'Daisy Jones & The Six'),
|
|
882
|
+
generateInjection('Love & Death', 'Love & Death'),
|
|
883
|
+
]
|
|
884
|
+
|
|
885
|
+
injectLinksInDocument(elements, { aiInjections: [], manualInjections: injections })
|
|
886
|
+
|
|
887
|
+
expect(document.querySelectorAll('a')).toHaveLength(2)
|
|
888
|
+
})
|
|
889
|
+
|
|
870
890
|
it('Should properly inject into titles that are split up by multiple elements when phrase_before and phrase_after are given', () => {
|
|
871
891
|
document.body.innerHTML = '<section>Some text with a <strong>phra</strong><strong>se</strong> in it</section>'
|
|
872
892
|
|