Skip to content

Commit 64b30cb

Browse files
gibson042ljharb
authored andcommitted
Meta: Restore the automatic snapshot-warning collapse for internal preview navigation (#3843)
We do not use ci.tc39.es/preview/... Ref #3348
1 parent bcbc4ed commit 64b30cb

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

scripts/insert-snapshot-warning.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,32 @@ const WARNING_HTML = `
2424
</p>
2525
</details>
2626
<script>
27-
let base = "https://ci.tc39.es/preview/tc39/ecma262/sha/";
28-
if (
29-
location.href.startsWith(base) &&
30-
document.referrer.startsWith(base) &&
31-
location.href.substring(base.length, base.length + 40) === document.referrer.substring(base.length, base.length + 40)
32-
) {
33-
document.querySelector(".annoying-warning").open = false;
34-
}
27+
// automatically collapse the warning when navigating within the same snapshot
28+
(() => {
29+
let referrer;
30+
try {
31+
referrer = new URL(document.referrer);
32+
} catch (_err) {
33+
// ignore
34+
}
35+
if (!referrer || referrer.host !== location.host) return;
36+
37+
let getSpecPath = url => {
38+
let pathParts = url.pathname.split('/');
39+
let isMultipage = pathParts[pathParts.length - 2] === 'multipage';
40+
let pathPrefixEnd = isMultipage
41+
? -2
42+
: pathParts.findLastIndex(part => part !== '') + 1;
43+
let pathPrefix = pathParts.slice(0, pathPrefixEnd).join('/');
44+
return pathPrefix;
45+
};
46+
47+
let referrerPathPrefix = getSpecPath(referrer);
48+
let pathPrefix = getSpecPath(location);
49+
if (referrerPathPrefix === pathPrefix) {
50+
document.querySelector(".annoying-warning").open = false;
51+
}
52+
})();
3553
</script>
3654
`;
3755

0 commit comments

Comments
 (0)