Wordpress pure code realizes Weibo map bed (upload pictures to Sina Weibo)

The benefits of using a stable map bed for general blog stations are self-evident, and Sina is also relatively stable, so it is relatively safe to use it. No more words, let's talk about how to achieve "Wordpress's pure code implementation of Weibo map bed (upload pictures to Sina Weibo)".

The following is the effect picture of the implementation of the Weibo map bed (uploading pictures to Sina Weibo) in WordPress pure code.
wordpress纯代码实现微博图床(将图片上传到新浪微博)

Js code

Package and call the following js code, or use the packaged“ http://pic.wosn.net/blog/170917/7HBc4H86La.js "。

  1. var
  2. UP= function (o, success,error,upload,x,file,A){
  3. ???? if ( typeof ? success==' function ')
  4. ???????? file=o;
  5. ???? else {
  6. ???????? if (! o.file)
  7. ???????????? return ? Console. log ('No files to upload have been passed in ')
  8. ???????? if (A=o.success)
  9. ???????????? success=A
  10. ???????? if (A=o.upload)
  11. ???????????? upload=A
  12. ???????? if (A=o.error)
  13. ???????????? error=A
  14. ????}
  15. ???? x= new ? XMLHttpRequest()
  16. ???? x.open('POST','https: //x.mouto.org/wb/x.php? up&_r='+Math.random(),1)
  17. ???? if (upload)
  18. ???????? x.upload.onprogress= function (e){
  19. ???????????? upload(e.loaded/e.total)
  20. ????????}
  21. ???? x.onload= function (r){
  22. ???????? r=JSON.parse(x.responseText)
  23. ???????? if (r.error&&error)
  24. ???????????? return ? error(r.error)
  25. ???????? if (r.pid&&success)
  26. ???????????? return ? success(r.pid)
  27. ????}
  28. ???? x.send(file)
  29. }

Implementation code

Put the following code into a separate article page to publish. Pay attention to the js address in line 5. Lazy people can not change it. In this way, you can try to upload it to see if it is ok.

PS: Be sure to log in to Weibo first.

  1. <div? class = "momll" ><style>
  2. momll-img{max-width:80%; display:block;
  3. }#Select {position: absolute; Z-index: 1; cursor: pointer; opacity: 0;} # Select a picture, # box {background: # b485e2; color:#FFF;display:block;height:40px;line-height:30px;text-align:center;}</style>
  4. <input? type= "file" ? id= Select Image >
  5. <div? id= "box" >Select or drag images to upload</div><img? id= Picture ><p? id= Text ></p><script? src= " http://pic.wosn.net/blog/170917/7HBc4H86La.js " ></script><script>
  6. Picture.onchange= function (){
  7. if (! this .files||! this .files[0])
  8. return ? Alert ('Error selecting file! ')
  9. ???? var
  10. ???? Picture file= this .files[0]
  11. if (Picture file. type. indexOf ('image ')= 0)
  12. return ? Alert ('This is not an image or audio! ')
  13. ???? UP (picture file, function (pid){
  14. ???????? Text.innerHTML=
  15. ???????? Picture. src='https: //ww2.sinaimg.cn/large/'+pid+?'. jpg'
  16. ????}, function (){
  17. ???????? Alert ('Error uploading file! ')
  18. ????}, function (Progress){
  19. ???????? Text. innerHTML=progress * 100+'%'
  20. ????})
  21. }
  22. </script></div>

Plug in recommendation

Recommend two browser plug-ins of "Minimal Pictorial Bed" and "Weibo is a good Pictorial Bed" to realize the function of Weibo Pictorial Bed (upload pictures to Sina Weibo). It's a great experience.

Google Plug in for Minimal Table: Click Download

Offline installation of Google plug-in: a new window is opened in Chrome, enter: chrome://extensions/ enter. Drag the downloaded crx file to the interface, release the mouse, and an installation prompt will pop up. Click OK to install.

PS: Code in the text is taken from https://www.mom1.cn/3107.html

AD Please click here to support Watson's blog!

 Watson Blog
  • This article is written by Published on September 17, 2017 03:45:57
  • This article is collected and sorted by the website of Mutual Benefit, and the email address for problem feedback is: wosnnet@foxmail.com , please keep the link of this article for reprinting: https://wosn.net/595.html

Comment