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

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

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

  1. // ==UserScript==
  2. // @name 微博图片原图地址批量复制
  3. // @description 点击一条微博下方的“复制”按钮后,就可粘贴到贴吧或者迅雷批量下载,支持相册图片
  4. // @include http://*.weibo.com/*
  5. // @include http://weibo.com/*
  6. // @version 2.4
  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, true);
  94.  
  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.  
  125. }
  126.  
  127. function add_copy_links() {
  128. var i, html;
  129. for (i=0; i<$('.WB_row_line').length; i++) {
  130. if ($('.WB_row_line').eq(i).find('.copy_images').length === 0) {
  131. html = $('.WB_row_line').eq(i).html().substr(0, $('.WB_row_line').eq(i).html().indexOf('</li>'));
  132. html += '<li class="copy_images"><a class="S_txt2"><span class="S_line1 line">复制</span></a></li>';
  133. html += $('.WB_row_line').eq(i).html().substr($('.WB_row_line').eq(i).html().indexOf('</li>'));
  134. $('.WB_row_line').eq(i).html(html);
  135. }
  136. }
  137. $('.WB_row_line li').css({width:"20%"});
  138.  
  139. for (i=0; i<$('.WB_praishare').length; i++) {
  140. if ($('.WB_praishare').eq(i).find('.copy_images').length === 0) {
  141. html = $('.WB_praishare').eq(i).html();
  142. html = '<a class="S_txt1"><span class="copy_images">复制</span></a><em class="W_vline S_line1"></em>' + html;
  143. $('.WB_praishare').eq(i).html(html);
  144. }
  145. }
  146.  
  147. $('.copy_images').click(function () {
  148. var images, contents, text='', urls = '';
  149. if ($(this).parents('.WB_cardwrap').length > 0) {
  150. if ($(this).parents('.WB_cardwrap').find('.WB_feed_expand').length > 0)
  151. contents = $(this).parents('.WB_cardwrap').find('.WB_feed_expand .WB_text').contents();
  152. else
  153. contents = $(this).parents('.WB_cardwrap').find('.WB_text, .describe').contents();
  154. contents.each(function() {
  155. if ($(this).attr('action-type') === "feed_list_url")
  156. text += this.href+' ';
  157. else
  158. text += $(this).text();
  159. });
  160. text = text.replace(/^\s+/, '');
  161. if (localStorage.also_contain_topic)
  162. text = text.replace(/#(.*?)#/g, '$1');
  163. else
  164. text = text.replace(/#(.*?)#/g, '');
  165. if (text === '分享圖片' || text === '分享图片')
  166. text = '';
  167. console.log(text);
  168.  
  169. images = $(this).parents('.WB_cardwrap').find('.WB_media_a img, .photo_pic');
  170. for (var i=0; i<images.length; i++) {
  171. urls += images[i].src + '\n';
  172. }
  173. console.log(images);
  174. urls = urls.replace(/\.cn\/\w+?\//g, '.cn/large/');
  175. console.log(urls);
  176.  
  177. if (localStorage.also_copy_text)
  178. GM_setClipboard(urls + text);
  179. else
  180. GM_setClipboard(urls);
  181. return false;
  182. }
  183. });
  184. }