allImg.js // ==UserScript==// @name allImg// @namespace https://zcmzcm.org/// @version 3.1// @description 百度推广批量添加删除创意图片// @author 张城铭// @match http://fengchao.baidu.com/nirvana/main.html?userid=*// @grant
// ==UserScript== // @name allImg // @namespace https://zcmzcm.org/ // @version 3.1 // @description 百度推广批量添加删除创意图片 // @author 张城铭 // @match http://fengchao.baidu.com/nirvana/main.html?userid=* // @grant none // ==/UserScript== var ideas,userInfo; function ajax(settings, callback) { if (!callback){ callback = settings.success; } if (!settings.dataType){ settings.dataType = 'json'; } if (!settings.type){ settings.type = 'post'; } settings.data.userid = userInfo.userid; settings.data.token = userInfo.token; settings.data.reqid = userInfo.reqid; settings.data.eventId = userInfo.eventId; if (callback){ settings.success = function(data){ if (data.status != 200){ alert(data.error); return false; } callback(data); }; } $.ajax(settings); } function getChecked(){ var checkeds = $('[type="checkbox"]:checked'); if (!checkeds.length){ alert('未选择'); return false; } return checkeds.slice(0, checkeds.length/2); } function del(){ var checkeds = getChecked() , segmentSigns = {} /*图片列表*/ var unitids = []; $.each(checkeds, function(k,v){ if (unitids[ideas[v.value].unitid] == 1){ return; } unitids[ideas[v.value].unitid] = 1; var unitid = ideas[v.value].unitid; ajax({ url:'http://fengchao.baidu.com/nirvana/request.ajax?path=vega/GET/unit/segments&reqid='+userInfo.reqid, data:{ path:'vega/GET/unit/segments', params:'{"unitid":'+unitid+',"pageNo":1,"pageSize":10,"segmentTypes":[100,101],"sources":[0,1],"auditStatus":[0,1,2,3]}' }, success:function(data){ $.each(data.data.listData, function(k,v){ if (segmentSigns[v.segmentSign+v.segmentType] == 1){ return; } segmentSigns[v.segmentSign+v.segmentType] = 1; li = $(' \ \ \ \ '); li.click(function(segmentType,segmentSign){ return function(){ $('#deljindu').css('width', '0%'); $('#deljindu span').text(''); var checkeds = getChecked(); $(this).css('display','none'); /*遍历删除*/ var unitids = []; var time = checkeds.length , jindu = 0 , count = 0; $.each(checkeds, function(k,v){ if (unitids[ideas[v.value].unitid] == 1){ --time return; } unitids[ideas[v.value].unitid] = 1; unitid = ideas[v.value].unitid; ajax({ url : 'http://fengchao.baidu.com/nirvana/request.ajax?path=vega/MOD/unit&reqid='+userInfo.userid, data : { path:'vega/MOD/unit', params:'{"unitid":['+unitid+'],"delUnitSegments":[{"unitid":'+unitid+',"segmentType":'+segmentType+',"segmentSign":"'+segmentSign+'"}]}' }, success:function(){ --time; var baifenbi = parseInt((count - time) * jindu)+'%'; $('#deljindu').css('width', baifenbi); $('#deljindu span').text(baifenbi); } }); }); count = time; jindu = 100/time; var t = setInterval(function(){ if(!time){ clearInterval(t); $('#deljindu').css('width', '100%'); $('#deljindu span').text('100% 处理成功'); } }, 2000); }; }(v.segmentType,v.segmentSign)); $('#segmentTypes_'+v.segmentType+' .row').append(li); }); } }); }); } function add(){ $('#addModal').modal('show'); var checkeds = getChecked(); $('#file').change(function(){ var img = document.createElement('img'); img.src = window.URL.createObjectURL(this.files[0]); img.onload = function(status){ return function(){ if (status){ status = 0; } else { return false; } var canvas = document.createElement("canvas"); canvas.height = this.height; canvas.width = this.width; canvas.getContext("2d").drawImage(this, 0, 0); var src = canvas.toDataURL("image/jpeg") , arr = src.split(',') , mime = arr[0].match(/:(.*?);/)[1] , bstr = atob(arr[1]) , n = bstr.length , u8arr = new Uint8Array(n); while (n--) { u8arr[n] = bstr.charCodeAt(n); } var formData = new FormData($('#uploadForm')[0]); formData.append('upfile', new File([new Blob([u8arr])], 'wwwwww.jpg', {type:mime})); /*7*/ ajax({ url: 'http://fengchao.baidu.com/venus/resource/multipleupload.do?userid='+userInfo.userid, type: 'POST', cache: false, data: formData, processData: false, contentType: false, success:function(data7){ /*裁剪*/ ajax({ url : 'http://fengchao.baidu.com/nirvana/request.ajax?path=vega/GET/scorePic&reqid='+userInfo.reqid, data : { path:'vega/GET/scorePic', params:'{"url":"'+data7.data[0].url+'"}' } }); /*1*/ ajax({ url : 'http://fengchao.baidu.com/nirvana/request.ajax?path=venus/CROP/picture&reqid='+userInfo.reqid, data : { path:'venus/CROP/picture', params:'{"originalImageUrl":"'+data7.data[0].url+'","sourceWidth":'+data7.data[0].width+',"sourceHeight":'+data7.data[0].height+',"leftPointX":0,"leftPointY":0,"maxTargetFileSize":64,"deviceType":'+($('#segmentType').val()==100?1:0)+',"opType":0}' }, success : function(data1){ /*3*/ ajax({ url : 'http://fengchao.baidu.com/nirvana/request.ajax?path=vega/ADD/resourceBase&reqid='+userInfo.reqid, data : { path:'vega/ADD/resourceBase', params:'[{"content":{"md5":"'+data7.data[0].md5+'","height":'+data7.data[0].height+',"width":'+data7.data[0].width+',"url":"'+data7.data[0].url+'"},"auditStatus":4,"score":7,"resourceType":2003,"source":9}]' }, success : function(data3){ /*5*/ ajax({ url : 'http://fengchao.baidu.com/nirvana/request.ajax?path=vega/ADD/cropImg&reqid='+userInfo.reqid, type: 'POST', data : { path:'vega/ADD/cropImg', params:'[{"resourceid":'+data3.data[0].resourceid+',"height":'+data7.data[0].height+',"width":'+data7.data[0].width+',"md5":"'+data3.data[0].md5+'","url":"'+data1.data.url+'","score":6,"source":9}]' }, success : function(data){ } }); } }); /*4*/ ajax({ url : 'http://fengchao.baidu.com/nirvana/request.ajax?path=vega/ADD/multiType/segment&reqid='+userInfo.reqid, data : { path:'vega/ADD/multiType/segment', params:'{"source":0,"data":["{\\"score\\":6,\\"picUrl\\":\\"'+data1.data.url+'\\",\\"segmentType\\":'+$('#segmentType').val()+',\\"rawPicUrl\\":\\"'+data7.data[0].url+'\\",\\"desc\\":\\"'+$('#desc').val()+'\\"}"]}' }, success : function(data4){ var unitids = []; var time = checkeds.length , jindu = 0 , count = 0; $.each(checkeds, function(k,v){ if (unitids[ideas[v.value].unitid] == 1){ --time; return; } unitids[ideas[v.value].unitid] = 1; ajax({ url : "http://fengchao.baidu.com/nirvana/request.ajax?path=vega/MOD/unit&reqid="+userInfo.reqid, data : { path:'vega/MOD/unit', params:'{"unitid":['+ideas[v.value].unitid+'],"addUnitSegments":[{"unitid":'+ideas[v.value].unitid+',"segmentType":'+$('#segmentType').val()+',"segmentSign":"'+data4.data[1].segmentSign+'","isSug":0}]}', }, success : function(){ --time; var baifenbi = parseInt((count - time) * jindu)+'%'; $('#addjindu').css('width', baifenbi); $('#addjindu span').text(baifenbi); } }); }); count = time; jindu = 100/time; var t = setInterval(function(){ if(!time){ clearInterval(t); $('#addjindu').css('width', '100%'); $('#addjindu span').text('100% 处理成功'); } }, 2000); } }); } }); } }); }; }(1); $('body').append(img); }); } (function() { // Your code here... //获取创意列表 setTimeout(function(){ userInfo = require("common/environment").getItem("userInfo"); userInfo.reqid = '4b534c46-553f-485a-0136-150477215230'; userInfo.eventId = '4b534c46-92f7-4606-e990-150492225935'; config = location.hash.match(/pageNo=(\d+)&pageSize=(\d+)/); config[3] = location.hash.match(/value%22%3A%22(\d+)%/)?location.hash.match(/value%22%3A%22(\d+)%/)[1]:undefined; config[4] = location.hash.match(/&planid=(\d+)/)?location.hash.match(/&planid=(\d+)/)[1]:undefined; ajax({ url : "http://fengchao.baidu.com/nirvana/request.ajax?path=vega/GET/mtllist/idea&reqid="+userInfo.reqid, data : { path:"vega/GET/mtllist/idea", params: '{"fields":["ideaid","unitid","unitname","planname","ideastat","clks","paysum","shows","trans","avgprice","clkrate","showpay","shadow_ideaid","shadow_ideastat","title","shadow_title","desc1","shadow_desc1","desc2","shadow_desc2","url","shadow_url","showurl","shadow_showurl","miurl","shadow_miurl","mshowurl","shadow_mshowurl","pausestat","activestat","deviceprefer","deviceOpt","shadow_deviceOpt","marker","adtype","crowdids","ideatag","showtag","bindSegCount","bindSegNotPassCount","bindSegPassCount","bindSegPassingCount","bidprefer"],"pageNo":'+config[1]+',"pageSize":'+config[2]+',"startTime":"2017-09-12","endTime":"2017-09-12","levelCond":{'+(config[4]?'"planid":'+config[4]:'"userid":'+userInfo.userid)+'}'+(config[3]?',"filters":[{"op":"in","field":"ideastat","values":["'+config[3]+'"]}]':'')+'}' }, success : function(data){ ideas = data.data.listData; //追加按钮 $('.ad-manage-operation-bar').append(' '); $('#add').click(add); $('.ad-manage-operation-bar').append(' '); $('#del').click(function(status){ return function(){ if (status){ del(); status = 0; } $('#delModal').modal('show'); } }(1)); } }); $('body').append('\ \ \ \ \ \ \ \ \\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \批量添加配图
\ \ \
批量删除配图
\ \ \ \移动端:
\ \ \ \ \ \ \桌面端:
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ '); },3000); })();