MCPcopy
hub / github.com/ampproject/amphtml / build

Function build

tools/experiments/experiments.js:90–161  ·  view source on GitHub ↗

* Builds the expriments table.

()

Source from the content-addressed store, hash-verified

88 * Builds the expriments table.
89 */
90function build() {
91 const {host} = window.location;
92
93 const subdomain = document.getElementById('subdomain');
94 subdomain.textContent = host;
95
96 // #redirect contains UI that generates a subdomain experiments page link
97 // given a "google.com/amp/..." viewer URL.
98 const redirect = document.getElementById('redirect');
99 const input = redirect.querySelector('input');
100 const button = redirect.querySelector('button');
101 const anchor = redirect.querySelector('a');
102 button.addEventListener('click', function () {
103 let urlString = input.value.trim();
104 // Avoid protocol-less urlString from being parsed as a relative URL.
105 const hasProtocol = /^https?:\/\//.test(urlString);
106 if (!hasProtocol) {
107 urlString = 'https://' + urlString;
108 }
109 const url = parseUrlDeprecated(urlString);
110 if (url) {
111 const subdomain = url.hostname.replace(/\./g, '-');
112 const href = `https://${subdomain}.cdn.ampproject.org/experiments.html`;
113 anchor.href = href;
114 anchor.textContent = href;
115 }
116 });
117
118 const channelsTable = document.getElementById('channels-table');
119 CHANNELS.forEach(function (experiment) {
120 channelsTable.appendChild(buildExperimentRow(experiment));
121 });
122
123 const experimentsTable = document.getElementById('experiments-table');
124 EXPERIMENTS.forEach(function (experiment) {
125 experimentsTable.appendChild(buildExperimentRow(experiment));
126 });
127
128 if (host === 'cdn.ampproject.org') {
129 const experimentsDesc = document.getElementById('experiments-desc');
130 experimentsDesc.setAttribute('hidden', '');
131 experimentsTable.setAttribute('hidden', '');
132 } else {
133 redirect.setAttribute('hidden', '');
134 }
135
136 const rtvInput = document.getElementById('rtv');
137 const rtvButton = document.getElementById('rtv-submit');
138 rtvInput.addEventListener('input', () => {
139 rtvButton.disabled = rtvInput.value && !RTV_PATTERN.test(rtvInput.value);
140 rtvButton.textContent = rtvInput.value ? 'opt-in' : 'opt-out';
141 });
142 rtvButton.addEventListener('click', () => {
143 if (!rtvInput.value) {
144 showConfirmation_(
145 'Do you really want to opt out of RTV?',
146 setAmpOptInCookie_.bind(null, AMP_OPT_IN_COOKIE.DISABLED)
147 );

Callers 1

experiments.jsFile · 0.70

Calls 11

parseUrlDeprecatedFunction · 0.90
getCookieFunction · 0.90
buildExperimentRowFunction · 0.85
showConfirmation_Function · 0.85
isExperimentOn_Function · 0.85
getElementByIdMethod · 0.45
addEventListenerMethod · 0.45
testMethod · 0.45
replaceMethod · 0.45
forEachMethod · 0.45
setAttributeMethod · 0.45

Tested by

no test coverage detected