Skip to content

Commit 7887922

Browse files
committed
reader mode: special-case fix for images on medium.com
1 parent f4aae21 commit 7887922

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

reader/reader.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,31 @@ function processArticle (data) {
216216

217217
// needed for wikipedia.org
218218

219-
var images = doc.querySelectorAll('img')
219+
var images = Array.from(doc.getElementsByTagName('img'))
220220

221-
for (var i = 0; i < images.length; i++) {
222-
if (images[i].src && images[i].srcset) {
223-
images[i].srcset = ''
224-
}
221+
if (articleLocation.hostname.includes('wikipedia.org')) {
222+
images.forEach(function (image) {
223+
if (image.src && image.srcset) {
224+
image.srcset = ''
225+
}
226+
})
227+
}
228+
229+
if (articleLocation.hostname === 'medium.com') {
230+
// medium.com - show high-resolution images
231+
var mediumImageRegex = /(?<=https?:\/\/miro.medium.com\/max\/)([0-9]+)(?=\/)/
232+
images.forEach(function (image) {
233+
if (image.src) {
234+
// for gifs
235+
image.src = image.src.replace('/freeze/', '/')
236+
if (mediumImageRegex.test(image.src)) {
237+
image.src = image.src.replace(mediumImageRegex, '2000')
238+
}
239+
} else {
240+
// empty images (for lazy loading) mess up paragraph spacing
241+
image.remove()
242+
}
243+
})
225244
}
226245

227246
extractAndShowNavigation(doc)

0 commit comments

Comments
 (0)