Worldcosplay download

Download photo(s) on WorldCosplay.

安装此脚本
作者推荐脚本

您可能也喜欢Image viewer

安装此脚本
  1. // ==UserScript==
  2. // @name Worldcosplay download
  3. // @name:vi Worldcosplay download
  4. // @namespace http://devs.forumvi.com/
  5. // @description Download photo(s) on WorldCosplay.
  6. // @description:vi Tải ảnh từ WorldCosplay.
  7. // @version 3.1.6
  8. // @icon http://i.imgur.com/gJLjIzb.png
  9. // @author Zzbaivong
  10. // @oujs:author baivong
  11. // @license MIT; https://baivong.mit-license.org/license.txt
  12. // @match https://worldcosplay.net/*/photos*
  13. // @match https://worldcosplay.net/*/favorites*
  14. // @match https://worldcosplay.net/photo/*
  15. // @match https://worldcosplay.net/tag/*
  16. // @match https://worldcosplay.net/search/photos?*
  17. // @match https://worldcosplay.net/collections/*
  18. // @match https://worldcosplay.net/character/*
  19. // @match https://worldcosplay.net/title/*
  20. // @match https://worldcosplay.net/photos
  21. // @match https://worldcosplay.net/popular
  22. // @match https://worldcosplay.net/ranking/good*
  23. // @match https://worldcosplay.net/member/*/characters/*
  24. // @match https://worldcosplay.net/*/photo/*
  25. // @match https://worldcosplay.net/*/tag/*
  26. // @match https://worldcosplay.net/*/search/photos?*
  27. // @match https://worldcosplay.net/*/collections/*
  28. // @match https://worldcosplay.net/*/character/*
  29. // @match https://worldcosplay.net/*/title/*
  30. // @match https://worldcosplay.net/*/photos
  31. // @match https://worldcosplay.net/*/popular
  32. // @match https://worldcosplay.net/*/ranking/good*
  33. // @match https://worldcosplay.net/*/member/*/characters/*
  34. // @require https://code.jquery.com/jquery-3.3.1.slim.min.js
  35. // @require https://unpkg.com/file-saver@2.0.1/dist/FileSaver.min.js
  36. // @require https://greasyfork.org/scripts/6250-waitforkeyelements/code/waitForKeyElements.js?version=23756
  37. // @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js?v=a834d46
  38. // @noframes
  39. // @connect self
  40. // @connect sakurastorage.jp
  41. // @supportURL https://github.com/lelinhtinh/Userscript/issues
  42. // @run-at document-idle
  43. // @grant GM.xmlHttpRequest
  44. // @grant GM_xmlhttpRequest
  45. // @grant GM.openInTab
  46. // @grant GM_openInTab
  47. // ==/UserScript==
  48.  
  49. /* global waitForKeyElements */
  50. (function($, window) {
  51. 'use strict';
  52.  
  53. window.URL = window.URL || window.webkitURL;
  54.  
  55. function downloadPhoto(el, url) {
  56. var photoName = url.replace(/.*\//g, ''),
  57. $icon = $(el).find('.fa');
  58.  
  59. $icon.addClass('fa-spinner fa-spin');
  60.  
  61. GM.xmlHttpRequest({
  62. method: 'GET',
  63. url: url,
  64. responseType: 'blob',
  65. onload: function(response) {
  66. var blob = response.response;
  67.  
  68. $(el)
  69. .attr({
  70. href: window.URL.createObjectURL(blob),
  71. download: photoName,
  72. })
  73. .off('click');
  74. $icon.removeClass('fa-spinner fa-spin').addClass('fa-download');
  75.  
  76. saveAs(blob, photoName);
  77. },
  78. onerror: function(err) {
  79. $icon.removeClass('fa-spinner fa-spin').addClass('fa-times');
  80. console.error(err);
  81. },
  82. });
  83. }
  84.  
  85. function getImage3000(url) {
  86. var hasMax = url.match(/\/max-(\d+)\//);
  87. if (hasMax) return url.replace(/-[\dx]+\./, '-' + hasMax[1] + '.');
  88.  
  89. return url.replace(/-[\dx]+\./, '-3000.');
  90. }
  91.  
  92. if (/^(\/[a-z-]+)?\/photo\/\d+$/.test(location.pathname)) {
  93. var $btn = $('<a>', {
  94. href: '#download',
  95. class: 'download-this-photo',
  96. title: 'Click to download this image\nRight Click to open in new tab',
  97. html:
  98. '<div class="side_buttons" style="right: 250px;"><div class="like-this-photo button fave fa fa-download"><div class="effect-ripple"></div></div></div>',
  99. }),
  100. img = $('#photoContainer')
  101. .find('.img')
  102. .attr('src');
  103. $btn
  104. .on('click', function(e) {
  105. e.preventDefault();
  106. e.stopPropagation();
  107. downloadPhoto(this, getImage3000(img));
  108. })
  109. .on('contextmenu', function(e) {
  110. e.preventDefault();
  111. e.stopPropagation();
  112. GM.openInTab(getImage3000(img));
  113. });
  114. $btn.insertAfter('.side_buttons');
  115. } else {
  116. var addBtn = function() {
  117. $('.preview')
  118. .not('.added-download-btn')
  119. .each(function() {
  120. var $this = $(this),
  121. $btn = $('<a>', {
  122. href: '#download',
  123. class: 'download-this-photo',
  124. title: 'Click to download this image\nRight Click to open in new tab',
  125. html:
  126. '<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>',
  127. });
  128. $btn
  129. .on('click', function(e) {
  130. e.preventDefault();
  131. e.stopPropagation();
  132. downloadPhoto(
  133. this,
  134. getImage3000(
  135. $this
  136. .find('.photo_img')
  137. .css('backgroundImage')
  138. .slice(5, -2)
  139. )
  140. );
  141. })
  142. .on('contextmenu', function(e) {
  143. e.preventDefault();
  144. e.stopPropagation();
  145. GM.openInTab(
  146. getImage3000(
  147. $this
  148. .find('.photo_img')
  149. .css('backgroundImage')
  150. .slice(5, -2)
  151. )
  152. );
  153. });
  154. $this.find('.options').append($btn);
  155. $this.addClass('added-download-btn');
  156. });
  157. };
  158. addBtn();
  159.  
  160. waitForKeyElements('.preview', addBtn);
  161. }
  162. })(jQuery, window);