Last active
January 2, 2016 08:39
-
-
Save Shinpeim/8278065 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// ==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