NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name 豆果注入 // @namespace cn.dietcare // @include http://www.douguo.com/upfood.html // @version 1 // @grant none // ==/UserScript== $(function () { function addCssByStyle(cssString) { var doc = document; var style = doc.createElement('style'); style.setAttribute('type', 'text/css'); if (style.styleSheet) { // IE style.styleSheet.cssText = cssString; } else { // w3c var cssText = doc.createTextNode(cssString); style.appendChild(cssText); } var heads = doc.getElementsByTagName('head'); if (heads.length) heads[0].appendChild(style); else doc.documentElement.appendChild(style); } addCssByStyle('.tips {font-size:12px;}\t.list_box {position:absolute;margin-left:1px;width:191px;background:#f3f3f3;border:1px solid #CCC;\t}\t.keywords_list {margin:0;padding:0;\tlist-style:none;}\tli:hover {background:#33CCFF;color:#333333;}'); var paramname = null; $.extend({ getdata:function(key,index){ var name =""; if(key=="zhu"){ name = $("input[name='zhuliao[]']:eq("+index+")").val(); }else{ name = $("input[name='fuliao[]']:eq("+index+")").val(); } if("null"!= name && name !=paramname ){ $.ajax({ type: 'get', async: true, url: 'http://192.168.88.247:8080/dietservice/rest/queryIngredient', data: 'token=c8a6aed59bc175af999261f64e0e02aaa2d60476d6bd2194ac5241ba6f34513193fb01dc3e43d662&name=' + name, dataType: 'jsonp', //数据类型为jsonp jsonp: 'jsonpCallback', //服务端用于接收callback调用的function名的参数 success: function (data) { var str = ''; var str2=''; $.each(data.data, function (index, content) { str += '<li>' + content.name + '</li>'; if(content.unit !="克" && content.unit !="斤" && content.unit !="两" ){ str2 += '<li>'+ content.unit + '</li>'; } }); if(str != ''){ var datadiv = '<div id=\'tt\'><ul> ' + str + '</ul></div>'; if($("#tt").length>0){ $("#tt").html(datadiv); }else{ if(key=="zhu"){ $("input[name='zhuliao[]']:eq("+index+")").after(datadiv); }else{ $("input[name='fuliao[]']:eq("+index+")").after(datadiv); } $('#tt').addClass('list_box'); } $('#tt ul li').on('click', function () { if(key=="zhu"){ $("input[name='zhuliao[]']:eq("+index+")").val($(this).html()); }else{ $("input[name='fuliao[]']:eq("+index+")").val($(this).html()); } $('#tt').remove(); }); } var sss = '' //str2 += "<li>"+$("input[name='zhuliaoValue[]']:eq("+index+")").val()+"克</li><li>"+$("input[name='zhuliaoValue[]']:eq("+index+")").val()+"斤</li><li>"+$("input[name='zhuliaoValue[]']:eq("+index+")").val()+"两</li>"; str2 += "<li>克</li><li>斤</li><li>两</li>"; $("input[name='zhuliaoValue[]']:eq("+index+")").focus(function(){ sss = setInterval(function(){ var value = ""; value = $("input[name='zhuliaoValue[]']:eq("+index+")").val(); if(value.length>0){ value = value.replace(/[^0-9]/ig,""); } var datadiv2 = '<div id=\'tt2\'><ul> ' + str2 + '</ul></div>'; if($("#tt2").length>0){ $("#tt2").html(datadiv2); }else{ $("input[name='zhuliaoValue[]']:eq("+index+")").after(datadiv2); $('#tt2').addClass('list_box'); } $('#tt2 ul li').each(function(){ $(this).html(value+""+$(this).html()); }); $('#tt2 ul li').on('click', function () { $("input[name='zhuliaoValue[]']:eq("+index+")").val($(this).html()); $('#tt2').remove(); }); },400); }).blur(function(){ clearInterval(sss); }); $("input[name='fuliaoValue[]']:eq("+index+")").focus(function(){ sss = setInterval(function(){ var value = ""; value = $("input[name='fuliaoValue[]']:eq("+index+")").val(); if(value.length>0){ value = value.replace(/[^0-9]/ig,""); } var datadiv2 = '<div id=\'tt2\'><ul> ' + str2 + '</ul></div>'; if($("#tt2").length>0){ $("#tt2").html(datadiv2); }else{ $("input[name='fuliaoValue[]']:eq("+index+")").after(datadiv2); $('#tt2').addClass('list_box'); } $('#tt2 ul li').each(function(){ $(this).html(value+""+$(this).html()); }); $('#tt2 ul li').on('click', function () { $("input[name='fuliaoValue[]']:eq("+index+")").val($(this).html()); $('#tt2').remove(); }); },400); }).blur(function(){ clearInterval(sss); }); }, error: function () { alert('fail'); } }); } paramname = name; } }); var interval = ''; $("input[name='zhuliao[]']").each(function(index){ var name=null; $(this).focus(function(){ interval = setInterval("$.getdata('zhu',"+index+")", 200); }).blur(function(){ clearInterval(interval); }); }); $("input[name='fuliao[]']").each(function(index){ var name=null; $(this).focus(function(){ interval = setInterval("$.getdata('fu',"+index+")", 200); }).blur(function(){ clearInterval(interval); }); }); });