|
| 1 | +;(() => { |
| 2 | + if (!location.search.includes(`redirect=true`)) { |
| 3 | + return |
| 4 | + } |
| 5 | + |
| 6 | + const v3Url = document.body.dataset.v3Url |
| 7 | + if (!v3Url) { |
| 8 | + return |
| 9 | + } |
| 10 | + |
| 11 | + const hashRedirect = |
| 12 | + typeof __pageRedirects !== 'undefined' && __pageRedirects[location.hash] |
| 13 | + const finalUrl = hashRedirect || v3Url |
| 14 | + |
| 15 | + const preferV3 = localStorage.getItem('prefer-v3') |
| 16 | + if (preferV3 === 'true') { |
| 17 | + location.href = `https://vuejs.org${finalUrl}` |
| 18 | + } |
| 19 | + |
| 20 | + const today = new Date() |
| 21 | + const target = new Date('2022-05-07') |
| 22 | + const timeinmilisec = target.getTime() - today.getTime() |
| 23 | + const days = Math.ceil(timeinmilisec / (1000 * 60 * 60 * 24)) |
| 24 | + |
| 25 | + const el = document.createElement('div') |
| 26 | + el.className = `v3-notice` |
| 27 | + el.innerHTML = ` |
| 28 | +<h3>Heads Up!</h3> |
| 29 | +<p> |
| 30 | +This page contains documentation for Vue 2. The Vue 3 version of the URL you are visiting is: <a id="v3-url" target="_blank"></a>. |
| 31 | +</p> |
| 32 | +<p> |
| 33 | +The original URL, <code>https://vuejs.org<span id="original-url"></span></code> |
| 34 | +will permanantly redirect to the v3 URL above after <b>May 7th, 2022 (${days} days from now).</b> If you need |
| 35 | +future access to this v2 page, please use the v2-prefixed URL |
| 36 | +<code>https://v2.vuejs.org<span id="current-url"></span></code>. |
| 37 | +</p> |
| 38 | +<p> |
| 39 | +You can learn more about the Vue 2 -> Vue 3 default version switch in |
| 40 | +<a target="_blank" href="https://blog.vuejs.org/posts/vue-3-as-the-new-default.html">this blog post</a>. |
| 41 | +</p> |
| 42 | +<p> |
| 43 | +Would you like to start redirecting all v2 URLs to v3 right now? |
| 44 | +</p> |
| 45 | +<p> |
| 46 | +<a class="go">Yes</a> |
| 47 | +<a class="stay">Not yet</a> |
| 48 | +</p> |
| 49 | + `.trim() |
| 50 | + |
| 51 | + const style = document.createElement('style') |
| 52 | + style.textContent = ` |
| 53 | +.v3-notice { |
| 54 | + position: fixed; |
| 55 | + top: 20px; |
| 56 | + --width: min(calc(100vw - 20px), 500px); |
| 57 | + left: calc(50vw - var(--width) / 2); |
| 58 | + width: var(--width); |
| 59 | + z-index: 9999; |
| 60 | + background-color: #f8f8f8; |
| 61 | + border: 2px solid #ffa500; |
| 62 | + border-radius: 8px; |
| 63 | + padding: 0 20px; |
| 64 | + box-shadow: 0 10px 28px rgba(0,0,0,0.25); |
| 65 | +} |
| 66 | +.v3-notice a { |
| 67 | + color: #42b983; |
| 68 | + font-weight: bold; |
| 69 | +} |
| 70 | +.v3-notice .go, .v3-notice .stay { |
| 71 | + display: inline-block; |
| 72 | + padding: 8px 12px; |
| 73 | + border-radius: 4px; |
| 74 | + cursor: pointer; |
| 75 | +} |
| 76 | +.v3-notice .go { |
| 77 | + background-color: #42b983; |
| 78 | + color: #fff; |
| 79 | +} |
| 80 | +.v3-notice .stay { |
| 81 | + background-color: #ddd; |
| 82 | + color: #666; |
| 83 | +} |
| 84 | +.v3-notice code { |
| 85 | + background-color: transparent; |
| 86 | +} |
| 87 | + ` |
| 88 | + |
| 89 | + document.body.appendChild(style) |
| 90 | + document.body.appendChild(el) |
| 91 | + |
| 92 | + el.querySelector('#original-url').textContent = location.pathname |
| 93 | + el.querySelector('#current-url').textContent = location.pathname |
| 94 | + const v3Link = el.querySelector('#v3-url') |
| 95 | + |
| 96 | + v3Link.textContent = |
| 97 | + v3Link.href = |
| 98 | + el.querySelector('.go').href = |
| 99 | + `https://vuejs.org${finalUrl}` |
| 100 | + |
| 101 | + el.querySelector('.go').addEventListener('click', () => { |
| 102 | + localStorage.setItem('prefer-v3', 'true') |
| 103 | + }) |
| 104 | + |
| 105 | + el.querySelector('.stay').addEventListener('click', () => { |
| 106 | + localStorage.setItem('prefer-v3', 'false') |
| 107 | + document.body.removeChild(el) |
| 108 | + document.body.removeChild(style) |
| 109 | + location.href = location.pathname |
| 110 | + }) |
| 111 | +})() |
0 commit comments