|
| 1 | +import shortenUrl from '../index.js'; |
| 2 | + |
| 3 | +// URLs imported from index.test.js |
| 4 | +const urls = [ |
| 5 | + 'https://github.com/fregante/shorten-repo-url/', |
| 6 | + 'https://github.com/fregante/shorten-repo-url/?tab=readme-ov-file', |
| 7 | + 'https://github.com/fregante/shorten-repo-url/tree/v0.12', |
| 8 | + 'https://github.com/fregante/shorten-repo-url/tree/d71718db6aa4feb8dc10edbad1134472468e971a', |
| 9 | + 'https://github.com/nodejs/node/', |
| 10 | + 'https://github.com/nodejs/shorten-repo-url/', |
| 11 | + 'https://github.com/nodejs/node/tree/v0.12', |
| 12 | + 'https://github.com/nodejs/node/tree/d71718db6aa4feb8dc10edbad1134472468e971a', |
| 13 | + 'https://github.com/fregante/shorten-repo-url/tree/master/doc', |
| 14 | + 'https://github.com/fregante/shorten-repo-url/tree/v0.12/doc', |
| 15 | + 'https://github.com/fregante/shorten-repo-url/tree/d71718db6aa4feb8dc10edbad1134472468e971a/doc', |
| 16 | + 'https://github.com/nodejs/node/tree/master/doc', |
| 17 | + 'https://github.com/nodejs/node/tree/v0.12/doc', |
| 18 | + 'https://github.com/nodejs/node/tree/d71718db6aa4feb8dc10edbad1134472468e971a/doc', |
| 19 | + 'https://github.com/fregante/shorten-repo-url/blob/master/.gitignore', |
| 20 | + 'https://github.com/fregante/shorten-repo-url/blob/v0.12/.gitignore', |
| 21 | + 'https://github.com/fregante/shorten-repo-url/blob/cc8fc46/.gitignore', |
| 22 | + 'https://github.com/fregante/shorten-repo-url/blob/main/한글.txt', |
| 23 | + 'https://github.com/nodejs/node/blob/master/.gitignore', |
| 24 | + 'https://github.com/nodejs/node/blob/v0.12/.gitignore', |
| 25 | + 'https://github.com/nodejs/node/blob/cc8fc46/.gitignore', |
| 26 | + 'https://github.com/fregante/shorten-repo-url/blame/master/.gitignore', |
| 27 | + 'https://github.com/fregante/shorten-repo-url/blame/v0.12/.gitignore', |
| 28 | + 'https://github.com/fregante/shorten-repo-url/blame/cc8fc46/.gitignore', |
| 29 | + 'https://github.com/nodejs/node/blame/master/.gitignore', |
| 30 | + 'https://github.com/nodejs/node/blame/v0.12/.gitignore', |
| 31 | + 'https://github.com/nodejs/node/blame/cc8fc46/.gitignore', |
| 32 | + 'https://github.com/fregante/shorten-repo-url/commits/master/.gitignore', |
| 33 | + 'https://github.com/fregante/shorten-repo-url/commits/v0.12/.gitignore', |
| 34 | + 'https://github.com/fregante/shorten-repo-url/commits/cc8fc46/.gitignore', |
| 35 | + 'https://github.com/nodejs/node/commits/master/.gitignore', |
| 36 | + 'https://github.com/nodejs/node/commits/v0.12/.gitignore', |
| 37 | + 'https://github.com/nodejs/node/commits/cc8fc46/.gitignore', |
| 38 | + 'https://github.com/fregante/shorten-repo-url/commit/cc8fc46.diff', |
| 39 | + 'https://github.com/fregante/shorten-repo-url/commit/cc8fc46.patch', |
| 40 | + 'https://github.com/nodejs/node/commit/cc8fc46.diff', |
| 41 | + 'https://github.com/nodejs/node/commit/cc8fc46.patch', |
| 42 | + 'https://github.com/fregante/shorten-repo-url/releases/tag/v0.12.0', |
| 43 | + 'https://github.com/nodejs/node/releases/tag/v0.12.0', |
| 44 | + 'https://github.com/fregante/shorten-repo-url/milestone/25', |
| 45 | + 'https://github.com/fregante/shorten-repo-url/compare/d71718db6aa4feb8dc10edbad1134472468e971a', |
| 46 | + 'https://github.com/fregante/shorten-repo-url/compare/master', |
| 47 | + 'https://github.com/fregante/shorten-repo-url/compare/master...master', |
| 48 | + 'https://github.com/nodejs/node/compare/d71718db6aa4feb8dc10edbad1134472468e971a', |
| 49 | + 'https://github.com/nodejs/node/compare/master', |
| 50 | + 'https://github.com/nodejs/node/compare/master...master', |
| 51 | + 'https://github.com/nodejs/node/milestone/25', |
| 52 | + 'https://github.com/fregante/shorten-repo-url/labels/npm', |
| 53 | + 'https://github.com/nodejs/node/labels/npm', |
| 54 | + 'https://github.com/nodejs/node/labels/Please%21%20♥', |
| 55 | + 'https://github.com/refined-github/refined-github/labels/Please%21%20♥%EF%B8%8E', |
| 56 | + 'https://github.com/fregante/shorten-repo-url/archive/6.4.1.zip', |
| 57 | + 'https://github.com/fregante/shorten-repo-url/releases/download/6.4.1/now-macos', |
| 58 | + 'https://github.com/zeit/now-cli/archive/6.4.1.zip', |
| 59 | + 'https://github.com/zeit/now-cli/releases/download/6.4.1/now-macos', |
| 60 | + 'https://github.com/bfred-it/shorten-repo-url/network/dependents', |
| 61 | + 'https://github.com/bfred-it/shorten-repo-url/network/dependencies', |
| 62 | + 'https://github.com/network/dependencies', |
| 63 | + 'https://github.com/bfred-it/shorten-repo-url/wiki', |
| 64 | + 'https://github.com/fregante/shorten-repo-url/pulse', |
| 65 | + 'https://github.com/fregante/shorten-repo-url/labels', |
| 66 | + 'https://github.com/fregante/shorten-repo-url/compare', |
| 67 | + 'https://github.com/fregante/shorten-repo-url/network', |
| 68 | + 'https://github.com/fregante/shorten-repo-url/projects', |
| 69 | + 'https://github.com/fregante/shorten-repo-url/releases', |
| 70 | + 'https://github.com/fregante/shorten-repo-url/milestones', |
| 71 | + 'https://github.com/fregante/shorten-repo-url/contributors', |
| 72 | + 'https://github.com/fregante/shorten-repo-url/pull/123/files', |
| 73 | + 'https://github.com/nodejs/node/pull/123/files', |
| 74 | + 'https://github.com/fregante/shorten-repo-url/pull/123/commits', |
| 75 | + 'https://github.com/fregante/shorten-repo-url/pull/123/checks', |
| 76 | + 'https://github.com/nodejs/node/wiki', |
| 77 | + 'https://github.com/nodejs/node/pulse', |
| 78 | + 'https://github.com/nodejs/node/labels', |
| 79 | + 'https://github.com/nodejs/node/compare', |
| 80 | + 'https://github.com/nodejs/node/network', |
| 81 | + 'https://github.com/nodejs/node/projects', |
| 82 | + 'https://github.com/nodejs/node/releases', |
| 83 | + 'https://github.com/nodejs/node/milestones', |
| 84 | + 'https://github.com/nodejs/node/contributors', |
| 85 | + 'https://github.com/nodejs/node/graphs/commit-activity', |
| 86 | + 'https://rawgit.com/fregante/shorten-repo-url/master/.gitignore', |
| 87 | + 'https://cdn.rawgit.com/fregante/shorten-repo-url/v0.12/.gitignore', |
| 88 | + 'https://cdn.rawgit.com/fregante/shorten-repo-url/d71718db/.gitignore', |
| 89 | + 'https://raw.githubusercontent.com/fregante/shorten-repo-url/master/.gitignore', |
| 90 | + 'https://raw.githubusercontent.com/fregante/shorten-repo-url/v0.12/.gitignore', |
| 91 | + 'https://raw.githubusercontent.com/fregante/shorten-repo-url/d71718db/.gitignore', |
| 92 | + 'https://rawgit.com/nodejs/node/master/.gitignore', |
| 93 | + 'https://cdn.rawgit.com/nodejs/node/v0.12/.gitignore', |
| 94 | + 'https://cdn.rawgit.com/nodejs/node/d71718db/.gitignore', |
| 95 | + 'https://raw.githubusercontent.com/nodejs/node/master/.gitignore', |
| 96 | + 'https://raw.githubusercontent.com/nodejs/node/v0.12/.gitignore', |
| 97 | + 'https://raw.githubusercontent.com/nodejs/node/d71718db/.gitignore', |
| 98 | + 'https://github.com/sindresorhus', |
| 99 | + 'https://github.com/nodejs', |
| 100 | + 'https://github.com/pulls', |
| 101 | + 'https://github.com/issues', |
| 102 | + 'https://github.com/trending', |
| 103 | + 'https://github.com/features', |
| 104 | + 'https://github.com/marketplace', |
| 105 | + 'https://github.com/trending/developers', |
| 106 | + 'https://github.com/settings/profile', |
| 107 | + 'https://github.com/', |
| 108 | + 'https://github.com', |
| 109 | + 'https://github.com/fregante/shorten-repo-url/issues', |
| 110 | + 'https://github.com/fregante/shorten-repo-url/issues?q=wow', |
| 111 | + 'https://github.com/fregante/shorten-repo-url/issues?q=is%3Aissue++is%3Aopen+sort%3Aupdated-desc+&unrelated=true', |
| 112 | + 'https://github.com/issues?q=is%3Aissue++is%3Aopen+sort%3Aupdated-desc+&unrelated=true', |
| 113 | + 'https://github.com/pulls?q=is%3Apr++is%3Aopen+sort%3Aupdated-desc+&unrelated=true', |
| 114 | + 'https://github.com/sindresorhus/notifier-for-github/pull/253/files/6b4489d417c9425dc27c5fb8d6b4a8518debd035..60cdcf3c3646164441bf8f037cef620479cdec59', |
| 115 | + 'https://togithub.com/fregante/shorten-repo-url/issues/25', |
| 116 | + 'https://togithub.com/fregante/shorten-repo-url/issues/28#issue-850900171', |
| 117 | + 'https://togithub.com/fregante/shorten-repo-url/pull/32', |
| 118 | + 'https://togithub.com/fregante/shorten-repo-url/pull/32/files', |
| 119 | + 'https://togithub.com/fregante/shorten-repo-url/pull/33#pullrequestreview-801229042', |
| 120 | + 'https://togithub.com/fregante/shorten-repo-url/pull/33#discussion_r750069394', |
| 121 | + 'https://togithub.com/nodejs/node/pull/123', |
| 122 | + 'https://togithub.com/nodejs/node/pull/123/files', |
| 123 | + 'https://togithub.com/fregante/shorten-repo-url/commit/98c6175b0cbd4caca71d24e68e57b942b0dfb549', |
| 124 | + 'https://togithub.com/refined-github/refined-github/commit/4f270c4f50e0a2a20085a6e92095117f10340322', |
| 125 | + 'https://togithub.com/refined-github/refined-github/commit/e81a9646b448d90c7e02ab41332cab0507dccbbd#commitcomment-60089354', |
| 126 | + 'https://github.com/refined-github/refined-github/wiki/%22Can-you-add-this-feature%3F%22#3-it-doesnt-require-options', |
| 127 | + 'https://github.com/refined-github/refined-github/wiki/%22Can-you-add-this-feature%3F%22#', |
| 128 | + 'https://github.com/refined-github/refined-github/wiki/%22Can-you-add-this-feature%3F%22', |
| 129 | + 'https://github.com/fregante/shorten-repo-url/wiki/%22Can-you-add-this-feature%3F%22', |
| 130 | + 'https://github.com/scarf005/hangul-test/wiki/한글-위키-페이지', |
| 131 | + 'https://github.com/scarf005/hangul-test/wiki/한글-위키-페이지#한글-헤딩', |
| 132 | + 'https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement#parameters', |
| 133 | + 'https://www.google.com/', |
| 134 | + 'https://wwww.google.com/', |
| 135 | + 'http://www.google.com/', |
| 136 | + 'https://www.npmjs.com/', |
| 137 | + 'https://www.npmjs.com/packaasdge/node', |
| 138 | + 'https://example.com/nodejs/node/blob/cc8fc46/.gitignore', |
| 139 | + 'https://example.site/한글로-된-URL', |
| 140 | + 'https://한글로-된-경로.com/하위경로#한글-해시', |
| 141 | +]; |
| 142 | + |
| 143 | +const currentLocation = 'https://github.com/fregante/shorten-repo-url/issue/1'; |
| 144 | + |
| 145 | +const urlInput = document.getElementById('url-input'); |
| 146 | +const output = document.getElementById('output'); |
| 147 | +const examplesContainer = document.getElementById('examples'); |
| 148 | + |
| 149 | +function updateOutput(url) { |
| 150 | + if (!url) { |
| 151 | + output.innerHTML = ''; |
| 152 | + output.classList.remove('has-content'); |
| 153 | + return; |
| 154 | + } |
| 155 | + |
| 156 | + const shortened = shortenUrl(url, currentLocation); |
| 157 | + |
| 158 | + if (shortened) { |
| 159 | + output.classList.add('has-content'); |
| 160 | + output.innerHTML = ` |
| 161 | + <div class="result">${shortened}</div> |
| 162 | + <div class="original">Original: ${url}</div> |
| 163 | + `; |
| 164 | + } else { |
| 165 | + output.classList.add('has-content'); |
| 166 | + output.innerHTML = ` |
| 167 | + <div class="result">Not a GitHub URL or unable to shorten</div> |
| 168 | + <div class="original">Original: ${url}</div> |
| 169 | + `; |
| 170 | + } |
| 171 | +} |
| 172 | + |
| 173 | +// Handle input changes |
| 174 | +urlInput.addEventListener('input', (e) => { |
| 175 | + updateOutput(e.target.value); |
| 176 | +}); |
| 177 | + |
| 178 | +// Initialize examples |
| 179 | +function renderExamples() { |
| 180 | + // Show a subset of interesting examples |
| 181 | + const interestingUrls = [ |
| 182 | + 'https://github.com/nodejs/node/tree/v0.12/doc', |
| 183 | + 'https://github.com/fregante/shorten-repo-url/blob/cc8fc46/.gitignore', |
| 184 | + 'https://github.com/fregante/shorten-repo-url/releases/tag/v0.12.0', |
| 185 | + 'https://github.com/fregante/shorten-repo-url/pull/123/files', |
| 186 | + 'https://github.com/nodejs/node/labels/Please%21%20♥', |
| 187 | + 'https://github.com/fregante/shorten-repo-url/commit/cc8fc46.diff', |
| 188 | + 'https://raw.githubusercontent.com/nodejs/node/master/.gitignore', |
| 189 | + 'https://github.com/sindresorhus', |
| 190 | + 'https://github.com/fregante/shorten-repo-url/wiki/%22Can-you-add-this-feature%3F%22', |
| 191 | + 'https://togithub.com/fregante/shorten-repo-url/issues/25', |
| 192 | + ]; |
| 193 | + |
| 194 | + examplesContainer.innerHTML = interestingUrls.map(url => { |
| 195 | + const shortened = shortenUrl(url, currentLocation); |
| 196 | + return ` |
| 197 | + <div class="example"> |
| 198 | + <div class="example-url">${url}</div> |
| 199 | + <div class="example-result">→ ${shortened || 'Not shortened'}</div> |
| 200 | + </div> |
| 201 | + `; |
| 202 | + }).join(''); |
| 203 | +} |
| 204 | + |
| 205 | +renderExamples(); |
0 commit comments