MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / connectedCallback

Method connectedCallback

docs/src/assets/version-selector.js:19–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17 }
18
19 connectedCallback() {
20 const currentVersion = (
21 versionRegex
22 .exec(location.pathname)?.[1]
23 .replace("archive/","")
24 || "dev"
25 );
26
27 if (currentVersion === "dev") {
28 this.innerHTML = `
29 <select>
30 <option value="/dev" selected>dev</option>
31 <option value="/stable">stable</option>
32 <option disabled>...</option>
33 </select>`;
34 } else if (currentVersion === "stable") {
35 this.innerHTML = `
36 <select>
37 <option value="/dev">dev</option>
38 <option value="/stable" selected>stable</option>
39 <option disabled>...</option>
40 </select>`;
41 } else {
42 this.innerHTML = `
43 <select>
44 <option value="/dev">dev</option>
45 <option value="/stable" >stable</option>
46 <option selected>${currentVersion}</option>
47 <option disabled>...</option>
48 </select>`;
49 }
50
51 const selectElement = this.querySelector('select');
52 selectElement.addEventListener('focus', async () => {
53 const versions = await fetchVersions();
54 selectElement.innerHTML = '';
55 versions.forEach(version => {
56 const option = document.createElement('option');
57 option.value = version.startsWith("v") ? `/archive/${version}` : `/${version}`;
58 option.text = version;
59 option.selected = currentVersion === version;
60 selectElement.appendChild(option);
61 });
62 }, {once: true});
63 selectElement.addEventListener('change', () => {
64 window.location.pathname = selectElement.value + location.pathname.replace(versionRegex, "")
65 });
66 }
67}
68
69window.customElements.define('version-selector', VersionSelector);

Callers

nothing calls this directly

Calls 4

fetchVersionsFunction · 0.85
execMethod · 0.80
addEventListenerMethod · 0.80
replaceMethod · 0.45

Tested by

no test coverage detected