New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add reload-failed-proxied-images
feature
#2393
Merged
fregante
merged 19 commits into
refined-github:master
from
GramThanos:reload-failed-proxied-images
Sep 1, 2019
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1095339
Implemented 'Auto reload failed github proxied images' feature
GramThanos b432154
Style corrections
GramThanos 89ebcf5
More style corrections based on TravisCI
GramThanos 87864ca
Removed file extension when importing feature and added missing semic…
GramThanos 3eddd63
More style corrections based on TravisCI
GramThanos 435544c
More style corrections based on TravisCI
GramThanos b746af8
Spelling correction (thanks @busches)
GramThanos bae0b4b
Removed unnecessary condition (thanks @busches)
GramThanos 5766080
Removed unnecessary else after return
GramThanos b14f5d4
Style correction
GramThanos f87a943
Spelling corrections
GramThanos 0c1c06a
Fixed additional request bug when image cache was disabled
GramThanos 6e1eaf1
@GramThanos Style correction
GramThanos d3283d5
Simplefied based on @fregante 's suggestion
GramThanos 7d03cd2
Merge branch 'master' into reload-failed-proxied-images
GramThanos 28df2a2
Update package-lock.json
GramThanos 2c66fee
Changed from `select-dom` to `delegate-it` (based on @fregante 's code)
GramThanos 28bc55a
Updated readme and added screenshot
GramThanos 315efbb
Update readme.md
GramThanos File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import delay from 'delay'; | ||
import delegate from 'delegate-it'; | ||
import loadImage from 'image-promise'; | ||
import features from '../libs/features'; | ||
|
||
async function handleErroredImage({target}: any): Promise<void> { | ||
await delay(5000); | ||
try { | ||
// A clone image retries downloading | ||
// `loadImage` awaits it | ||
// If successfully loaded, the failed image will be replaced. | ||
target.replaceWith(await loadImage(target.cloneNode() as HTMLImageElement)); | ||
} catch {} | ||
} | ||
|
||
function init(): void { | ||
delegate('img[src^="https://camo.githubusercontent.com/"]', 'error', handleErroredImage, true); | ||
} | ||
|
||
features.add({ | ||
id: __featureName__, | ||
description: 'Retries downloading images that failed downloading due to GitHub limited proxying.', | ||
screenshot: 'https://user-images.githubusercontent.com/14858959/64068746-21991100-cc45-11e9-844e-827f5ac9b51e.png', | ||
load: features.onAjaxedPages, | ||
init | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's retry once, then.
If you use https://github.com/fregante/image-promise this whole feature can just be:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on my tests/debugging
delegate
does not work in this case. I think GitHub gabs the errors for statistics and the event does not bubble up to the body element. Maybe I am wrong.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works if you pass a
true
as the last parameter ofdelegate
to make it acapture
listener.