|
@@ -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(" ", " ");
|
|
|
eleScript.href = linkUrl;
|
|
|
document.querySelector(domSelector).appendChild(eleScript);
|
|
|
-}
|
|
|
+}
|