Forked from Shinpeim/chatwork-image-extractor.user.js
Last active
January 2, 2016 11:49
-
-
Save ushiboy/8299146 to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @name ChatWork Image Extractor | |
// @description Image extractor for ChatWork. | |
// @include https://www.chatwork.com/* | |
// @version 0.0.1 | |
// ==/UserScript== | |
(function() { | |
var forEach = Array.prototype.forEach, | |
ATTR_NAME_APPEND_IMG_DONE = 'data-append-img-done', | |
ATTR_NAME_APPEND_IMG = 'data-append-img'; | |
function extractImage(){ | |
forEach.call(document.getElementsByTagName('a'), function(el) { | |
var href = el.href; | |
if (href && href.match(/^https:\/\/.+(jpeg|jpg|gif|png)$/) && !el.hasAttribute(ATTR_NAME_APPEND_IMG_DONE)) { | |
var img = document.createElement('img'); | |
img.setAttribute(ATTR_NAME_APPEND_IMG, 1); | |
img.src = href; | |
el.setAttribute(ATTR_NAME_APPEND_IMG_DONE, 1); | |
el.parentNode.appendChild(img); | |
} | |
}); | |
} | |
function onDomNodeInserted(evt) { | |
var srcElement = evt.srcElement; | |
if (srcElement.hasAttribute && srcElement.hasAttribute(ATTR_NAME_APPEND_IMG)) return; | |
extractImage(); | |
} | |
function main() { | |
extractImage(); | |
window.addEventListener('DOMNodeInserted', onDomNodeInserted, false); | |
} | |
window.addEventListener('load', main, false); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(´・ω・`)