|
1 | 1 | export const addStyles = () => {
|
2 |
| - const { $ } = Cypress; |
3 | 2 | const hasStyles = top === null || top === void 0 ? void 0 : top.document.querySelector('#xhrStyle');
|
4 | 3 | const hasToggleButton = top === null || top === void 0 ? void 0 : top.document.querySelector('#xhrToggle');
|
5 | 4 | const defaultStyles = `
|
@@ -45,6 +44,9 @@ export const addStyles = () => {
|
45 | 44 | border-style: solid;
|
46 | 45 | border-color: transparent transparent #f3f4fa transparent;
|
47 | 46 | }
|
| 47 | + .reporter:has(#xhrToggle:checked) .command.command-name-request:has(.command-is-event) { |
| 48 | + display:none |
| 49 | + } |
48 | 50 | `;
|
49 | 51 | const turnOffXhrIcon = `<svg xmlns="http://www.w3.org/2000/svg" width="17" height="17" viewBox="0 0 24 24"><path fill="#afb3c7" d="M12 6.5c2.76 0 5 2.24 5 5c0 .51-.1 1-.24 1.46l3.06 3.06c1.39-1.23 2.49-2.77 3.18-4.53C21.27 7.11 17 4 12 4c-1.27 0-2.49.2-3.64.57l2.17 2.17c.47-.14.96-.24 1.47-.24zM2.71 3.16a.996.996 0 0 0 0 1.41l1.97 1.97A11.892 11.892 0 0 0 1 11.5C2.73 15.89 7 19 12 19c1.52 0 2.97-.3 4.31-.82l2.72 2.72a.996.996 0 1 0 1.41-1.41L4.13 3.16c-.39-.39-1.03-.39-1.42 0zM12 16.5c-2.76 0-5-2.24-5-5c0-.77.18-1.5.49-2.14l1.57 1.57c-.03.18-.06.37-.06.57c0 1.66 1.34 3 3 3c.2 0 .38-.03.57-.07L14.14 16c-.65.32-1.37.5-2.14.5zm2.97-5.33a2.97 2.97 0 0 0-2.64-2.64l2.64 2.64z"/></svg>`;
|
50 | 52 | const turnOnXhrIcon = `<svg xmlns="http://www.w3.org/2000/svg" width="17" height="17" viewBox="0 0 24 24"><path fill="#afb3c7" d="M12 4C7 4 2.73 7.11 1 11.5C2.73 15.89 7 19 12 19s9.27-3.11 11-7.5C21.27 7.11 17 4 12 4zm0 12.5c-2.76 0-5-2.24-5-5s2.24-5 5-5s5 2.24 5 5s-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3s3-1.34 3-3s-1.34-3-3-3z"/></svg>`;
|
@@ -82,37 +84,32 @@ export const addStyles = () => {
|
82 | 84 | headerToggleButton === null || headerToggleButton === void 0 ? void 0 : headerToggleButton.appendChild(headerToggleInput);
|
83 | 85 | headerToggleButton === null || headerToggleButton === void 0 ? void 0 : headerToggleButton.appendChild(headerToggleLabel);
|
84 | 86 | }
|
85 |
| - const xhrToggleElement = top === null || top === void 0 ? void 0 : top.document.querySelector('#xhrToggle'); |
86 |
| - const xhrToggleLabelElement = top === null || top === void 0 ? void 0 : top.document.querySelector('[for=xhrToggle]'); |
87 |
| - const xhrTooltipElement = top === null || top === void 0 ? void 0 : top.document.querySelector('#xhrTooltip'); |
88 |
| - const hideXhr = () => { |
89 |
| - $("#unified-reporter", top === null || top === void 0 ? void 0 : top.document).find(".command.command-name-request").has(".command-is-event").css("display", "none"); |
90 |
| - xhrToggleLabelElement.innerHTML = turnOnXhrIcon; |
91 |
| - xhrTooltipElement.innerHTML = turnOnXhrDescription; |
92 |
| - }; |
93 |
| - const showXhr = () => { |
94 |
| - $("#unified-reporter", top === null || top === void 0 ? void 0 : top.document).find(".command.command-name-request").has(".command-is-event").css("display", "block"); |
95 |
| - xhrToggleLabelElement.innerHTML = turnOffXhrIcon; |
96 |
| - xhrTooltipElement.innerHTML = turnOffXhrDescription; |
97 |
| - }; |
98 |
| - if (Cypress.env('hideXhr')) { |
99 |
| - xhrToggleElement.setAttribute('checked', 'true'); |
100 |
| - Cypress.on('log:added', () => { |
101 |
| - hideXhr(); |
102 |
| - }); |
103 |
| - } |
104 |
| - else { |
105 |
| - // just to be on the safe side when changing hideXhr variable |
106 |
| - xhrToggleElement.setAttribute('checked', 'false'); |
107 |
| - showXhr(); |
| 87 | + const xhrToggleElement = top.document.querySelector('#xhrToggle'); |
| 88 | + const xhrToggleLabelElement = top.document.querySelector('[for=xhrToggle]'); |
| 89 | + const xhrTooltipElement = top.document.querySelector('#xhrTooltip'); |
| 90 | + if (xhrToggleElement && xhrToggleLabelElement && xhrTooltipElement) { |
| 91 | + if (Cypress.env('hideXhr') === true || Cypress.env('hideXhr') === undefined) { |
| 92 | + xhrToggleElement.checked = true; |
| 93 | + xhrToggleLabelElement.innerHTML = turnOnXhrIcon; |
| 94 | + xhrTooltipElement.innerHTML = turnOnXhrDescription; |
| 95 | + } |
| 96 | + else { |
| 97 | + xhrToggleElement.checked = false; |
| 98 | + xhrToggleLabelElement.innerHTML = turnOffXhrIcon; |
| 99 | + xhrTooltipElement.innerHTML = turnOffXhrDescription; |
| 100 | + } |
108 | 101 | }
|
109 |
| - xhrToggleElement.addEventListener('change', (e) => { |
| 102 | + xhrToggleElement === null || xhrToggleElement === void 0 ? void 0 : xhrToggleElement.addEventListener('change', (e) => { |
110 | 103 | // @ts-ignore errors about HTMLElement
|
111 | 104 | if (e.target.checked) {
|
112 |
| - hideXhr(); |
| 105 | + // when checked, xhr elements are hidden |
| 106 | + xhrToggleLabelElement.innerHTML = turnOnXhrIcon; |
| 107 | + xhrTooltipElement.innerHTML = turnOnXhrDescription; |
113 | 108 | }
|
114 | 109 | else {
|
115 |
| - showXhr(); |
| 110 | + // when unchecked, xhr elements are visible |
| 111 | + xhrToggleLabelElement.innerHTML = turnOffXhrIcon; |
| 112 | + xhrTooltipElement.innerHTML = turnOffXhrDescription; |
116 | 113 | }
|
117 | 114 | });
|
118 | 115 | };
|
0 commit comments