location.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>location</title>
  6. <script src="https://git.tianyunperfect.cn/tianyunperfect/web-base/raw/master/monkey/util.js"></script>
  7. <script src="js/axios.min.js"></script>
  8. </head>
  9. <body>
  10. <textarea id="msg" style="width: 100%;" rows="10"></textarea>
  11. <h1 id="tip">2秒内发送</h1>
  12. <script>
  13. let longitude;
  14. let latitude;
  15. let status = false;
  16. navigator.geolocation.getCurrentPosition(function (position) {
  17. longitude = position.coords.longitude;
  18. latitude = position.coords.latitude;
  19. }, function (error) {
  20. alert(error.message);
  21. }, {
  22. timeout: 90000
  23. });
  24. setTimeout(() => {
  25. if (status === false) {
  26. sendMsg();
  27. }
  28. }, 2000)
  29. function setTip(str) {
  30. document.querySelector('#tip').innerHTML = str;
  31. }
  32. document.querySelector("#msg").onfocus = function () {
  33. status = true;
  34. setTip('点击发送');
  35. document.querySelector("#tip").onclick = function () {
  36. sendMsg();
  37. };
  38. };
  39. function sendMsg() {
  40. axios.post("https://api.tianyunperfect.cn/web_history/location_history", {
  41. "location_str": "",
  42. "location_xy": longitude + "-" + latitude,
  43. "msg": document.querySelector("#msg").innerHTML,
  44. "create_time": new Date().format('yyyy-MM-dd hh:mm:ss'),
  45. "update_time": new Date().format('yyyy-MM-dd hh:mm:ss')
  46. }).then(res => {
  47. if (res.data.code === 1) {
  48. // window.close();
  49. if (longitude === undefined) {
  50. setTip("发送成功,但是没有经纬度");
  51. } else {
  52. setTip("发送成功");
  53. }
  54. }
  55. });
  56. }
  57. </script>
  58. </body>
  59. </html>