wangantding / add_shopitem

// ==UserScript==
// @name       add_shopitem
// @namespace  http://use.i.E.your.homepage/
// @version    0.1
// @description  enter something useful
// @match      http://shop.kongfz.com/seller/product/item.html
// @grant GM_getValue
// @grant GM_setValue
// @copyright  2012+, You
// ==/UserScript==

//变量声明
var inject;
var book_cs;
var book_hh;
//货号界面
var hh_div = document.createElement("label");
hh_div.innerHTML = '<label>货号:<input size=8 id="bk_hh"/></label>';

/*huohao.onchange = function(){
    GM_setValue('bk_hh',huohao.value);
    alert(GM_getValue('bk_hh',"null"));
}*/

//录入图书种类设置
var sel1 = document.createElement("select");
var op0 = new Option("普通书" , 0 );
var op1 = new Option("教材", 1 );
sel1.options[0] = op0;
sel1.options[1] = op1;
sel1.onchange = function(){
    GM_setValue('bk_cs',sel1.selectedIndex);
};

//全局变量
book_cs = GM_getValue('bk_cs',1);
book_hh = GM_getValue('bk_hh',"null");
inject = function (){
	//书名
	var bookname = document.getElementById("itemName").value;
    var author = document.getElementById("author").value;
    var press = document.getElementById("press").value;
    document.getElementById("author").value = author + " " +  bookname;
    document.getElementById("press").value = press + " " + bookname;
    if( book_cs == 0 ){
        document.getElementById("qualityDesc").value = "图书品相请买家自定。细节描述不够详细,但图片为实拍图。如对品相有高标准要求,还请留言详问。";  
    }
    else{
        document.getElementById("qualityDesc").value = "本店所有图书的照片均为实际拍摄,而且品相均在8-9成新左右,是正版二手图书。大部分教材的内页都会有笔记,但我们会挑选品相最好,成色最新的出售。【如在意笔记的,对品相苛刻的请留言询问】"; 
    }
    document.getElementById("itemSn").value = book_hh;
    var sub_hh1 = book_hh.substring(3);
    var sub_hh2 = parseInt(sub_hh1) + 1;
    sub_hh2 = sub_hh2.toString();
    for(i = sub_hh2.length; i < 4; i++ ){
        sub_hh2 = 0 + sub_hh2;
    }
    book_hh = book_hh.replace( sub_hh1, sub_hh2 );
    GM_setValue('bk_hh',book_hh );
}

//提交按钮,自动设置固定参数
var bt1 = document.createElement("input");
bt1.setAttribute("type", "button");
bt1.setAttribute("id", "bt1");
bt1.setAttribute("width", "300");
bt1.setAttribute("height", "100");
bt1.setAttribute("value", "修改");
//提交方法
bt1.onclick = inject;

//页面显示设置
var c = document.getElementById("content");
c.appendChild(hh_div);
c.appendChild(sel1);
c.appendChild(bt1);


//货号处理
var huohao = document.getElementById("bk_hh");
huohao.onchange = function(){
    GM_setValue('bk_hh',huohao.value);
    book_hh = huohao.value;
}



//载入
sel1.options[book_cs].selected = true;
huohao.value = book_hh;