SOURCE

class Adminx {
    // 全屏指定对象
    fullScreen = function (obj) {
        var event = document.querySelector(obj);
        if (event.requestFullscreen) {
            event.requestFullscreen().then(function () {
                // console.log("success");
            }).catch(function (error) {
                // console.log(error);
            });
        } else {
            event.mozRequestFullScreen().then(function () {
                // console.log("success");
            }).catch(function (error) {
                // console.log(error);
            });
        }
    };
    // 退出全屏
    exitFullScreen = function () {
        if (document.exitFullscreen) {
            document.exitFullscreen().then(function () {
                // console.log("success");
            }).catch(function (error) {
                // console.log(error);
            });
        } else if (document.mozCancelFullScreen) {
            document.mozCancelFullScreen();
        }
    };
    // 判断对象、数组是否在另一个数组中存在
    inArray = function (search, array) {
        for (var i in array) {
            if (array[i] == search) {
                return true;
            }
        }
        return false;
    };
    // 判断字符串为空或者null
    isEmpty = function (str) {
        if (str == null || str == "") {
            return true;
        } else {
            return false;
        }
    };
    // 判断字符串为空 https://blog.csdn.net/K346K346/article/details/113182838
    isEmptyStrv2 = function (s) {
        if (s == null || s === '') {
            return true;
        }
        return false;
    };
    // 或 判断字符串为空
    isEmptyStr = function (s) {
        if (s == undefined || s === '') {
            return true;
        }
        return false;
    };
    // 判断字符串不为空
    isNotEmptyStr = function (s) {
        if (typeof s == 'string' && s.length > 0) {
            return true;
        }
        return false;
    };


    // 显示桌面通知,需要安全上下文(HTTPS)https://developer.mozilla.org/zh-CN/docs/Web/API/Notification
    showNotification(title, options) {
        // 初始化通知选项
        const image = "/information-desk.svg";
        const icon = "/hospitals.png";
        const sound = "/sound.wav";
        // 默认通知选项
        var options = {
            body: undefined ? undefined : options.body,
            dir: "" ? "rtl" : options.lang,
            lang: "" ? "zh-cn" : options.lang,
            tag: "Notification",
            icon: this.isEmpty(options.icon) ? icon : options.icon,
            image: this.isEmpty(options.image) ? image : options.image,
            // data: "Notification",
            // vibrate: window.navigator.vibrate(200), // https://stackoom.com/question/37ntZ
            renotify: true,
            requireInteraction: false,
            silent: false, // 暂不支持
            sound: undefined ? sound : options.sound,
            noscreen: false,
            sticky: true
        };
        // 检查浏览器是否支持桌面通知
        if (!("Notification" in window)) {
            console.log("This browser does not support desktop notification!");
            return;
            // 检查通知权限是否已经被授予;如果是的话,创建一条通知
        } else if (Notification.permission === "granted") {
            const n = new Notification(title, options);
            console.log(typeof (n.icon));
            // 当通知权限为默认时
        } else if (Notification.permission !== "denied") {
            // 请求通知 我们需要请求用户的许可
            Notification.requestPermission().then((permission) => {
                if (permission === "granted") {
                    new Notification(title, options);
                }
            });
        }
        // 如果用户拒绝,请尊重用户的选择
    };

    // 显示页面遮罩层
    showPageMask = function (options) { }

    // 打印页面对象 依赖PrintThis
    printPageObj = function (obj, options) { }

    // 保存文件内容为文本文档
    saveAsText = function (data, filename) {
        const urlObject = window.URL || window.webkitURL || window;
        const exportBlob = new Blob([data]);
        const saveLink = document.createElementNS("http://www.w3.org/1999/xhtml", "a");
        saveLink.href = urlObject.createObjectURL(exportBlob);
        saveLink.download = filename;
        saveLink.click();
    };

    // 保存对象为图像文件 依赖 html2canvas
    saveAsImage = function (obj, filename) { }

    // 保存对象为CSV文件
    saveAsCsv = function (obj, filename) { }

    // 保存对象为Excel文件
    saveAsExcel = function (obj, filename) { }

    // 保存对象为Word文件
    saveAsWord = function (obj, filename) { }

    // 保存对象为PDF文件
    saveAsPdf = function (obj, filename) { }

    // 生成随机IPv4地址
    randomIP = () => Array(4).fill(0).map((_, i) => Math.floor(Math.random() * 255) + (i === 0 ? 1 : 0)).join('.');

    // 生成随机的十六进制颜色 Hex
    randomHex = () => `#${Math.random().toString(16).slice(2, 8).padEnd(6, '0')}`;

    // 生成随机的十六进制颜色 Hex
    randomColor = () => `#${(~~(Math.random() * (1 << 24))).toString(16)}`;

    // 拷贝对象文本框中的内容到剪贴板
    copyInputToClipboard = function (obj, msg) {
        if (navigator.clipboard && window.isSecureContext) {
            console.info(true);
            navigator.clipboard.writeText().then(
                cliptext => document.querySelector(obj).value = JSON.stringify(cliptext)
            ).catch(
                error => console.error(error)
            );
        } else {
            console.info(false);
            const input = document.createElement('textarea');
            input.style.position = 'fixed';
            input.style.left = '-9999px';
            input.style.top = '-9999px';
            input.style.opacity = '0';
            input.value = JSON.stringify(document.querySelector(obj).value);
            document.body.appendChild(input);
            input.select();
            document.execCommand('copy');
            document.body.removeChild(input);
        }
    };

    // 手动触发对象播放提示音
    lectureAudio = function (obj, url) {
        const button = document.querySelector(obj);
        button, addEventListener('click', (e) => {
            e.preventDefault();
            const audio = new Audio(url);
            audio.play();
            audio.remove();
        });
    };

    // 自动触发播放提示音
    playAudio = function (url) {
        const audio = new Audio(url);
        // 系统允许自动播放
        audio.play().then(() => {
            audio.play();
            audio.remove();
        }).catch(error => {
            // 系统不允许自动播放时,使用iframe自动播放
            let iframe = document.createElement('iframe');
            iframe.src = url;
            iframe.setAttribute('allow', "autoplay 'src';fullscreen");
            document.body.appendChild(iframe);
            setInterval(() => {
                iframe.remove();
            }, 5000);
        }).finally(() => {
            audio.remove();
            // 收集反馈错误
            // resolove();
        });
    };
    // 获取当前文档页面链接
    documentPageLink = () => { return window.location.href; };

    // 页面标签栏滚动
    documentTitleScroll = function () { }

    // 文档全局水印 防截屏/拍照/录像泄密
    documentWatermark = function (str) {
        if (str == '' || str == undefined || str == null) {
            str = "Hygeia Group";
        }
        let can = document.createElement('canvas');
        let box = document.createElement('div');
        let now = new Date();
        now = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate() + ' ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds();
        box.style.position = 'fixed';
        box.style.width = '100%';
        box.style.height = '100%';
        box.style.zIndex = '-9999';
        document.body.appendChild(box);
        box.appendChild(can);
        can.width = 250;
        can.height = 250;
        can.style.display = 'none';
        can.style.background = "transparent";
        let ctx = can.getContext('2d');
        ctx.fillStyle = 'rgba(17,17,17,0.1)';
        ctx.rotate(-30 * Math.PI / 180);
        ctx.font = '11px Arial';
        ctx.textAlign = 'center';
        ctx.textBaseline = 'middle';
        ctx.fillText(str, can.width / 4, can.height / 2);
        ctx.fillText(now, can.width / 4, can.width / 2.5);
        // console.info(now);
        box.removeChild(can);
        const imageData = ctx.getImageData(0, 0, can.width, can.height);
        box.style.background = 'transparent';
        box.style.backgroundImage = 'url(' + can.toDataURL("image/png") + ')';
    };
    // 基于当前系统月份创建select对象
    createMonthSelect = function (obj) {
        // 获取当前系统日期  
        let currentDate = new Date();

        // 获取当前月份  
        let currentMonth = currentDate.getMonth() + 1; // 月份从0开始,因此需要+1  

        // 获取select对象元素
        const select = document.querySelector(obj);
        // 创建选项元素
        // let select = document.createElement("select");

        // 循环创建月份选项  
        for (let i = 0; i < 12; i++) {
            let option = document.createElement("option");
            option.value = i + 1; // 月份从1开始,因此需要+1  
            // 根据索引获取月份名称  
            option.text = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][i];

            // 默认选中当前系统时间的月份  
            if (i + 1 === currentMonth) {
                option.selected = true;
            }

            select.appendChild(option);
        }

        // 将选择列表添加到页面中,可选
        // document.body.appendChild(select);
    };
    // createMonthSelect("#month");
    // 基于当前系统日期创建select对象,并设置默认选中为当前系统日期
    createDateSelect = function (obj) {
        // 获取当前系统日期  
        let currentDate = new Date();
        // 获取当前月份
        let currentMonth = currentDate.getMonth() + 1; // 月份从0开始,因此需要+1
        // 获取当前月份总天数
        let days = new Date(currentDate.getFullYear(), currentMonth + 1, 0).getDate();
        // 获取当前日期
        let currentDay = currentDate.getDate();
        // 获取select对象元素
        const select = document.querySelector(obj);
        // 创建选项元素
        // let select = document.createElement("select");

        // 循环创建当前月份option选项
        for (let i = 0; i < days; i++) {
            let option = document.createElement("option");
            option.value = i; // 月份从1开始,因此需要+1  
            // 根据索引获取月份名称  
            option.text = i;

            // 默认选中当前系统时间的日期
            if (i === currentDay) {
                option.selected = true;
            }
        }
    }

    // 激活Enter键事件无障碍功能(当无法使用鼠标点击时,使用键盘Enter键代替鼠标点击操作)
    onkeydown = function (e) {
        if (e.keycode === 13) {
            document.activeElement.onclick(e);
        }
    };

    // 获取客户端经纬度坐标信息 GEO
    async getClientLocation() {
        if (!navigator.geolocation) {
            throw new Error("Geolocation is not supported by your browser!");
        }

        try {
            const options = {
                enableHighAccuracy: true,
                timeout: 5000,
                maximumAge: 0,
            };

            const position = await new Promise((resolve, reject) => {
                navigator.geolocation.getCurrentPosition(resolve, reject);
            });

            const longitude = position.coords.longitude;
            const latitude = position.coords.latitude;
            const accuracy = position.coords.accuracy;

            return {
                lng: longitude,
                lat: latitude,
                accuracy: accuracy
            };
        } catch (error) {
            throw new Error(error.message);
        }
    };

    getClientLocation2() {
        return new Promise((resolve, reject) => {
            if (!navigator.geolocation) {
                reject("Geolocation is not supported by your browser!");
            } else {
                function success(position) {
                    let longitude = position.coords.longitude;
                    let latitude = position.coords.latitude;
                    let accuracy = position.coords.accuracy;
                    resolve({
                        lng: longitude,
                        lat: latitude,
                        accuracy: accuracy
                    });
                }

                function error(error) {
                    reject(error);
                }

                navigator.geolocation.getCurrentPosition(success, error);
            }
        });
    };

    getClientLocation3() {
        if (!navigator.geolocation) {
            console.log("Geolocation is not supported by your browser!");
            return false;
        } else {
            // navigator.geolocation.getCurrentPosition(success, error);
            // success
            function success(position) {
                let longitude = position.coords.longitude;
                let latitude = position.coords.latitude;
                let accuracy = position.coords.accuracy;
                console.log(longitude, latitude, accuracy);
                return {
                    // 经度 东经 East(E)
                    lng: longitude,
                    // 纬度 北纬 North(N)
                    lat: latitude,
                    // 精度 Accuracy
                    accuracy: accuracy
                };
            }
            // error
            function error(error) {
                console.log(error);
            }
            navigator.geolocation.getCurrentPosition(success, error);
        }
    };

    // 屏蔽对象右键菜单
    disableContextMenu = function (obj) { }

    // 日期时间格式化
    dateToString = function (date, format) { }

    // 弹窗打开 依赖
    layerOpen = function (title, url, w, h) { }

    // 自定义显示弹窗 依赖 layer
    layerShow = function (title, url, w, h) { }

    // 全屏显示弹窗 依赖 layer
    layerFull = function (title, url) { }

    // 弹窗显示表格标签 依赖 layer
    layerTable = function (title, url, w, h) { }

    // 关闭弹窗 依赖 layer
    layerClose = function () { }
}
console 命令行工具 X clear

                    
>
console