Last active
April 28, 2020 01:16
-
-
Save shugen002/74c9cd69be60b00759595a2d3903591e to your computer and use it in GitHub Desktop.
B站头像直传脚本
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var input= document.createElement("input"); | |
input.type="file"; | |
input.onchange=function(){ | |
if(input.files.length>0){ | |
var data= new FormData(); | |
data.append("dopost","save"); | |
data.append("Displayrank","10000"); | |
data.append("face",input.files[0]); | |
var xhr = new XMLHttpRequest(); | |
xhr.withCredentials = true; | |
xhr.open("POST","https://api.bilibili.com/x/member/web/face/update?csrf="+document.cookie.match(/bili_jct=(.+?);/)[1]); | |
xhr.onload=function(){ | |
var data=xhr.response; | |
try { | |
data=JSON.parse(data); | |
switch (data.code) { | |
case 0: | |
alert("更新成功,刷新页面即可"); | |
break; | |
case 40012: | |
alert("头像格式错误"); | |
break; | |
case 40013: | |
alert("头像大小不能超过2M"); | |
break; | |
default: | |
alert("未知返回"+xhr.response); | |
console.error(xhr.response,xhr); | |
break; | |
} | |
} catch (error) { | |
console.error(error,xhr,data); | |
alert("解析返回数据时出现错误,具体看console") | |
} | |
}; | |
xhr.onerror=function(e){ | |
console.error(err,xhr); | |
alert("请求出现错误,具体看console"); | |
}; | |
xhr.send(data); | |
}else{ | |
alert("请选择一个文件") | |
} | |
}; | |
input.click(); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:void (()=>{var a=document.createElement("input");a.type="file";a.onchange=function(){if(a.files.length>0){var b=new FormData();b.append("dopost","save");b.append("Displayrank","10000");b.append("face",a.files[0]);var c=new XMLHttpRequest();c.withCredentials=!!1;c.open("POST","https://api.bilibili.com/x/member/web/face/update?csrf="+document.cookie.match(/bili_jct=(.+?);/)[1]);c.onload=function(){var d=c.response;try{d=JSON.parse(d);switch(d.code){case 0:alert("更新成功,刷新页面即可");break;case 40012:alert("头像格式错误");break;case 40013:alert("头像大小不能超过2M");break;default:alert("未知返回"+c.response);console.error(c.response, c);break}}catch(e){console.error(e, c, d);alert("解析返回数据时出现错误,具体看console")}};c.onerror=function(e){console.error(e,c);alert("请求出现错误,具体看console");};c.send(b)}else{alert("请选择一个文件")}};a.click();})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment