tianyunperfect 2 năm trước cách đây
mục cha
commit
526cfaccea
2 tập tin đã thay đổi với 30 bổ sung27 xóa
  1. 28 7
      monkey/util.js
  2. 2 20
      simple-demo/location.html

+ 28 - 7
monkey/util.js

@@ -2,6 +2,27 @@ function sleep(time) {
     return new Promise((resolve) => setTimeout(resolve, time));
 }
 
+Date.prototype.format = function (fmt) {
+    var o = {
+        "M+": this.getMonth() + 1,                 //月份
+        "d+": this.getDate(),                    //日
+        "h+": this.getHours(),                   //小时
+        "m+": this.getMinutes(),                 //分
+        "s+": this.getSeconds(),                 //秒
+        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
+        "S": this.getMilliseconds()             //毫秒
+    };
+    if (/(y+)/.test(fmt)) {
+        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
+    }
+    for (var k in o) {
+        if (new RegExp("(" + k + ")").test(fmt)) {
+            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
+        }
+    }
+    return fmt;
+}
+
 async function getDom(sel) {
     for (let i = 0; i < 100; i++) {
         let dom = document.querySelector(sel);
@@ -188,12 +209,12 @@ function addJQ() {
  * @param text
  * @param uri
  */
-function copyTextToClipboard(text,uri) {
+function copyTextToClipboard(text, uri) {
     let copyFrom, agent, body;
 
     copyFrom = document.createElement("a");
-    copyFrom.setAttribute("id","target");
-    copyFrom.setAttribute("href",uri);
+    copyFrom.setAttribute("id", "target");
+    copyFrom.setAttribute("href", uri);
     copyFrom.innerHTML = text;
     agent = document.createElement("button");
     body = document.getElementsByTagName('body')[0];
@@ -201,16 +222,16 @@ function copyTextToClipboard(text,uri) {
     body.appendChild(agent);
     // 麻烦:无法传入'.btn'元素 我们可以创建一个btn作为代理
     let clipboard = new ClipboardJS(agent, {
-        target: function() {
+        target: function () {
             return document.querySelector('#target');
         }
     });
 
-    clipboard.on('success', function(e) {
+    clipboard.on('success', function (e) {
         console.log(e);
     });
 
-    clipboard.on('error', function(e) {
+    clipboard.on('error', function (e) {
         console.log(e);
     });
     agent.click();
@@ -228,4 +249,4 @@ function addLink(domSelector, link_str, linkUrl) {
     eleScript.innerHTML = link_str.replaceAll(" ", "&nbsp;");
     eleScript.href = linkUrl;
     document.querySelector(domSelector).appendChild(eleScript);
-}
+}

+ 2 - 20
simple-demo/location.html

@@ -3,32 +3,14 @@
 <head>
     <meta charset="UTF-8">
     <title>location</title>
+    <script src="https://git.tianyunperfect.cn/tianyunperfect/web-base/raw/master/monkey/util.js"></script>
     <script src="js/axios.min.js"></script>
 </head>
 <body>
 <textarea id="msg" style="width: 100%;" rows="10"></textarea>
 <h1 id="tip">2秒内发送</h1>
 <script>
-    Date.prototype.format = function (fmt) {
-        var o = {
-            "M+": this.getMonth() + 1,                 //月份
-            "d+": this.getDate(),                    //日
-            "h+": this.getHours(),                   //小时
-            "m+": this.getMinutes(),                 //分
-            "s+": this.getSeconds(),                 //秒
-            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
-            "S": this.getMilliseconds()             //毫秒
-        };
-        if (/(y+)/.test(fmt)) {
-            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
-        }
-        for (var k in o) {
-            if (new RegExp("(" + k + ")").test(fmt)) {
-                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
-            }
-        }
-        return fmt;
-    }
+
 
     let longitude;
     let latitude;