Skip to content

Instantly share code, notes, and snippets.

@K-atc
Created January 3, 2021 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save K-atc/4eebd88bbbed00e572fb4705b3688b10 to your computer and use it in GitHub Desktop.
Save K-atc/4eebd88bbbed00e572fb4705b3688b10 to your computer and use it in GitHub Desktop.
<a href=URL> の下に <img src=URL loading=lazy> を追加するブックマークレット
javascript:(function(){
function check_extention(url) {
for (const ext of [".jpg", ".jpeg", ".png", ".png"]) {
if (url.includes(ext)) return true;
}
return false;
}
function append_image(el) {
var el_img = document.createElement("img");
el_img.setAttribute("src", el.href);
el_img.setAttribute("loading", "lazy");
el.append(el_img);
}
Array.from(document.getElementsByTagName("a")).filter(function(el) { return check_extention(el.href); }).map(function(el) { append_image(el) } )
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment