|
64 | 64 | return p;
|
65 | 65 | }
|
66 | 66 |
|
| 67 | + let ignoreHashChange = false; |
67 | 68 | async function hashChange() {
|
68 |
| - if (window.location.hash.startsWith('#project=')) { |
| 69 | + const hash = window.location.hash; |
| 70 | + if (hash.length > 0) { |
| 71 | + ignoreHashChange = true; |
| 72 | + window.history.replaceState( |
| 73 | + undefined, |
| 74 | + undefined, |
| 75 | + window.location.pathname + window.location.search, |
| 76 | + ); |
| 77 | + ignoreHashChange = false; |
| 78 | + } |
| 79 | + if (ignoreHashChange) { |
| 80 | + return; |
| 81 | + } |
| 82 | +
|
| 83 | + if (hash.startsWith('#project=')) { |
69 | 84 | try {
|
70 |
| - const json = decodeURIComponent( |
71 |
| - window.location.hash.substring(9), |
72 |
| - ); |
| 85 | + const json = decodeURIComponent(hash.substring(9)); |
73 | 86 | openProject(newSession(), {
|
74 | 87 | ...JSON.parse(json),
|
75 | 88 | timestamp: Date.now(),
|
|
80 | 93 | }
|
81 | 94 | }
|
82 | 95 |
|
83 |
| - if (window.location.hash.startsWith('#code=')) { |
| 96 | + if (hash.startsWith('#code=')) { |
84 | 97 | try {
|
85 |
| - const contents = decodeURIComponent( |
86 |
| - window.location.hash.substring(6), |
87 |
| - ); |
| 98 | + const contents = decodeURIComponent(hash.substring(6)); |
88 | 99 | openProject(newSession(), {
|
89 | 100 | files: [
|
90 | 101 | {
|
|
101 | 112 | }
|
102 | 113 | }
|
103 | 114 |
|
104 |
| - if (window.location.hash.startsWith('#url=')) { |
| 115 | + if (hash.startsWith('#url=')) { |
105 | 116 | try {
|
106 |
| - const url = decodeURIComponent( |
107 |
| - window.location.hash.substring(5), |
108 |
| - ); |
| 117 | + const url = decodeURIComponent(hash.substring(5)); |
109 | 118 | openProject(newSession(), await loadFromUrl(url));
|
110 | 119 | return;
|
111 | 120 | } catch (e) {
|
|
0 commit comments