Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ushiboy/8299146 to your computer and use it in GitHub Desktop.
Save ushiboy/8299146 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() {
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);
})();
@ushiboy
Copy link
Author

ushiboy commented Jan 7, 2014

(´・ω・`)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment