File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments