Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getNamesByTag(tag) {
- elements = document.getElementsByClassName(tag);
- names = []
- for (var i=0; i < elements.length; i++) {
- name = elements[i].children[1].text;
- names.push(name);
- }
- return names;
- }
- function getImage() {
- image = document.getElementById('image');
- return image;
- }
- function getImageUrl() {
- url = getImage().src;
- return url;
- }
- function getImageId(url) {
- id = url.split('_')[1].split('.')[0];
- return id;
- }
- function getImageExt(url) {
- ext = url.split('_')[1].split('.')[1];
- return ext;
- }
- function insertAfter(newNode, referenceNode) {
- referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
- }
- char_names = getNamesByTag('tag-type-character');
- artist_names = getNamesByTag('tag-type-artist');
- copyright_names = getNamesByTag('tag-type-copyright');
- image_url = getImageUrl()
- image_id = getImageId(url);
- image_ext = getImageExt(url);
- image_name = '__' + char_names.join(' and ') +
- '_' + copyright_names.join(' and ') +
- '_drawn_by_' + artist_names.join(' and ') +
- '__' + image_id + '.' + image_ext;
- image_name = image_name.replace(/\s/g, '_');
- var link = document.createElement('a');
- link.setAttribute('href', image_url);
- link.setAttribute('download', image_name);
- link.text = 'Click to save';
- image_element = getImage();
- insertAfter(link, image_element);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement