Greasy Fork is available in English.

花瓣网下载

花瓣网(huaban.com)用户画板图片批量下载到本地

您查看的为 2019-02-15 07:01:34 UTC 提交的版本。查看 最新版本

// ==UserScript==
// @name         花瓣网下载
// @namespace    https://www.saintic.com/
// @version      0.7.0
// @description  花瓣网(huaban.com)用户画板图片批量下载到本地
// @author       staugur
// @match        http*://huaban.com/*
// @match        http*://*.meiwu.co/*
// @require      https://cdn.bootcss.com/FileSaver.js/1.3.2/FileSaver.min.js
// @grant        GM_setClipboard
// @grant        GM_info
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAAA+CAYAAACIll2bAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAABlLSURBVHhe3VsJXFTV97/vvjdvFgaGZdh3EFAUkE1xQyVNUBEl19DUzC3DUHMtoqzUXELTXCtMNDW00jDNnUxNxVJEya3SXFBRQUFg3sy7/3PHx/xmAP37S7A+v+/n8/2I995z373nnXPuOe+9Qc8ChBAMVIgTJ3qKvXrF6hMSXhSfj08VuyXMEOPjZ+qTkzP0gwZNFEeOHCJOn96Z5Ob6wXgNkJemeCYoQMjvppV6i+G11+ZITY0D2BhDMjLUYljY84bAoFl6H/89gqt7saB1Ngh2jkTQaIlgbUcEK1siqDREUMPftM3Rleg9fIgQ0FSvj4y+oe+W8LMwZEiWfty4VHHp0hixrMwB5pZJl2kwlCBkc5eVvXOfk9/XuXrcFzMyIqSuhoXYtauV6OzcX6912qSzsSurttKQarkVqeaUf48yoMqGVIPidP6BRBfd+rbQJ/lHcfTYuXADepP8fC9QmIreEGkJTwzjTXR11ep4fvoDTl5cKVMRnZVNmRgSkvB35nscmCqeDxRU6oVVClVJpUJNKmFjjUZeRSo1DqTKy5dUh4RV6+KeK9IPGLhJP2LE28KUKcnVq1c3lyyNKk4GZM3Iiykprnpvv4GCvcMGWG9FzZw6heoscXNrKe2pQcDclckiHnCyTRW8QqiAC1HeA94CXpMpyFVgMf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x8GeM95Sybd6+BfxTXaKAx6QeEnD7CeMw7PL8v1d6+ZKSnp/5Fb2+SRRO2+hREKZeTKkgLrnfsePK3hIS4fbWO7hrQmwAxJhaUkg3uVFXKsvOhrd6A/a8HfSSyFiHvj1g2bhnGw6Zi/NZmhrnz2K8v6Ce/Pj6iPizskqFVq21QUqwwhIUtFJo0WaV3dv5BUKlu6SDo38b4zF8IdZIu9b8DyIyDFzLM8Sv1KedRBMuj/9KPykHu91NQp1HlS1P+74G+qYBKe/ByKCF+xFhHlUVzF/pDFWpdlPTvciB9lgPB91Y+w6zfiVAvCMr/u4qpD89BUTkYDGsK5DDzwAVXMMwHWQzzHpTdkz5BaAB9W/q4QP1sgdD/AX2Kxwp17Bl5AAAAAElFTkSuQmCC
// @license      MIT
// @date         2018-05-25
// @modified     2019-02-15
// @github       https://github.com/staugur/grab_huaban_board/blob/master/grab_huaban_board.js
// @supportURL   https://blog.saintic.com/blog/256.html
// ==/UserScript==

(function() {
    'use strict';
    //字符串是否包含子串
    function isContains(str, substr) {
        //str是否包含substr
        return str.indexOf(substr) >= 0;
    }
    //数组是否包含某元素
    function arrayContains(arr, obj) {
        var i = arr.length;
        while (i--) {
            if (arr[i] === obj) {
                return true;
            }
        }
        return false;
    }
    //判断页面中id是否存在
    function hasId(id) {
        //有此id返回true,否则返回false
        var element = document.getElementById(id);
        if (element) {
            return true
        } else {
            return false
        }
    }
    //获取url查询参数
    function getUrlQuery(key, acq) {
        /*
            获取URL中?之后的查询参数,不包含锚部分,比如url为http://passport.saintic.com/user/message/?status=1&Action=getCount
            若无查询的key,则返回整个查询参数对象,即返回{status: "1", Action: "getCount"};
            若有查询的key,则返回对象值,返回值可以指定默认值acq:如key=status, 返回1;key=test返回acq
        */
        var str = location.search;
        var obj = {};
        if (str) {
            str = str.substring(1, str.length);
            // 以&分隔字符串,获得类似name=xiaoli这样的元素数组
            var arr = str.split("&");
            //var obj = new Object();
            // 将每一个数组元素以=分隔并赋给obj对象
            for (var i = 0; i < arr.length; i++) {
                var tmp_arr = arr[i].split("=");
                obj[decodeURIComponent(tmp_arr[0])] = decodeURIComponent(tmp_arr[1]);
            }
        }
        return key ? obj[key] || acq : obj;
    }
    //保存图片
    function saveImage(imgUrl, imgName) {
        /*
            imgUrl: 图片地址; imgName: 保存的文件名
            注意,使用此函数请先在用户脚本中:@require https://cdn.bootcss.com/FileSaver.js/1.3.2/FileSaver.min.js
        */
        try {
            const xhr = new XMLHttpRequest();
            xhr.open('GET', imgUrl, true);
            xhr.responseType = 'blob';
            xhr.onload = () => {
                if (xhr.status === 200) {
                    //将图片文件用浏览器中下载
                    saveAs(xhr.response, imgName);
                }
            };
            xhr.send();
        } catch (e) {
            console.error(e);
        }
    }
    //计算百分比
    function calculatePercentage(num, total) {
        //小数点后两位百分比
        return (Math.round(num / total * 10000) / 100.00 + "%");
    }
    //加载css文件
    function addCSS(href) {
        var link = document.createElement('link');
        link.type = 'text/css';
        link.rel = 'stylesheet';
        link.href = href;
        document.getElementsByTagName("head")[0].appendChild(link);
    }
    //加载js文件
    function addJS(src, cb) {
        var script = document.createElement("script");
        script.type = "text/javascript";
        script.src = src;
        document.getElementsByTagName('head')[0].appendChild(script);
        script.onload = typeof cb === "function" ? cb : function() {};
    }
    //获取可使用域名
    function getEffectiveHost() {
        var host = window.location.host;
        if (!host) {
            host = document.domain;
        }
        if (!host) {
            host = "huaban.com";
        }
        if (isContains(host, "meiwu.co")) {
            host = "login.meiwu.co";
        } else {
            host = "huaban.com";
        }
        return host;
    }
    //时间戳转化为日期格式
    function formatUnixtimestamp(unixtimestamp) {
        var unixtimestamp = new Date(unixtimestamp * 1000);
        var year = 1900 + unixtimestamp.getYear();
        var month = "0" + (unixtimestamp.getMonth() + 1);
        var date = "0" + unixtimestamp.getDate();
        var hour = "0" + unixtimestamp.getHours();
        var minute = "0" + unixtimestamp.getMinutes();
        var second = "0" + unixtimestamp.getSeconds();
        return year + "-" + month.substring(month.length - 2, month.length) + "-" + date.substring(date.length - 2, date.length) +
            " " + hour.substring(hour.length - 2, hour.length) + ":" +
            minute.substring(minute.length - 2, minute.length);
    }
    //封装localStorage
    class StorageMix {

        constructor(key) {
            this.key = key;
            this.obj = window.localStorage;
            if (!this.obj) {
                console.error("浏览不支持localStorage");
                return false;
            }
        }

        //设置或跟新本地存储数据
        set(data) {
            if (data) {
                return this.obj.setItem(this.key, JSON.stringify(data));
            }
        }

        //获取本地存储数据
        get() {
            var data = null;
            try {
                data = JSON.parse(this.obj.getItem(this.key));
            } catch (e) {
                console.error(e);
            } finally {
                return data;
            }
        }

        clear() {
            //清除对象
            return this.obj.removeItem(this.key);
        }
    }
    //由于@require方式引入jquery时layer使用异常,故引用cdn中jquery v1.10.1;加载完成后引用又拍云中layer v3.1.1
    addJS("https://cdn.bootcss.com/jquery/1.10.1/jquery.min.js", function() {
        addJS("https://static.saintic.com/cdn/layer/3.1.1/layer.js");
    });
    //加载优化
    var loadingLayer = null;
    /**
     * 设置接收信息
     * @param type 参数: mobile|email
     */
    function setupReceiveTo(type) {
        var es = new StorageMix("grab_huaban_board_remind_email");
        var ms = new StorageMix("grab_huaban_board_remind_mobile");
        if (type === 'email') {
            var title = '输入邮箱待下载完成后邮件提醒';
            var isEmail = /^[\w.\-]+@(?:[a-z0-9]+(?:-[a-z0-9]+)*\.)+[a-z]{2,3}$/i;
            var successCall = function(value, index, elem) {
                if (!isEmail.test(value)) {
                    layer.msg('请输入正确的邮箱地址');
                    return;
                }
                layer.close(index);
                es.set(value);
                layer.msg('邮箱:' + value + ',设置成功!', {
                    icon: 1
                });
            }
            layer.prompt({
                title: title,
                value: es.get() || "",
                icon: 1,
                shade: 0
            }, successCall);
        } else if (type === 'mobile') {
            var title = '输入手机号待下载完成后短信提醒';
            var isMobile = /^1\d{10}$/i;
            var successCall = function(value, index, elem) {
                if (!isMobile.test(value)) {
                    layer.msg('请输入正确的手机号');
                    return;
                }
                layer.close(index);
                ms.set(value);
                layer.msg('手机号:' + value + ',设置成功!', {
                    icon: 1
                });
            }
            layer.prompt({
                title: title,
                value: ms.get() || "",
                icon: 1,
                shade: 0
            }, successCall);
        } else {
            layer.msg('暂不支持此接收方式!');
            return;
        }
    }
    /**
     * 读取接收信息值
     * @param type 参数: mobile|email
     */
    function getReceiveBy(type) {
        var str = '',
            es = new StorageMix("grab_huaban_board_remind_email"),
            ms = new StorageMix("grab_huaban_board_remind_mobile");
        if (type === 'email') {
            str = es.get();
        } else if (type === 'mobile') {
            str = ms.get();
        }
        return str;
    }
    /*
        下载用户画板接口
    */
    //交互确定画板下载方式
    function interactiveBoard(board_id, pins, pin_number, user_id) {
        /*
            board_id int: 画板id
            pins list: 包含所有程序加载到的图片数据
            pin_number int: 这个画板总共有多少图片
            user_id str: 这个画板所属的用户
        */
        layer.close(loadingLayer);
        var downloadMethod = 0,
            msg = [
                '<div style="padding: 20px;"><b>当前画板共' + pin_number + '张图片,抓取了' + pins.length + '张,抓取率:' + calculatePercentage(pins.length, pin_number) + '!</b><small>提示: 只有登录后才可以抓取几乎所有图片哦。</small><br/>',
                '<b>请选择以下三种下载方式:</b><br/>',
                '1. <i>文本</i>: <br/>&nbsp;&nbsp;&nbsp;&nbsp;即所有图片地址按行显示,提供复制,粘贴至迅雷、QQ旋风等下载工具批量下载即可,推荐使用此方法。<br/>',
                '2. <i>本地</i>: <br/>&nbsp;&nbsp;&nbsp;&nbsp;即所有图片直接保存到硬盘中,由于是批量下载,所以浏览器设置中请关闭"下载前询问每个文件的保存位置",并且允许浏览器下载多个文件的授权申请,以保证可以自动批量保存,否则每次保存时会弹出询问,对您造成困扰。<br/>',
                '3. <i>远程</i>: <br/>&nbsp;&nbsp;&nbsp;&nbsp;即所有图片将由远端服务器下载并压缩,提供压缩文件链接,直接下载此链接解压即可。<br/>',
                '<br/><p><b>寻求帮助?</b><a href="https://blog.saintic.com/blog/256.html" target="_blank" title="FAQ、彩蛋、文档等" style="color: green;">请点击我!</a></p></div>'
            ].join('');
        layer.open({
            type: 1,
            title: "选择画板图片下载方式",
            content: msg,
            closeBtn: false,
            shadeClose: false,
            shade: 0,
            btn: ['文本', '本地', '远程'],
            btnAlign: 'c',
            zIndex: layer.zIndex,
            success: function(layero) {
                layer.setTop(layero);
            },
            yes: function(index, layero) {
                //文本方式下载,比如迅雷、QQ旋风
                downloadMethod = 1;
                layer.close(index);
                layer.open({
                    type: 1,
                    title: "文本方式下载",
                    content: '<div style="padding: 20px;"><b>请点击复制按钮,粘贴到迅雷等下载!</b></div>',
                    closeBtn: false,
                    shadeClose: false,
                    shade: 0,
                    btn: '复制',
                    btnAlign: 'c',
                    maxmin: true,
                    zIndex: layer.zIndex,
                    success: function(layero) {
                        layer.setTop(layero);
                    },
                    yes: function(index, layero) {
                        layer.close(index);
                        GM_setClipboard(pins.map(function(pin) {
                            return pin.imgUrl + "\n";
                        }).join(""));
                        layer.msg("复制成功", {
                            icon: 1
                        });
                    }
                });
            },
            btn2: function(index, layero) {
                //本地下载
                downloadMethod = 2;
                layer.close(index);
                pins.map(function(pin) {
                    saveImage(pin.imgUrl, pin.imgName);
                });
            },
            btn3: function(index, layero) {
                //远端下载
                downloadMethod = 3;
                layer.close(index);
                // 提醒接收配置信息读取
                var email = getUrlQuery("email", getReceiveBy('email'));
                var mobile = getUrlQuery("sms", getReceiveBy('mobile'));
                $.ajax({
                    url: "https://open.saintic.com/CrawlHuaban/",
                    type: "POST",
                    data: {
                        site: 1,
                        version: GM_info.script.version,
                        board_total: pin_number,
                        board_id: board_id,
                        user_id: user_id,
                        pins: JSON.stringify(pins),
                        email: email,
                        sms: mobile
                    },
                    success: function(res) {
                        if (res.success === true) {
                            var msg = ['<div style="padding: 20px;"><b>下载任务已经提交!</b><br>根据画板图片数量,所需时间不等,请稍等数分钟后访问下载链接:<br><i><a href="',
                                res.downloadUrl + '" target="_blank">',
                                res.downloadUrl + '</a></i><br>它将于<b>',
                                res.expireTime + '</b>过期,那时资源会被删除,请提前下载。',
                                res.tip + '</div>'
                            ].join("");
                            layer.open({
                                type: 1,
                                title: "温馨提示",
                                content: msg,
                                closeBtn: false,
                                shadeClose: false,
                                shade: 0,
                                area: '350px',
                                btn: '我已知晓并复制下载链接',
                                btnAlign: 'c',
                                maxmin: true,
                                zIndex: layer.zIndex,
                                success: function(layero) {
                                    layer.setTop(layero);
                                },
                                yes: function(index, layero) {
                                    layer.close(index);
                                    GM_setClipboard(res.downloadUrl);
                                    var tips = '复制成功!';
                                    if (email) {
                                        tips += ' 接收提醒邮箱:' + email;
                                    }
                                    if (mobile) {
                                        tips += ' 接收提醒手机:' + mobile;
                                    }
                                    layer.msg(tips, {
                                        icon: 1
                                    });
                                }
                            });
                        } else {
                            layer.msg("远端服务提示: " + res.msg, {
                                icon: 2,
                                time: 8000
                            });
                        }
                    }
                });
            },
            end: function() {
                $.ajax({
                    url: "https://open.saintic.com/CrawlHuaban/putClick",
                    type: "POST",
                    data: {
                        site: 1,
                        version: GM_info.script.version,
                        total_number: pin_number,
                        pin_number: pins.length,
                        board_id: board_id,
                        user_id: user_id,
                        downloadMethod: downloadMethod
                    }
                });
            }
        });
    }
    //交互确定用户下载方式
    function interactiveUser(user_id, boards, board_number) {
        boards.map(function(board_id) {
            var msg = [
                '<div style="padding: 20px;"><b>当前画板是:' + board_id + '!</b><small>提示: 只有登录后才可以抓取几乎所有画板哦。</small><br/>',
                '<b>请选择以下两种功能按钮:</b><br/>',
                '1. <i>开始下载</i>: <br/>&nbsp;&nbsp;&nbsp;&nbsp;点击此按钮将开始抓取画板图片,抓取完成后弹出下载方式,请选择某种方式后完成当前画板下载。<br/>',
                '2. <i>跳过</i>: <br/>&nbsp;&nbsp;&nbsp;&nbsp;即忽略此画板,并关闭本窗口。<br/>',
                '<br/><p><b>请注意:</b>用户存在多个画板时会弹出多个窗口,请移动或最小化当前窗口以显示其他窗口。</p>',
                '<br/><p><b>寻求帮助?</b><a href="https://blog.saintic.com/blog/256.html" target="_blank" title="FAQ、彩蛋、文档等" style="color: green;">请点击我!</a></p></div>'
            ].join('');
            layer.open({
                type: 1,
                title: "花瓣网用户抓取:" + user_id,
                content: msg,
                closeBtn: false,
                shadeClose: false,
                shade: 0,
                btn: ['开始下载', '跳过'],
                btnAlign: 'c',
                maxmin: true,
                zIndex: layer.zIndex,
                success: function(layero) {
                    layer.setTop(layero);
                },
                yes: function(index, layero) {
                    //按钮【开始下载】的回调
                    layer.close(index);
                    downloadBoard(board_id);
                },
                btn2: function(index, layero) {
                    //按钮【跳过】的回调
                    layer.close(index);
                }
            });
        });
        layer.open({
            type: 1,
            title: "温馨提示",
            content: '<div style="padding: 20px;"><b>当前用户画板数量总共为' + board_number + '个,抓取了' + boards.length + '个,抓取率:' + calculatePercentage(boards.length, board_number) + '!</b><br/><b>寻求帮助?Bug反馈?</b><a href="https://blog.saintic.com/blog/256.html" target="_blank" title="帮助文档" style="color: green;">请点击我!</a></div>',
            closeBtn: false,
            shadeClose: false,
            shade: 0,
            btn: '我已知晓',
            btnAlign: 'c',
            zIndex: layer.zIndex,
            success: function(layero) {
                layer.setTop(layero);
            },
            yes: function(index, layero) {
                //按钮【我已知晓】的回调
                layer.close(index);
            }
        });
    }
    //画板解析与下载
    function downloadBoard(board_id) {
        if (board_id) {
            console.group("花瓣网下载-当前画板:" + board_id);
            var limit = 100,
                loadingLayer = layer.load(0, {
                    time: 1000
                });
            //get first pin data
            $.ajax({
                url: window.location.protocol + '//' + getEffectiveHost() + '/boards/' + board_id,
                async: false,
                success: function(res) {
                    try {
                        //console.log(res);
                        if (res.hasOwnProperty("board") === true) {
                            var board_data = res.board,
                                //画板图片总数
                                pin_number = board_data.pin_count,
                                board_pins = board_data.pins,
                                user_id = board_data.user.urlname,
                                //尝试向上取整,计算加载完画板图片需要的最大次数
                                retry = board_pins.length < pin_number ? Math.ceil(pin_number / limit) : 0;
                            console.debug("Current board <" + board_id + "> pins number is " + pin_number + ", first pins number is " + board_pins.length + ", retry is " + retry);
                            var bf = setInterval(function() {
                                if (retry > 0) {
                                    //说明没有加载完画板图片,需要ajax请求
                                    var last_pin = board_pins[board_pins.length - 1].pin_id;
                                    //get ajax pin data
                                    var board_next_url = window.location.protocol + "//" + getEffectiveHost() + "/boards/" + board_id + "/?max=" + last_pin + "&limit=" + limit + "&wfl=1";
                                    $.ajax({
                                        url: board_next_url,
                                        async: false,
                                        success: function(res) {
                                            //console.log(res);
                                            var board_next_data = res.board;
                                            board_pins = board_pins.concat(board_next_data.pins);
                                            console.debug("ajax load board with pin_id " + last_pin + ", get pins number is " + board_next_data.pins.length + ", merged");
                                            if (board_next_data.pins.length === 0) {
                                                retry = 0;
                                                return false;
                                            }
                                            last_pin = board_next_data.pins[board_next_data.pins.length - 1].pin_id;
                                        }
                                    });
                                    retry--;
                                } else {
                                    console.log("画板" + board_id + "共抓取" + board_pins.length + "个pin");
                                    var pins = board_pins.map(function(pin) {
                                        return {
                                            imgUrl: window.location.protocol + "//hbimg.b0.upaiyun.com/" + pin.file.key,
                                            imgName: pin.pin_id + "." + pin.file.type.split("/")[1]
                                        };
                                    })
                                    //交互确定下载方式
                                    interactiveBoard(board_id, pins, pin_number, user_id);
                                    clearInterval(bf);
                                }
                            }, 200);
                        }
                    } catch (e) {
                        console.error(e);
                    }
                }
            });
            console.groupEnd();
        }
    }
    //用户解析与下载
    function downloadUser(user_id) {
        if (user_id) {
            console.group("花瓣网下载-当前用户:" + user_id);
            var limit = 10;
            //get first board data
            $.ajax({
                url: window.location.protocol + '//' + getEffectiveHost() + '/' + user_id,
                async: false,
                success: function(res) {
                    try {
                        //console.log(res);
                        if (res.hasOwnProperty("user") === true) {
                            var user_data = res.user,
                                board_number = user_data.board_count,
                                board_ids = user_data.boards,
                                retry = board_ids.length < board_number ? Math.ceil(board_number / limit) : 0;
                            console.debug("Current user <" + user_id + "> boards number is " + board_number + ", first boards number is " + board_ids.length + ", retry is" + retry);
                            var uf = setInterval(function() {
                                if (retry > 0) {
                                    var last_board = board_ids[board_ids.length - 1].board_id;
                                    //get ajax board data
                                    var user_next_url = window.location.protocol + "//" + getEffectiveHost() + "/" + user_id + "/?max=" + last_board + "&limit=" + limit + "&wfl=1";
                                    $.ajax({
                                        url: user_next_url,
                                        async: false,
                                        success: function(res) {
                                            //console.log(res);
                                            var user_next_data = res.user.boards;
                                            board_ids = board_ids.concat(user_next_data);
                                            console.debug("ajax load user with board_id " + last_board + ", get boards number is " + user_next_data.length + ", merged");
                                            if (user_next_data.length === 0) {
                                                retry = 0;
                                                return false;
                                            }
                                            last_board = user_next_data[user_next_data.length - 1].board_id;
                                        }
                                    });
                                    retry--;
                                } else {
                                    console.log("用户" + user_id + "共抓取" + board_ids.length + "个board");
                                    var boards = board_ids.map(function(board) {
                                        return board.board_id;
                                    });
                                    //交互确定下载方式
                                    interactiveUser(user_id, boards, board_number);
                                    clearInterval(uf);
                                }
                            }, 200);
                        }
                    } catch (e) {
                        console.error(e);
                    }
                }
            });
            console.groupEnd();
        }
    }
    //获取公告接口
    function showNotice() {
        $.ajax({
            url: "https://open.saintic.com/CrawlHuaban/notice?catalog=2",
            type: "GET",
            success: function(res) {
                if (res.code === 0) {
                    var notices = res.data;
                    if (notices.length > 0) {
                        var storage = new StorageMix("grab_huaban_board");
                        var localIds = storage.get() || [];
                        var html = "";
                        notices.map(function(notice) {
                            //notice{id, ctime, content}
                            if (!arrayContains(localIds, notice.id) === true) {
                                localIds.push(notice.id);
                                html += "<p><b><i>@" + formatUnixtimestamp(notice.ctime) + "</i></b> 【 " + notice.content + " 】</p>";
                            }
                        });
                        storage.set(localIds);
                        if (!html) {
                            return false;
                        }
                        layer.open({
                            type: 1,
                            title: '诏预开放平台公告',
                            closeBtn: false,
                            area: 'auto',
                            shade: 0,
                            id: 'grab_huaban_board' //设定一个id,防止重复弹出
                                ,
                            resize: true,
                            maxmin: true,
                            btn: ['我知道了'],
                            btnAlign: 'c',
                            moveType: 1 //拖拽模式,0或者1
                                ,
                            content: '<div style="padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">' + html + '</div>',
                            yes: function(index, layero) {
                                layer.close(index);
                            }
                        });
                    }
                }
            }
        });
    }
    /*
        主入口,分出不同模块:用户、画板,监听并刷新URL
    */
    //当前URL
    var initUrl = window.location.href;
    //判断UA是否为移动端
    var isMobile = ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone|Opera Mini)/i))) ? true : false;
    if (window.location.pathname.split('/')[1] === "boards") {
        //当前在画板地址下
        var board_id = window.location.pathname.split('/')[2],
            board_text = "下载此画板",
            board_mobile_text = "下载",
            setup_email_text = "配置提醒邮箱",
            setup_mobile_text = "配置提醒手机号";
        if (isMobile && hasId("mobile_board_page")) {
            //当前是移动版
            var bca = document.getElementById('board_card').getElementsByTagName("a"),
                brpx = "10px";
            if (bca.length <= 1) {
                bca = bca[0];
            } else {
                bca = bca[1];
                if (isContains(bca.innerText, "已关注")) {
                    brpx = "116px";
                } else {
                    brpx = "103px";
                }
            }
            if (isContains(bca.innerText, board_mobile_text) === false) {
                bca.insertAdjacentHTML('afterEnd', '<a href="javascript:;" id="downloadBoard" class="btn rbtn" style="position:absolute;right:' + brpx + ';top:22px;"><span class="text"> ' + board_mobile_text + '</span></a>');
            }
        } else {
            //当前是PC版
            var pab = document.getElementById('board_card').getElementsByClassName('action-buttons')[0];
            //插入下载画板按钮
            if (isContains(pab.innerText, board_text) === false) {
                var tmpHtml = '<a href="javascript:;" id="setupEmailText" class="btn rbtn"><span class="text"> ' + setup_email_text + '</span></a>' +
                    '<a href="javascript:;" id="setupMobileText" class="btn rbtn"><span class="text"> ' + setup_mobile_text + '</span></a>' +
                    '<a href="javascript:;" id="downloadBoard" class="btn rbtn"><span class="text"> ' + board_text + '</span></a>';
                pab.insertAdjacentHTML('afterbegin', tmpHtml);
            }
        }
        //监听画板点击下载事件
        document.getElementById("downloadBoard").onclick = function() {
            //展示公告
            showNotice();
            downloadBoard(board_id);
        };
    } else if (hasId("user_page") === true || hasId("people_card") === true) {
        //根据user_page确定了是在用户主页
        var user_id = window.location.pathname.split('/')[1],
            user_text = "下载此用户",
            user_mobile_text = "下载",
            setup_email_text = "配置提醒邮箱",
            setup_mobile_text = "配置提醒手机号";
        if (arrayContains(["all", "discovery", "favorite", "categories", "apps", "about", "search", "activities", "settings", "users", "friends", "partner", "message", "muse", "login", "signup", "go", "explore"], user_id) === false) {
            //排除以上数组中的二级目录
            if (isMobile && hasId("people_card")) {
                //当前是移动版
                var pca = document.getElementById('people_card').getElementsByTagName("a"),
                    urpx = "10px";
                if (pca.length <= 2) {
                    pca = pca[1];
                } else {
                    pca = pca[2];
                    if (isContains(pca.innerText, "已关注")) {
                        urpx = "85px";
                    } else {
                        urpx = "68px";
                    }
                }
                if (isContains(pca.innerText, user_mobile_text) === false) {
                    pca.insertAdjacentHTML('afterEnd', '<a href="#" id="downloadUser" class="btn rbtn" style="position:absolute;right:' + urpx + ';top:30px;"><span class="text"> ' + user_mobile_text + '</span></a>');
                }
            } else {
                //当前是PC版
                var uca = document.getElementById('user_card').getElementsByClassName('action-buttons')[0];
                //插入下载用户画板按钮
                if (isContains(uca.innerText, user_text) === false) {
                    var tmpHtml = '<a href="javascript:;" id="setupEmailText" class="btn rbtn"><span class="text"> ' + setup_email_text + '</span></a>' +
                        '<a href="javascript:;" id="setupMobileText" class="btn rbtn"><span class="text"> ' + setup_mobile_text + '</span></a>' +
                        '<a href="javascript:;" id="downloadUser" class="btn rbtn"><span class="text"> ' + user_text + '</span></a>';
                    uca.insertAdjacentHTML('afterbegin', tmpHtml);
                }
            }
            //监听用户点击下载事件
            document.getElementById("downloadUser").onclick = function() {
                //展示公告
                showNotice();
                downloadUser(user_id);
            };
        }
    }
    // 配置提醒邮箱
    document.getElementById('setupEmailText').onclick = function() {
        setupReceiveTo('email');
    }
    // 配置提醒手机号
    document.getElementById('setupMobileText').onclick = function() {
        setupReceiveTo('mobile');
    }
    //采用循环方式判断url变化
    setInterval(function() {
        if (window.location.href != initUrl) {
            if (hasId("downloadBoard") === false && hasId("downloadUser") === false) {
                if (window.location.pathname.split('/')[1] != "pins") {
                    window.location.reload();
                }
            }
        }
    }, 1000);
})();