// ==UserScript== // @name 微博图片原图地址批量复制 // @description 点击一条微博下方的“复制”按钮后,就可粘贴到贴吧或者迅雷批量下载,支持相册图片 // @include http://*.weibo.com/* // @version 2.1 // @author yechenyin // @namespace https://greasyfork.org/users/3586-yechenyin // @require https://code.jquery.com/jquery-1.11.2.min.js // @grant GM_setClipboard // @downloadURL none // ==/UserScript== add_text = false; //如果需要同时复制文字,请将false为true。否则将true改为false jQuery.fn.loaded = function(action) { var selector = this.selector; if ($(selector).length > 0) console.log($(selector).length + ' ' + selector + " is loaded at begin"); var check = setInterval(function () { if ($(selector).length > 0) { console.log($(selector).length + ' ' + selector + " is loaded"); clearInterval(check); action(); } }, 50); }; jQuery.fn.inserted = function(action) { var selector = this.selector; var last_length = 0; if ($(selector).length > 0) console.log($(selector).length + ' ' + selector + " is loaded at begin"); var react = function () { var current_length = document.querySelectorAll(selector).length; if (current_length !== last_length) { console.log((current_length - last_length) + ' ' + selector + " is inserted"); last_length = current_length; action(); } }; var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; if (MutationObserver) { var observer = new MutationObserver(react); observer.observe(document.body, {childList: true, subtree: true}); } else { setInterval(react, 100); } }; jQuery.fn.changed = function(action, forEachAddedNode, delay) { var selector = this.selector; var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; if (MutationObserver) { var callback = function (records) { setTimeout(function() { console.log(records.length + ' ' + records[0].target.className + " is mutated"); if (forEachAddedNode) { records.map(function (record) { console.log(record.target); console.log(record.addedNodes); for (var i = 0; i < record.addedNodes.length; i++) { action.call(record.addedNodes.item(i)); } }); } else action.call(document.querySelector(selector)); }, delay || 0); }; var observer = new MutationObserver(callback); if ($(selector).length > 0) { console.log($(selector).length + ' ' + selector + " is loaded"); setTimeout(function() { if (forEachAddedNode) $(selector).each(action); else action(); }, delay || 0); } else { var check = setInterval(function () { if ($(selector).length > 0) { console.log($(selector).length + ' ' + selector + " is inserted"); clearInterval(check); if (forEachAddedNode) $(selector).each(action); else action(); observer.observe(document.querySelector(selector), {childList: true}); } }, 100); } } }; if (!location.href.indexOf("http://www.weibo.com/")) { block = "unlock"; //add_copy_links(); //$(document).on('DOMNodeInserted', '#plc_main', add_copy_links); //$('.WB_feed[node-type="feed_list"]').changed(add_copy_links); $('.WB_row_line, .WB_praishare').inserted(add_copy_links); $('.gn_topmenulist li').loaded(function () { $('.gn_topmenulist li').eq(0).after($('
  • ').append($('', {text:'包含话题', id:'contain_topic_setting'}))); if (localStorage.also_contain_topic === undefined) localStorage.also_contain_topic = ''; if (!localStorage.also_contain_topic) $('#contain_topic_setting').css('color', '#ccc'); $('#contain_topic_setting').click(function () { if (localStorage.also_contain_topic) { localStorage.also_contain_topic = ''; $('#contain_topic_setting').css('color', '#ccc'); } else { localStorage.also_contain_topic = 'true'; $('#contain_topic_setting').css('color', '#333'); } }); $('.gn_topmenulist li').eq(0).after($('
  • ').append($('', {text:'复制文字', id:'copy_text_setting'}))); if (localStorage.also_copy_text === undefined) localStorage.also_copy_text = ''; if (!localStorage.also_copy_text) $('#copy_text_setting').css('color', '#ccc'); $('#copy_text_setting').click(function () { if (localStorage.also_copy_text) { localStorage.also_copy_text = ''; $('#copy_text_setting').css('color', '#ccc'); } else { localStorage.also_copy_text = 'true'; $('#copy_text_setting').css('color', '#333'); } }); }); } function add_copy_links() { var i, html; for (i=0; i<$('.WB_row_line').length; i++) { if ($('.WB_row_line').eq(i).find('.copy_images').length === 0) { html = $('.WB_row_line').eq(i).html().substr(0, $('.WB_row_line').eq(i).html().indexOf('
  • ')); html += '
  • 复制
  • '; html += $('.WB_row_line').eq(i).html().substr($('.WB_row_line').eq(i).html().indexOf('')); $('.WB_row_line').eq(i).html(html); } } $('.WB_row_line li').css({width:"20%"}); for (i=0; i<$('.WB_praishare').length; i++) { if ($('.WB_praishare').eq(i).find('.copy_images').length === 0) { html = $('.WB_praishare').eq(i).html(); html = '复制' + html; $('.WB_praishare').eq(i).html(html); } } $('.copy_images').click(function () { var images, contents, text='', urls = ''; if ($(this).parents('.WB_cardwrap').length > 0) { images = $(this).parents('.WB_cardwrap').find('.WB_media_a img, .photo_pic'); if ($(this).parents('.WB_cardwrap').find('.WB_feed_expand').length > 0) contents = $(this).parents('.WB_cardwrap').find('.WB_feed_expand .WB_text').contents(); else contents = $(this).parents('.WB_cardwrap').find('.WB_text, .describe').contents(); contents.each(function() { if ($(this).attr('action-type') === "feed_list_url") text += this.href+' '; else text += $(this).text(); }); } for (var i=0; i