Greasy Fork is available in English.

新商盟订单获取条码

新商盟订烟获取订单对应香烟条码,便于导入到采购入库单

// ==UserScript==
// @name         新商盟订单获取条码
// @namespace    http://*.xinshangmeng.com/
// @version      0.1
// @description  新商盟订烟获取订单对应香烟条码,便于导入到采购入库单
// @author       春杰
// @match        http://*.xinshangmeng.com/*orderForCC/myCoDetailForCC*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    var codeTable = {
        220407 : '6901028100267',
        320111 : '6901028111263',
        420164 : '6901028181785',
        530235 : '6901028315005',
        220418 : '6901028098656',
        530134 : '6901028046886',
        220409 : '6901028097383',
        220419 : '6901028099219',
        420122 : '6901028180559',
        340227 : '6901028223997',
        520121 : '6901028095884',
        320103 : '6901028300056',
        330102 : '6901028118170',
        370230 : '6901028157643',
        420212 : '6901028178211',
        220241 : '6901028100410',
        430237 : '6901028063364',
        530224 : '6901028317122',
        420192 : '6901028188074',
        310112 : '6901028075770',
        210201 : '6901028092944',
        610611 : '6901028058131',
        530952 : '6901028322522',
        110106 : '6901028071468',
        320102 : '6901028300070',
        410214 : '6901028163613',
        350345 : '6901028211345',
        220283 : '6901028100663',
        310104 : '6901028075862',
        430201 : '6901028193498',
        350217 : '6901028137126',
        410215 : '6901028169677',
        530927 : '6901028339940',
        340176 : '6901028223751',
        410238 : '6901028160278',
        510107 : '6901028024969',
        530938 : '6901028054881',
        520138 : '6901028221443',
        320319 : '6901028115155',
        630002 : '6901028227278',
        370232 : '6901028159746',
        620108 : '6901028066853',
        310173 : '6901028010108',
        410231 : '6901028165235',
        340218 : '6901028208932',
        410241 : '6901028165914',
        220216 : '6901028100359',
        520137 : '6901028036047',
        210209 : '6901028092821',
        220297 : '6901028097178',
        310169 : '6901028071529',
        360115 : '6901028224062',
        220281 : '6901028099776',
        220411 : '6901028098328',
        340232 : '6901028124881',
        430234 : '6901028192095',
        700204 : '4891132530017',
        530120 : '6901028045902',
        350346 : '6901028211376',
        530216 : '6901028316989',
        520139 : '6901028221535',
        320309 : '6901028062008',
        340223 : '6901028125314',
        130122 : '6901028080514',
        410236 : '6901028164160',
        350202 : '6901028143073',
        420128 : '6901028184250',
        530945 : '6901028326483',
        220422 : '6901028096249',
        440112 : '6901028005142',
        130120 : '6901028079952',
        430238 : '6901028201711',
        530939 : '6901028340601',
        320112 : '6901028062343',
        330134 : '6901028121729',
        420195 : '6901028219143',
        420189 : '6901028187275',
        320118 : '6901028111539',
        420162 : '6901028189972',
        330131 : '6901028121514',
        700207 : '4891132580012',
        310168 : '6901028018210',
        320116 : '6901028062312',
        420113 : '6901028180573',
        530928 : '6901028053464',
        330126 : '6901028118996',
        220420 : '6901028096096',
        310101 : '6901028075763',
        530261 : '6901028054430',
        310171 : '6901028018715',
        450113 : '6901028011990',
        510252 : '6901028084918',
        130127 : '6901028107136',
        530946 : '6901028317573',
        420211 : '6901028218740',
        220421 : '6901028096195',
        310183 : '6901028212137',
        430241 : '6901028196024',
        510260 : '6901028084765',
        320119 : '6901028112987',
        530948 : '6901028177757',
        370322 : '6901028155960',
        420174 : '6901028181440',
        530919 : '6901028051996',
        360120 : '6901028224635',
        430250 : '6901028204804',
        610618 : '6901028937405',
        310176 : '6901028018777',
        220290 : '6901028100373',
        320313 : '6901028301695',
        530951 : '6901028339520',
        220291 : '6901028100137',
        520141 : '6901028221665',
        420181 : '6901028188012',
        420188 : '6901028187855',
        210211 : '6901028090544',
        370326 : '6901028155908',
        310128 : '6901028075725',
        220417 : '6901028096805',
        330117 : '6901028120692',
        320318 : '6901028303880',
        700205 : '8888075024020',
        700151 : '8888075005517',
        530266 : '6901028312356',
        430232 : '6901028196055',
        310179 : '6901028018968',
        530949 : '6901028177696',
        340159 : '6901028131612',
        700150 : '8888075005487',
        320317 : '6901028116237',
        530265 : '6901028056663',
        340225 : '6901028125970',
        410243 : '6901028167062',
        430249 : '6901028204828',
        630007 : '6901028228909',
        320109 : '6901028112772',
        310185 : '6901028212335',
        700201 : '8888075018609',
        320304 : '6901028114448',
        410235 : '6901028165860',
        310180 : '6901028212212',
        350338 : '6901028143431',
        430254 : '6901028191296',
        330133 : '6901028121811',
        310170 : '6901028018630',
        530947 : '6901028331296',
        310182 : '6901028212182',
        510273 : '6901028145060',
        360121 : '6901028224611',
        220416 : '6901028098595',
        530277 : '6901028177207',
        310181 : '6901028071673',
        350336 : '6901028143844',
        530953 : '6901028322850',
        330119 : '6901028118811',
        370319 : '6901028155540',
        420171 : '6901028184304',
        370313 : '6901028154611',
        630008 : '6901028229067',
        520146 : '6901028102087',
        370329 : '6901028158381',
        410233 : '6901028165358',
        520127 : '6901028102810',
        410219 : '6901028169967',
        430121 : '6901028196932'
    };
    var arr = $("#cgt tbody tr");//获取订单列表
    var codeTxt = "";
    arr.each(function(){
        var td = $(this).children("td");
        //如果订购量大于零,就查找编码并添加到字符串
        if(td.eq(5).text() > 0){
            var temp = td.eq(0).text();
            var code = eval("codeTable["+temp+"]");
            if(code != undefined){
                codeTxt = codeTxt + code + "\r\n";
            }
        }
    });
    /**
     * [
     *     saveToDesktop
     *     IE:可以将数据写进文件并保存到桌面;
     *     fireFox:可以选择路径将写进数据的文件保存;
     *     chrome:只能保存到浏览器指定的下载目录下;
     * ]
     * @param  {[string]} fileName [文件名 如:"test.txt"]
     * @param  {[string]} data     [数据 如:"username:key \r\n password:123456"]
     */
    function saveToDesktop(fileName, data) {
        var explorer = navigator.userAgent.toLowerCase();
        if (explorer.indexOf("trident") > 0) {//IE 5+
            var wss = new ActiveXObject("WScript.Shell");
            var desktopUrl = wss.SpecialFolders("Desktop");
            var fso = new ActiveXObject("Scripting.FileSystemObject");
            var tf = fso.CreateTextFile(desktopUrl + "\\" + fileName, true);
            tf.Write(data);
            tf.Close();
        } else {//fireFox chrome
            var urlObj = window.URL || window.webkitURL || window;
            var blob = new Blob([data]);
            var link = document.createElementNS("http://www.w3.org/1999/xhtml", "a")
            link.href = urlObj.createObjectURL(blob);
            link.download = fileName;
            saveClick(link);
        }

        function saveClick(obj) {
            var e = document.createEvent("MouseEvents");
            e.initMouseEvent(
                "click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null
            );
            obj.dispatchEvent(e);
        }
    }
    saveToDesktop("香烟条码.txt",codeTxt);
})();