Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getNamesByTag(tag) {
  2.     elements = document.getElementsByClassName(tag);
  3.     names = []
  4.     for (var i=0; i < elements.length; i++) {
  5.         name = elements[i].children[1].text;
  6.         names.push(name);
  7.     }
  8.     return names;
  9. }
  10.  
  11. function getImage() {
  12.     image = document.getElementById('image');
  13.     return image;
  14. }
  15.  
  16. function getImageUrl() {
  17.     url = getImage().src;
  18.     return url;
  19. }
  20.  
  21. function getImageId(url) {
  22.     id = url.split('_')[1].split('.')[0];
  23.     return id;
  24. }
  25.  
  26. function getImageExt(url) {
  27.     ext = url.split('_')[1].split('.')[1];
  28.     return ext;
  29. }
  30.  
  31. function insertAfter(newNode, referenceNode) {
  32.     referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
  33. }
  34.    
  35. char_names = getNamesByTag('tag-type-character');
  36. artist_names = getNamesByTag('tag-type-artist');
  37. copyright_names = getNamesByTag('tag-type-copyright');
  38.  
  39. image_url = getImageUrl()
  40. image_id = getImageId(url);
  41. image_ext = getImageExt(url);
  42.  
  43. image_name = '__' + char_names.join(' and ') +
  44.     '_' + copyright_names.join(' and ') +
  45.     '_drawn_by_' + artist_names.join(' and ') +
  46.     '__' + image_id + '.' + image_ext;
  47. image_name = image_name.replace(/\s/g, '_');
  48.  
  49. var link = document.createElement('a');
  50. link.setAttribute('href', image_url);
  51. link.setAttribute('download', image_name);
  52. link.text = 'Click to save';
  53. image_element = getImage();
  54. insertAfter(link, image_element);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement