Worldcosplay download

Download photo(s) on worldcosplay.net

当前为 2016-05-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @id worldcosplay-download@devs.forumvi.com
  3. // @name Worldcosplay download
  4. // @namespace http://devs.forumvi.com/
  5. // @description Download photo(s) on worldcosplay.net
  6. // @version 1.1.8
  7. // @icon http://i.imgur.com/gJLjIzb.png
  8. // @author Zzbaivong
  9. // @license MIT
  10. // @match http://worldcosplay.net/*/photos*
  11. // @match http://worldcosplay.net/*/favorites*
  12. // @match http://worldcosplay.net/photo/*
  13. // @match http://worldcosplay.net/tag/*
  14. // @match http://worldcosplay.net/search/photos?*
  15. // @match http://worldcosplay.net/character/*
  16. // @match http://worldcosplay.net/title/*
  17. // @match http://worldcosplay.net/photos
  18. // @match http://worldcosplay.net/popular
  19. // @match http://worldcosplay.net/ranking/good*
  20. // @match http://worldcosplay.net/*/photo/*
  21. // @match http://worldcosplay.net/*/tag/*
  22. // @match http://worldcosplay.net/*/search/photos?*
  23. // @match http://worldcosplay.net/*/character/*
  24. // @match http://worldcosplay.net/*/title/*
  25. // @match http://worldcosplay.net/*/photos
  26. // @match http://worldcosplay.net/*/popular
  27. // @match http://worldcosplay.net/*/ranking/good*
  28. // @require https://code.jquery.com/jquery-2.2.4.min.js
  29. // @require https://greasyfork.org/scripts/18532-filesaver/code/FileSaver.js?version=128198
  30. // @require https://greasyfork.org/scripts/5392-waitforkeyelements/code/WaitForKeyElements.js?version=115012
  31. // @noframes
  32. // @connect worldcosplay.net
  33. // @supportURL https://github.com/baivong/Userscript/issues
  34. // @run-at document-idle
  35. // @grant GM_xmlhttpRequest
  36. // ==/UserScript==
  37.  
  38. (function($, window, document, undefined) {
  39. 'use strict';
  40.  
  41. window.URL = window.URL || window.webkitURL;
  42.  
  43. function downloadPhoto(el, url) {
  44. var photoName = url.replace(/.*\//g, '');
  45. GM_xmlhttpRequest({
  46. method: 'GET',
  47. url: url,
  48. responseType: 'blob',
  49. onload: function(response) {
  50. var blob = response.response;
  51. $(el).attr({
  52. href: window.URL.createObjectURL(blob),
  53. download: photoName
  54. }).removeAttr('onclick');
  55. saveAs(blob, photoName);
  56. },
  57. onerror: function(err) {
  58. console.error(err);
  59. }
  60. });
  61. }
  62.  
  63. if (/^(\/[a-z\-]+)?\/photo\/\d+$/.test(location.pathname)) {
  64.  
  65. var $btn = $('<a>', {
  66. href: '#download',
  67. 'class': 'download-this-photo',
  68. html: '<div class="side_buttons" style="right: 220px;"><div class="like-this-photo button fave fa fa-download"><div class="effect-ripple"></div></div></div>'
  69. });
  70. $btn.on('click', function(e) {
  71. e.preventDefault();
  72. e.stopPropagation();
  73. downloadPhoto(this, $('#photoContainer').find('.img').attr('src'));
  74. });
  75. $btn.insertAfter('.side_buttons');
  76.  
  77. } else {
  78.  
  79. var addBtn = function() {
  80. $('.preview').not('.added-download-btn').each(function() {
  81. var $this = $(this),
  82. $btn = $('<a>', {
  83. href: '#download',
  84. 'class': 'download-this-photo',
  85. html: '<div class="item likes" style="top: 50px;"><span class="like-this-photo"><i class="fa fa-download"></i><span class="effect-ripple"></span></span></div>'
  86. });
  87. $btn.on('click', function(e) {
  88. e.preventDefault();
  89. e.stopPropagation();
  90. downloadPhoto(this, $this.find('.photo_img').css('backgroundImage').slice(5, -2).replace('sq300/', ''));
  91. });
  92. $this.find('.options').append($btn);
  93. $this.addClass('added-download-btn');
  94. });
  95. };
  96. addBtn();
  97.  
  98. waitForKeyElements('.preview', addBtn);
  99.  
  100. }
  101.  
  102. })(jQuery, window, document);