|
1 | 1 | // ==UserScript== |
2 | 2 | // @name GitHub Image Preview |
3 | | -// @version 2.0.6 |
| 3 | +// @version 2.0.7 |
4 | 4 | // @description A userscript that adds clickable image thumbnails |
5 | 5 | // @license MIT |
6 | 6 | // @author Rob Garrison |
|
29 | 29 | background-color:transparent !important; } |
30 | 30 | .ghip-show-previews .Box-row:not(.ghsc-header):not(.hidden) > div[role] { |
31 | 31 | display:none !important; } |
32 | | - .ghip-wrapper.ghip-show-previews img.ghip-non-image { height:80px; |
33 | | - margin-top:15px; opacity:.2; } |
| 32 | + .ghip-wrapper.ghip-show-previews svg.ghip-non-image, |
| 33 | + .ghip-wrapper.ghip-show-previews img.ghip-non-image { height:80px; width:80px; |
| 34 | + margin-top:15px; } |
34 | 35 | .ghip-wrapper.ghip-show-previews .image { width:100%; position:relative; |
35 | 36 | overflow:hidden; text-align:center; } |
36 | 37 |
|
|
185 | 186 | let content = ""; |
186 | 187 | // not every submodule includes a link; reference examples from |
187 | 188 | // see https://github.com/electron/electron/tree/v1.1.1/vendor |
188 | | - const el = $("a", row) || $("div[role='rowheader'] span[title]", row); |
| 189 | + const el = $("div[role='rowheader'] a, div[role='rowheader'] span[title]", row); |
189 | 190 | const url = el && el.nodeName === "A" ? el.href : ""; |
190 | 191 | // use innerHTML because some links include path - see "third_party/lss" |
191 | 192 | const fileName = el && el.textContent.trim() || ""; |
|
215 | 216 | content = updateTemplate(url, `${title()}${svgPlaceholder(url)}`); |
216 | 217 | } else { |
217 | 218 | // *** non-images (file/folder icons) *** |
218 | | - const svg = $("svg", row); |
| 219 | + const svg = $("[role='gridcell'] svg, [role='gridcell'] img", row); |
219 | 220 | if (svg) { |
220 | 221 | // non-files svg class: "directory", "submodule" or "symlink" |
221 | 222 | // add "ghip-folder" class for file-filters userscript |
222 | 223 | const noExt = svg.matches(folderIconClasses) ? " ghip-folder" : ""; |
223 | | - // add xmlns otherwise the svg won't work inside an img |
224 | | - // GitHub doesn't include this attribute on any svg octicons |
225 | | - const svgHTML = svg.outerHTML.replace("<svg", "<svg xmlns='http://www.w3.org/2000/svg'"); |
| 224 | + const clone = svg.cloneNode(true); |
| 225 | + clone.classList.add("ghip-non-image"); |
226 | 226 | // include "leaflet-tile-container" to invert icon for GitHub-Dark |
227 | 227 | content = `${title("non-image")}<span class="leaflet-tile-container${noExt}">` + |
228 | | - `<img class="ghip-non-image" src="data:image/svg+xml;base64,` + |
229 | | - window.btoa(svgHTML) + `"/>`; |
230 | | - // get file name + extension |
231 | | - const str = url.substring(url.lastIndexOf("/") + 1, url.length); |
232 | | - // don't include extension for folders, or files with no extension, |
233 | | - // or files starting with a "." (e.g. ".gitignore") |
234 | | - content += (!noExt && str.indexOf(".") > 0) ? |
235 | | - "<h4 class='ghip-file-type'>" + |
236 | | - str |
237 | | - .substring(str.lastIndexOf(".") + 1, str.length) |
238 | | - .toUpperCase() + |
239 | | - "</h4></span>" : "</span>"; |
| 228 | + clone.outerHTML + "</span>"; |
240 | 229 | content = url ? |
241 | 230 | updateTemplate(url, content) : |
242 | 231 | // empty url; use non-link template |
|
0 commit comments