登录
const copyToClipboard = (text) => navigator.clipboard.writeText(text);
copyToClipboard("Hello World");
const clearCookies = document.cookie.split(';').forEach(cookie => {
document.cookie = cookie.replace(/^ +/, '').replace(/=.*/, `=;expires=${new Date(0).toUTCString()};path=/`)
});
const getSelectedText = () => window.getSelection().toString();
getSelectedText();
const goToTop = () => window.scrollTo(0, 0);
goToTop();
const scrolledToBottom = () => document.documentElement.clientHeight + window.scrollY >= document.documentElement.scrollHeight;
const isTabInView = () => !document.hidden;
const isAppleDevice = () => /Mac|iPod|iPhone|iPad/.test(navigator.platform);
isAppleDevice();
// 判断是否为微信手机端的内部浏览器中打开的
export function isWeChat() {
return /MicroMessenger/i.test(window.navigator.userAgent) && /Mobile/i.test(window.navigator.userAgent)
}
const trueTypeOf = (obj) => Object.prototype.toString.call(obj).slice(8, -1).toLowerCase();
trueTypeOf('');
// string
// number
// undefined
// null
// object
// array
// number
// function
const isEmpty = obj => Reflect.ownKeys(obj).length === 0 && obj.constructor === Object;
const randomString = () => Math.random().toString(36).slice(2);
randomString();
const stripHtml = html => (new DOMParser().parseFromString(html, 'text/html')).body.textContent || '';
const isNotEmpty = arr => Array.isArray(arr) && arr.length > 0;
isNotEmpty([1, 2, 3]);