* Builds the expriments table.
()
| 88 | * Builds the expriments table. |
| 89 | */ |
| 90 | function 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 | ); |
no test coverage detected