Greasy Fork

淘宝集市店 图片获取脚本

try to take over the world!

当前为 2016-12-26 提交的版本,查看 最新版本

// ==UserScript==
// @name         淘宝集市店 图片获取脚本
// @namespace    https://item.taobao.com/
// @version      0.1
// @description  try to take over the world!
// @author       Richard He
// @match        https://item.taobao.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    //获取原图地址
    var count = document.getElementsByClassName('tb-pic').length;
    for(var i=1;i<count;i++)
    {
        var thumb = document.getElementsByClassName('tb-pic')[i].childNodes[1].childNodes[0];
        var arr = thumb.src.split(".");
        arr.splice(3,arr.length-3);
        var addr = arr.join(".")+".jpg";
    //生成按钮
        var buttonR = document.createElement('a');
        buttonR.href = addr;
        buttonR.target = '_blank';
        buttonR.innerHTML = i;
        buttonR.style.border='1px solid #FF8F1C';
        buttonR.style.display = 'inline-block';
        buttonR.style.width = '32px';
        buttonR.style.height = '32px';
        buttonR.style.lineHeight = '32px';
        buttonR.style.textAlign = 'center';
        buttonR.style.color = '#FF8F1C';
        buttonR.style.margin = '6px 2px';
       document.getElementsByClassName('tb-item-info-l')[0].appendChild(buttonR);
    }
    
    //分类图
    var down = document.createElement('dl');
    
    var catLis = document.getElementsByClassName('tb-img')[0].childNodes;
    for(var m=0;m<catLis.length;m++)
    {
        if(m%2 == 1)
        {
            
            var thumb1 = catLis[m].childNodes[1].style;
            var url = thumb1.backgroundImage.split("(")[1].split(")")[0];
            var arr1 = url.split(".");
            arr1.splice(-2,1);
            var addr1 = arr1.join(".");
            addr1 =addr1.substring(1,addr1.length-1);

            
            //生成按钮
            var buttonL = document.createElement('a');
            buttonL.href = addr1;
            buttonL.target = '_blank';
            if(catLis[m].style.display === "")
            buttonL.innerHTML = '打开第'+ Math.ceil(m/2) +'张分类图';
            else
            buttonL.innerHTML = '打开隐藏分类图';
            buttonL.style.position = 'absolute';
            buttonL.style.right = '200px';
            buttonL.style.top = 300+Math.ceil(m/2)*40+"px";
            buttonL.style.border='1px solid #000';
            buttonL.style.padding = '6px 6px 6px 6px';
            buttonL.style.color = '#000';
            document.body.appendChild(buttonL);
        }
        else
        {
        }
    }
})();