Skip to content

Instantly share code, notes, and snippets.

@Shinpeim
Last active January 2, 2016 08:39
Show Gist options
  • Save Shinpeim/8278065 to your computer and use it in GitHub Desktop.
Save Shinpeim/8278065 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name ChatWork Image Extractor
// @description Image extractor for ChatWork.
// @include https://www.chatwork.com/*
// @version 0.0.1
// ==/UserScript==
(function(){
function main(){
var extractedList = []
function extractImage(){
var links = document.getElementsByTagName('a');
var imageLinks = [];
for( var i = 0, l = links.length; i < l; i++) {
var el = links[i];
var href = el.href;
if (href && href.match(/^https:\/\/.+(jpeg|jpg|gif|png)$/)) {
imageLinks.push(el)
}
}
imageLinks.forEach(function(el){
for(var i = 0, l = extractedList.length; i < l; i++){
if (extractedList[i] == el) {
return;
}
}
var url = el.href;
var img = document.createElement('img');
img.src = url;
window.removeEventListener("DOMNodeInserted", extractImage, false);
el.parentNode.appendChild(img);
window.addEventListener("DOMNodeInserted", extractImage, false);
extractedList.push(el);
});
}
window.addEventListener("DOMNodeInserted", extractImage, false);
}
window.addEventListener('load', main, false);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment