// ==UserScript== // @name display the image of tumblr in HD revolution and copy http url of images in one post or open images // @description 直接显示tumblr的图片为高清版,并可以复制一个博文的所有图片地址或者打开所有图片 // @version 1.2 // @include http://*.tumblr.com/* // @include https://*.tumblr.com/* // @author yechenyin // @namespace https://greasyfork.org/users/3586-yechenyin // @require https://code.jquery.com/jquery-1.11.2.min.js // @grant GM_setClipboard // @grant GM_openInTab // @downloadURL none // ==/UserScript== $(document).on('click', '.copy_images', copy_images); $(document).on('click', '.open_images', open_images); $(".post_wrapper").each(function() { console.log($(this).find(".post_media img").length); if ($(this).find(".post_media img").length > 0) { $(this).find(".photoset_photo img").each(function() { if (this.src != this.parentNode.href) this.src = this.parentNode.href; }); $(this).find(".post_media_photo").each(function() { if ($(this).parent().attr("data-big-photo") && this.src != $(this).parent().attr("data-big-photo")) { this.src = $(this).parent().attr("data-big-photo"); console.log(this.src); } }); $(this).find(".post_notes_label").after($("", {text:"copy images", class:"copy_images", css:{display:"inline", cursor:"pointer"}})); if ($(this).find(".note_link_current").html() !== '') $(this).find(".note_link_current").css({display:"inline", marginRight:"12px"}); if ($(this).find(".copy_images").length > 0) console.log('added copy images'); $(this).find(".post_notes_label").next().after($("", {text:"open images", class:"open_images", css:{marginLeft:"12px", cursor:"pointer"}})); } }); if (location.href.match(/(\.jpg|\.gif|\.png)#/)) { var left_images = JSON.parse(decodeURIComponent(location.hash.replace('#', ''))); for (var i = 0; i < left_images.length; i++) { $('img').last().after($('', {src:left_images[i]})); } } $(document).on('DOMNodeInserted', '.post_container', function(e) { if ($(e.target).hasClass('post_container')) { //console.log($(this).html()); //setTimeout(function(){console.log($(this).find(".post_notes_label").length)}, 3000); if ($(this).find(".post_media img").length > 0) { $(this).find(".photoset_photo img").each(function() { if (this.src != this.parentNode.href) this.src = this.parentNode.href; }); $(this).find(".post_media_photo").each(function() { if ($(this).parent().attr("data-big-photo") && this.src != $(this).parent().attr("data-big-photo")) { this.src = $(this).parent().attr("data-big-photo"); console.log(this.src); } }); $(this).find(".post_notes_label").eq(0).after($("", {text:"copy images", class:"copy_images", css:{display:"inline", cursor:"pointer"}})); if ($(this).find(".note_link_current").html() !== '') $(this).find(".note_link_current").css({display:"inline", marginRight:"12px"}); if ($(this).find(".copy_images").length > 0) console.log('added copy images'); $(this).find(".post_notes_label").next().after($("", {text:"open images", class:"open_images", css:{marginLeft:"12px", cursor:"pointer"}})); } } }); function copy_images() { images=''; //var index = $(".copy_images").index(this); //console.log('index:' +index); var images_window = GM_openInTab('', false); var image = 'img").get(0).src + '">'; console.log(image); images_window.document.write(image); $(this).parents('.post_wrapper').find("a>img").each(function() { images += this.src.replace(/https:\/\//g, "http://") + '\n'; }); if (typeof GM_setClipboard === "undefined") console.log('images:' +images); else GM_setClipboard(images); } function open_images() { var images=[]; for (var i=1; i<$(this).parents('.post_wrapper').find("a>img").length; i++) { images.push($(this).parents('.post_wrapper').find("a>img").get(i).src.replace(/https:\/\//g, "http://")); } var image = $(this).parents('.post_wrapper').find("a>img").get(0).src.replace(/https:\/\//g, "http://"); url = image + '#' + encodeURIComponent(JSON.stringify(images)); console.log(url); GM_openInTab(url, false); }