Greasy Fork is available in English.

微博图片原图地址批量复制

点击一条微博下方的“复制”按钮后,就可粘贴到贴吧或者迅雷批量下载,支持相册图片

Устаревшая версия за 26.05.2016. Перейдите к последней версии.

  1. // ==UserScript==
  2. // @name 微博图片原图地址批量复制
  3. // @description 点击一条微博下方的“复制”按钮后,就可粘贴到贴吧或者迅雷批量下载,支持相册图片
  4. // @include http://*.weibo.com/*
  5. // @include http://weibo.com/*
  6. // @version 2.5
  7. // @author yechenyin
  8. // @namespace https://greasyfork.org/users/3586-yechenyin
  9. // @require https://code.jquery.com/jquery-1.11.2.min.js
  10. // @grant GM_setClipboard
  11. // @run-at document-body
  12. // ==/UserScript==
  13.  
  14. jQuery.fn.inserted = function(action, observe_for_once) {
  15. var selector = this.selector;
  16. if ($(selector).length > 0) {
  17. console.log($(selector).length + ' ' + selector + " is loaded at begin");
  18. action();
  19. }
  20. var reaction = function(records) {
  21. records.map(function(record) {
  22. if(record.target !== document.body && $(record.target).find(selector).length) {
  23. console.log($(record.target).selector + ' which contains ' + selector + ' is loaded');
  24. action();
  25. if (observe_for_once)
  26. observer.disconnect();
  27. }
  28. });
  29. };
  30.  
  31. var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  32. if (MutationObserver) {
  33. var observer = new MutationObserver(reaction);
  34. observer.observe(document.body, {childList: true, subtree: true});
  35. } else {
  36. //setInterval(reaction, 100);
  37. }
  38. };
  39.  
  40. jQuery.fn.changed = function(action, forEachAddedNode, delay) {
  41. var selector = this.selector;
  42. var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  43. if (MutationObserver) {
  44. var callback = function (records) {
  45. setTimeout(function() {
  46. console.log(records.length + ' ' + records[0].target.className + " is mutated");
  47. if (forEachAddedNode) {
  48. records.map(function (record) {
  49. console.log(record.target);
  50. console.log(record.addedNodes);
  51. for (var i = 0; i < record.addedNodes.length; i++) {
  52. action.call(record.addedNodes.item(i));
  53. }
  54. });
  55. } else
  56. action.call(document.querySelector(selector));
  57.  
  58. }, delay || 0);
  59.  
  60. };
  61. var observer = new MutationObserver(callback);
  62.  
  63. if ($(selector).length > 0) {
  64. console.log($(selector).length + ' ' + selector + " is loaded");
  65. setTimeout(function() {
  66. if (forEachAddedNode)
  67. $(selector).each(action);
  68. else
  69. action();
  70. }, delay || 0);
  71. } else {
  72. var check = setInterval(function () {
  73. if ($(selector).length > 0) {
  74. console.log($(selector).length + ' ' + selector + " is inserted");
  75. clearInterval(check);
  76. if (forEachAddedNode)
  77. $(selector).each(action);
  78. else
  79. action();
  80. observer.observe(document.querySelector(selector), {childList: true});
  81. }
  82. }, 100);
  83. }
  84.  
  85. }
  86. };
  87.  
  88. if (location.href.indexOf("weibo.com/") > 0) {
  89. block = "unlock";
  90. //add_copy_links();
  91. //$(document).on('DOMNodeInserted', '#plc_main', add_copy_links);
  92. //$('.WB_feed[node-type="feed_list"]').changed(add_copy_links);
  93. $('.WB_row_line, .WB_praishare').inserted(add_copy_links);
  94. $('.gn_topmenulist li').inserted(function () {
  95. $('.gn_topmenulist li').eq(0).after($('<li>').append($('<a>', {text:'包含话题', id:'contain_topic_setting'})));
  96. if (localStorage.also_contain_topic === undefined)
  97. localStorage.also_contain_topic = '';
  98. if (!localStorage.also_contain_topic)
  99. $('#contain_topic_setting').css('color', '#ccc');
  100. $('#contain_topic_setting').click(function () {
  101. if (localStorage.also_contain_topic) {
  102. localStorage.also_contain_topic = '';
  103. $('#contain_topic_setting').css('color', '#ccc');
  104. } else {
  105. localStorage.also_contain_topic = 'true';
  106. $('#contain_topic_setting').css('color', '#333');
  107. }
  108. });
  109.  
  110. $('.gn_topmenulist li').eq(0).after($('<li>').append($('<a>', {text:'复制文字', id:'copy_text_setting'})));
  111. if (localStorage.also_copy_text === undefined)
  112. localStorage.also_copy_text = '';
  113. if (!localStorage.also_copy_text)
  114. $('#copy_text_setting').css('color', '#ccc');
  115. $('#copy_text_setting').click(function () {
  116. if (localStorage.also_copy_text) {
  117. localStorage.also_copy_text = '';
  118. $('#copy_text_setting').css('color', '#ccc');
  119. } else {
  120. localStorage.also_copy_text = 'true';
  121. $('#copy_text_setting').css('color', '#333');
  122. }
  123. });
  124. }, true);
  125.  
  126.  
  127. }
  128.  
  129. function add_copy_links() {
  130. var i, html;
  131. for (i=0; i<$('.WB_row_line').length; i++) {
  132. if ($('.WB_row_line').eq(i).find('.copy_images').length === 0) {
  133. html = $('.WB_row_line').eq(i).html().substr(0, $('.WB_row_line').eq(i).html().indexOf('</li>'));
  134. html += '<li class="copy_images"><a class="S_txt2"><span class="S_line1 line">复制</span></a></li>';
  135. html += $('.WB_row_line').eq(i).html().substr($('.WB_row_line').eq(i).html().indexOf('</li>'));
  136. $('.WB_row_line').eq(i).html(html);
  137. }
  138. }
  139. $('.WB_row_line li').css({width:"20%"});
  140.  
  141. for (i=0; i<$('.WB_praishare').length; i++) {
  142. if ($('.WB_praishare').eq(i).find('.copy_images').length === 0) {
  143. html = $('.WB_praishare').eq(i).html();
  144. html = '<a class="S_txt1"><span class="copy_images">复制</span></a><em class="W_vline S_line1"></em>' + html;
  145. $('.WB_praishare').eq(i).html(html);
  146. }
  147. }
  148.  
  149. $('.copy_images').click(function () {
  150. var images, contents, text='', urls = '';
  151. if ($(this).parents('.WB_cardwrap').length > 0) {
  152. if ($(this).parents('.WB_cardwrap').find('.WB_feed_expand').length > 0)
  153. contents = $(this).parents('.WB_cardwrap').find('.WB_feed_expand .WB_text').contents();
  154. else
  155. contents = $(this).parents('.WB_cardwrap').find('.WB_text, .describe').contents();
  156. contents.each(function() {
  157. if ($(this).attr('action-type') === "feed_list_url")
  158. text += this.href+' ';
  159. else
  160. text += $(this).text();
  161. });
  162. text = text.replace(/^\s+/, '');
  163. if (localStorage.also_contain_topic)
  164. text = text.replace(/#(.*?)#/g, '$1');
  165. else
  166. text = text.replace(/#(.*?)#/g, '');
  167. if (text === '分享圖片' || text === '分享图片')
  168. text = '';
  169. console.log(text);
  170.  
  171. images = $(this).parents('.WB_cardwrap').find('.WB_media_a img, .photo_pic');
  172. for (var i=0; i<images.length; i++) {
  173. urls += images[i].src + '\n';
  174. }
  175. console.log(images);
  176. urls = urls.replace(/\.cn\/\w+?\//g, '.cn/large/');
  177. console.log(urls);
  178.  
  179. if (localStorage.also_copy_text)
  180. GM_setClipboard(urls + text);
  181. else
  182. GM_setClipboard(urls);
  183. $(this).find('span').css('color', '#ccc');
  184. $(this).hover(function() {
  185. var that = this;
  186. setTimeout(function() {
  187. $(that).find('span').attr('style', '');
  188. }, 300);
  189. });
  190. return false;
  191. }
  192. });
  193. }