//========================= 显示当前时间 =========================
function CurentTime() {
var now = new Date();
var year = now.getFullYear(); //年
var month = now.getMonth() + 1; //月
var day = now.getDate(); //日
var hh = now.getHours(); //时
var mm = now.getMinutes(); //分
var ss = now.getSeconds(); //秒
var hs = now.getMilliseconds();
clock = hh + ":" + mm + ":" + ss + ":" + hs;
clock2 = year + '-' + month + '-' + day + ' ' + hh + ":" + mm + ":" + ss
return(clock2);
}
var list = [1, 2, 3, 4, 5]
// for(var i = 0; i < 5; i++) {
// // (function(i) {
// // setTimeout(function() {
// // console.log(CurentTime())
// // }, (i + 1) * 3000);
// // })(i)
// setTimeout(function() {
// console.log(CurentTime())
// setTimeout(function() {
// console.log(CurentTime())
// console.log('--------------------')
// }, 2000);
// }, (i + 1) * 3000);
// }
// function upLoadPic(imgData){
// if (typeof imgData == 'string' && imgData.length > 2) {
// console.log('【设置群头像 成功】:', imgData.length)
// } else {
// console.log(typeof(imgData))
// console.log(imgData.length)
// }
// }
// upLoadPic('6')
function Start(){
console.log('【666】')
}
var nowList = ['1', '2', '3', '4', '5']
function Test(nowList){
var list = nowList
for(i = 0, len = list.length; i < len; i++) {
(function(i) {
setTimeout(function() {
console.log('删除前list',list)
console.log('删除前nowList',nowList)
list.shift()
console.log(list)
console.log(list.length)
console.log('--------------------')
if (list.length == 0) {
Start()
}
}, (i + 1) * 3000);
})(i)
}
}
// Test(nowList)
function returnJson() {
var errCount = 0
var errJson = {}
errJson['status'] = 200
try {
throw new Error("errTest1")
} catch (err) {
errCount += 1
errJson['err1'] = String(err)
console.log('err: ', String(err))
}
console.log('--------------------')
try {
throw new Error("errTest2")
} catch (err) {
errCount += 1
errJson['err2'] = String(err)
console.log('err: ', String(err))
// alert(err.name + ": " + err.message)
}
console.log('--------------------')
if (errCount > 0) {
console.log('失败')
console.log(errJson)
} else {
console.log('成功')
console.log(errJson)
}
}
// returnJson()
async function WaitTime(sleepTime) {
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
var waitTime = 2
if (typeof sleepTime == 'number' && sleepTime > 0) {
waitTime = sleepTime
}
for(i = 0, len = nowList.length; i < len; i++) {
await sleep(waitTime * 1000).then(console.log('【sleep结束】'));
console.log('当前:',i)
}
}
// WaitTime(2)
//========================= 获取主页联系方式 =========================
var contactObj = {};
var otherLinksArray = [];
var str = "简介\n查看全部\nTrain with your favorite instructors from Daily Burn, Grokker, Aaptiv, Jillian Michaels, FitFusion & more ����\nhttp://sweatfactor.com\n154,104位用户赞了\n156,753位用户关注了\n+233 59 290 1252\nhttp://www.mikedfitness.com/\nbiz.mikedfitness@gmail.com\n健康与保养网站 · 企业家 · 健身教练\nhttp://instagram.com/mikedfitness\nhttp://twitter.com/mikedonavanik\nhttp://youtube.com/mikedfitness\nhttps://www.snapchat.com/add/mikedfitness\n照片\n查看全部\n视频\n查看全部\n0:27\ncurrent life status ������ instagram.com/mikedfitness snapchat.com/add/mikedfitness (original videos courtesy of instagram.com/breadfaceblog)\n11 万\n11 万\n5,583.5 万次播放\n \n · 5年前\n公共主页信息公示\n查看全部\nFacebook 会公示有助于你了解公共主页用途的信息,你可以据此了解内容管理与发布人员的操作记录。\n公共主页创建日期:2011年6月28日\n借助 Facebook 发展业务\n展示你的业务内容、创建广告并与客户或支持者建立联系。\n创建公共主页\n隐私权政策\n \n · 服务条款\n \n · 广告\n \n · Ad Choices \n \n · Cookie\n \n · 更多\n \n · Facebook © 2021";
var contactTextArray = str.split('\n');
var phoneReg = /\+[\d]/;
var emailReg = /[\w]@[\w]/;
for (var i=0; i<contactTextArray.length; i++) {
if(phoneReg.test(contactTextArray[i])) {
contactObj['phone'] = contactTextArray[i]
} else if (emailReg.test(contactTextArray[i])) {
contactObj['email'] = contactTextArray[i]
} else if (contactTextArray[i].substr(0, 4) == "http") {
if (contactTextArray[i].includes("twitter.com")) {
contactObj['twitter'] = contactTextArray[i]
} else if (contactTextArray[i].includes("youtube.com")) {
contactObj['youtube'] = contactTextArray[i]
} else if (contactTextArray[i].includes("instagram.com")) {
contactObj['instagram'] = contactTextArray[i]
} else {
otherLinksArray.push(contactTextArray[i])
}
}
}
if (otherLinksArray.length > 0) {
contactObj['otherLinks'] = otherLinksArray;
}
//console.log(contactObj)
//========================= facebook获取用户信息方法 =========================
var testStr = '72,052人對此讚好';
var countReg = /([\d]{1,3}([\,][\d]{1,3})*)/;
console.log(testStr.match(countReg));
console.log(testStr.match(countReg)[0].replace(/,/g, ''))
function getContact(messageid) {
//联系方式json
var contactObj = {};
//其他链接
var otherLinksList = '';
var contactText = document.querySelector('[class="lpgh02oy"]').innerText;
var contactTextArray = contactText.split('\n');
// var phoneReg = /\+[\d]/;
var phoneReg = /(?<!\w)\+[\d]/;
var emailReg = /[\w]@[\w]/;
var likeReg = /(like|赞|讚)/;
var followReg = /(follow|关注|追蹤)/;
var countReg = /([\d]{1,3}([\,][\d]{1,3})*)/;
contactObj['name'] = document.querySelector('[class="bi6gxh9e aov4n071"]').innerText;
contactObj['website'] = document.URL;
for (var i=0; i<contactTextArray.length; i++) {
if(phoneReg.test(contactTextArray[i])) {
contactObj['phone'] = contactTextArray[i];
} else if (emailReg.test(contactTextArray[i])) {
contactObj['email'] = contactTextArray[i];
} else if (likeReg.test(contactTextArray[i])) {
var likeCountArr = contactTextArray[i].match(countReg);
setTimeout(function() {
console.log(likeCountArr[0]);
contactObj['likeCount'] = likeCountArr[0].replace(/,/g, '');
}, 1000);
//contactObj['likeCount'] = contactTextArray[i].match(countReg)[0].replace(/,/g, '');
} else if (followReg.test(contactTextArray[i])) {
var followCountArr = contactTextArray[i].match(countReg);
setTimeout(function() {
console.log(followCountArr[0]);
contactObj['followCount'] = followCountArr[0].replace(/,/g, '');
}, 1000);
//contactObj['followCount'] = contactTextArray[i].match(countReg)[0].replace(/,/g, '');
} else if (contactTextArray[i].substr(0, 4) == "http") {
if (contactTextArray[i].includes("twitter.com")) {
contactObj['twitter'] = contactTextArray[i];
} else if (contactTextArray[i].includes("youtube.com")) {
contactObj['youtube'] = contactTextArray[i];
} else if (contactTextArray[i].includes("instagram.com")) {
contactObj['instagram'] = contactTextArray[i];
} else {
//otherLinksArray.push(contactTextArray[i]);
if (otherLinksList == '') {
otherLinksList = contactTextArray[i];
} else {
otherLinksList += ',' + contactTextArray[i];
};
};
};
};
var personPagesArray = document.querySelector('[class="lpgh02oy"]').querySelectorAll('a');
for (var i=0; i<personPagesArray.length; i++) {
if(personPagesArray[i].href.includes("http") && personPagesArray[i].href.includes("twitter.com")) {
if (contactObj.hasOwnProperty('twitter') == false) {
contactObj['twitter'] = personPagesArray[i].href
};
} else if(personPagesArray[i].href.includes("http") && personPagesArray[i].href.includes("youtube.com")) {
if (contactObj.hasOwnProperty('youtube') == false) {
contactObj['youtube'] = personPagesArray[i].href
};
} else if(personPagesArray[i].href.includes("http") && personPagesArray[i].href.includes("instagram.com")) {
if (contactObj.hasOwnProperty('instagram') == false) {
contactObj['instagram'] = personPagesArray[i].href
};
};
};
if (otherLinksList != '') {
contactObj['otherLinks'] = otherLinksList;
};
console.log(contactObj);
};
//========================= while循环延时 =========================
const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
// return new Promise(resolve => {
// setTimeout(() => {
// resolve()
// }, millisecond)
// })
}
const doSomething = async () => {
var i = 0;
while (i < 5) {
console.log(i)
i++;
await sleep(2000)
}
console.log('循环结束')
}
// doSomething()
function DeleteGroups() {
setTimeout( function() {
const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
const doSomething = async () => {
for (var i=0;i<5;i++) {
console.log(i);
await sleep(2000);
}
console.log('循环结束')
}
doSomething()
},3000);
};
// DeleteGroups()
//=============================回调函数==========================
var obj = {
name:1,
age:2,
sex:3
};
console.log('========== 对象长度 ==========')
console.log(Object.getOwnPropertyNames(obj).length)
console.log(Object.keys(obj).length)
console.log('========== 对象第一个value值 ==========')
console.log(Object.values(obj)[0])
console.log(obj[Object.keys(obj)[0]])
console.log('========== 对象第一个key值 ==========')
console.log(Object.keys(obj)[0])
console.log('========== 循环输出key ==========')
for(var key in obj){
console.log(key);
}
//=======================================================
var contactsArray = [2,3]
for (var i = 1; i < 4; i++) {
// if (contactsArray.indexOf(i) != -1) {
// console.log(i)
// }
if (contactsArray.includes(i)) {
console.log(i)
}
}
function toast(str) {
showMessage(str)
}
function getUserEmail() {
$.ajax({
type: "get",
url: "https://thirddevexternal.laifuyun.com:443/linkedin/getEmail",
headers: {
'accesstoken': 'q265XBMIJSUYVUBc'
},
data:{
memberId: '10637490'
},
//contentType: "application/json",
dataType: "json",
success: function(data){
console.log(data);
},
error:function(err){
console.log(err);
//toast("获取图表数据接口调用失败!")
}
})
}
// getUserEmail()
function getUserEmail2() {
// axios({
// method:"get",
// url:"https://thirddevexternal.laifuyun.com:443/linkedin/getEmail?memberId=10637490",
// //data:{"action":"refreshToken"},
// headers:{
// accessToken: "q265XBMIJSUYVUBc"
// }
// })
axios
.get("https://thirddevexternal.laifuyun.com:443/linkedin/getEmail?memberId=10637490", {
headers:{
accessToken: "q265XBMIJSUYVUBc"
}
})
.then(response => {
console.log("获取用户邮箱成功!: " + response.data);
})
.catch(error => {
console.log("获取用户邮箱失败!: " + error);
});
}
// getUserEmail2()
//=========================================================
/**
* uri 打开客户端的uri
* failCb 打开客户端失败回调
* successCb 打开客户端成功回调
*/
function openUriWithInputTimeoutHack(uri, failCb, successCb) {
let target = document.createElement('input')
target.style.width = '0'
target.style.height = '0'
target.style.position = 'fixed'
target.style.top = '0'
target.style.left = '0'
document.body.appendChild(target)
target.focus();
var handler = _registerEvent(target, "blur", onBlur);
console.log('focus')
function onBlur() {
console.log('blur')
successCb && successCb()
handler.remove()
clearTimeout(timeout)
document.body.removeChild(target)
};
//will trigger onblur
location.href = uri
// Note: timeout could vary as per the browser version, have a higher value
var timeout = setTimeout(function () {
console.log('setTimeout')
failCb && failCb()
handler.remove()
document.body.removeChild(target)
}, 1000);
}
function _registerEvent(target, eventType, cb) {
if (target.addEventListener) {
target.addEventListener(eventType, cb);
return {
remove: function () {
target.removeEventListener(eventType, cb);
}
};
} else {
target.attachEvent(eventType, cb);
return {
remove: function () {
target.detachEvent(eventType, cb);
}
};
}
}
// 测试
// let protocalUrl = `MXFacebookManager://`
// openUriWithInputTimeoutHack(protocalUrl, () => {
// console.log('检测到,未安装客户端')
// }, () => {
// // 浏览器弹窗提示
// console.log('检测到:已安装了客户端')
// })
//=======================时间格式化=======================
function dateFormat(fmt, date) {
let ret;
const opt = {
"Y+": date.getFullYear().toString(), // 年
"m+": (date.getMonth() + 1).toString(), // 月
"d+": date.getDate().toString(), // 日
"H+": date.getHours().toString(), // 时
"M+": date.getMinutes().toString(), // 分
"S+": date.getSeconds().toString() // 秒
// 有其他格式化字符需求可以继续添加,必须转化成字符串
};
for (let k in opt) {
ret = new RegExp("(" + k + ")").exec(fmt);
if (ret) {
fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
};
};
return fmt;
}
// let date = new Date()
console.log('获取当前时间格式化:', dateFormat("YYYY-mm-dd HH:MM", new Date()))
//=======================月份加减方法======================
//月份,在原有的日期基础上,增加 months 月份,默认增加1月
function calcMonth(date,months){
if(months==undefined||months=='')
months=1;
var date=new Date(date);
date.setMonth(date.getMonth()+months);
var month=date.getMonth()+1;
var day=date.getDate();
// return date.getFullYear()+'-'+getFormatDate(month)+'-'+getFormatDate(day);
if (month == 12) {
return (date.getFullYear() + 1) + '-01-01'
} else {
return date.getFullYear() + '-' + getFormatDate(month + 1) + '-01'
}
}
function getFormatDate(arg) {
if (arg == undefined || arg == '') {
return '';
}
var re = arg + '';
if (re.length < 2) {
re = '0' + re;
}
return re;
}
console.log('月份计算:',calcMonth('2022-12-21', -24))
console