zoukankan      html  css  js  c++  java
  • 电商工具 谷歌插件 版本 2020-10-29

    最新版

    https://www.cnblogs.com/guxingy/p/14661143.html


    插件下载:
    https://files-cdn.cnblogs.com/files/guxingy/谷歌插件-保存订单.rar

    之前的文章有如何安装的教程

    //原文:https://github.com/smileyby/js-table-excel
    //原文:https://github.com/sxei/chrome-plugin-demo
    
    
    
    
    
    var tableToExcel = (function () {
        var uri = 'data:application/vnd.ms-excel;base64,',
            template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">'
                + '<head><meta http-equiv="Content-type" content="text/html;charset=UTF-8" /><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/>'
                + '</x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body>{table}</body></html>',
            base64 = function (s) {
                return window.btoa(unescape(encodeURIComponent(s)))
            },
            format = function (s, c) {
                return s.replace(/{(w+)}/g, function (m, p) {
                    return c[p];
                })
            };
    
        return function (table_html, name) {
            var ctx = {
                worksheet: name || 'Worksheet',
                table: table_html
            }
            return uri + base64(format(template, ctx));
        }
    })();
    
    
    
    Date.prototype.Format = function (fmt) {
        var o = {
            "M+": this.getMonth() + 1, //月份
            "d+": this.getDate(), //日
            "H+": this.getHours(), //小时
            "m+": this.getMinutes(), //分
            "s+": this.getSeconds(), //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }
    
    
    
    var msieversion = function () {
    	var ua = window.navigator.userAgent;
    	var msie = ua.indexOf("MSIE ");
    	if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv:11./)) // If Internet Explorer, return version number
    	{
    		return true;
    	} else { // If another browser,
    		return false;
    	}
    	return false;
    };
    
    
    
    var JSONToCSVConvertor = function (JSONData, ShowLabel) {
    	var arrData = typeof JSONData !== 'object' ? JSON.parse(JSONData) : JSONData;
    	var CSV = '';
    	if (ShowLabel) {
    		var row = "";
    		for (var index in arrData[0]) {
    			row += index + ',';
    		}
    		row = row.slice(0, -1);
    		CSV += row + '
    ';
    	}
    	for (var i = 0; i < arrData.length; i++) {
    		var row = "";
    		for (var index in arrData[i]) {
    			// 这样改 对excel更友好,但是得注意里面的数据是否有问题,现在不严谨 明天加判断
    			var arrValue = arrData[i][index] == null ? "" : arrData[i][index];
    			//var arrValue = arrData[i][index] == null ? "" : '="' + arrData[i][index] + '"';
    			row += arrValue + ',';
    		}
    		row.slice(0, row.length - 1);
    		CSV += row + '
    ';
    	}
    	if (CSV == '') {
    		growl.error("Invalid data");
    		return;
    	}
    	var fileName = "Result";
    	if (msieversion()) {
    		var IEwindow = window.open();
    		IEwindow.document.write('sep=,
    ' + CSV);
    		IEwindow.document.close();
    		IEwindow.document.execCommand('SaveAs', true, fileName + ".csv");
    		IEwindow.close();
    	} else {
    		//var uri = 'data:application/csv;charset=utf-8,' + escape(CSV);
    		var uri = 'data:application/csv;charset=utf-8,' + CSV;
    		var link = document.createElement("a");
    		link.href = uri;
    		link.style = "visibility:hidden";
    		link.download = fileName + ".csv";
    		document.body.appendChild(link);
    		link.click();
    		document.body.removeChild(link);
    	}
    };
    
    
    
    
    
    
    
    
    
    
    var arr = [];
    
    
    
    var add = function(){
    
    	$("div.trade-order-main").each(function () {
    
    		var orderInfo = {
    			orderNum: '',
    			createTime: '',
    			title: '',
    			nickName: '',
    			realPrice: '',
    		};
    		
    		// order info
    		var spans = $($(this).children("table")[0]).find("tbody label span");
    		orderInfo.orderNum = $(spans[2]).text();
    		orderInfo.createTime = $(spans[5]).text();
    
    		// goods info
    		var spans = $($(this).children("table")[1]).find("tbody tr").each(function () {
    			var index = $(this).index();
    			if (index == 0) {
    				var tds = $(this).find("td");;
    				orderInfo.title = $($(tds[0]).find("p span")[1]).text();
    				orderInfo.nickName = $($(tds[4]).find("a")[0]).text();
    				orderInfo.realPrice = $($(tds[6]).find("span")[1]).text();
    			} else {// one order, multiple goods
    				var tds = $(this).find("td");;
    				orderInfo.title = orderInfo.title + "," + $($(tds[0]).find("p span")[1]).text();
    			}
    
    		});
    
    		// console
    		//console.log(orderInfo);
    		arr.push(orderInfo);
    	});
    	console.log(arr);
    };
    
    
    
    
    
    
    
    // 接收来自后台的消息
    chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
        console.log('收到来自 ' + (sender.tab ? "content-script(" + sender.tab.url + ")" : "popup或者background") + ' 的消息:', request);
        if (request.cmd == 'update_font_size') {
    		var id = setInterval(function () {
    			console.log('准备保存数据');
    			add();
    			console.log('数据保存完成');
    			if ($("#sold_container li.pagination-disabled.pagination-next").length > 0) {
    				console.log('没有下一页了');
    				window.clearInterval(id)
    				JSONToCSVConvertor(arr.reverse(), true);
    				return;
    			}
    			$("li.pagination-next").get(0).click();//下一页           
    		}, 2000);
        }
        else {
            tip(JSON.stringify(request));
            sendResponse('我收到你的消息了:' + JSON.stringify(request));
        }
    });
    
  • 相关阅读:
    Python学习笔记(十四)—hashlib模块
    Python学习笔记(十三)—函数常用模块
    Python学习笔记(十二)—函数
    PHP-代码执行
    CVE-2020-5902 F5 BIG-IP RCE复现
    sqli-Mysql写shell/读文件
    Mysql服务端反向读取客户端的任意文件
    PHP-AJAX
    PHP-XML
    googlehacking
  • 原文地址:https://www.cnblogs.com/guxingy/p/13899468.html
Copyright © 2011-2022 走看看