MaxHome增强插件

随机每日一言、工作时长统计

当前为 2024-11-08 提交的版本,查看 最新版本

// ==UserScript==
// @name         MaxHome增强插件
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  随机每日一言、工作时长统计
// @author       luc
// @match        http://maxvision.eicp.net:52800/maxhome/*
// @icon         http://maxvision.eicp.net:52800/maxhome/ui/images/logo.png
// @grant        GM_xmlhttpRequest
// @grant        GM_addStyle
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    const textElement = document.querySelector('.header-marquee-item1');

    GM_xmlhttpRequest({
        method: 'GET',
        url: 'https://api.codelife.cc/yiyan/random?lang=cn',
        onload: function(response) {
            const data = JSON.parse(response.responseText);
            if (data.code === 200) {
                const hitokoto = data.data.hitokoto;
                console.log(hitokoto);
                if (textElement) {
                    textElement.textContent = hitokoto;

                    const elementWidth = textElement.offsetWidth;
                    const parentWidth = textElement.parentElement.offsetWidth;

                    if (elementWidth > parentWidth) {
                        textElement.style.whiteSpace = 'nowrap';
                        textElement.style.overflow = 'hidden';
                        textElement.style.textOverflow = 'ellipsis';
                        textElement.style.display = 'inline-block';
                        textElement.style.animation = 'marquee 20s linear infinite';

                        GM_addStyle(`
                            @keyframes marquee {
                                0% { transform: translateX(100%); }
                                100% { transform: translateX(-100%); }
                            }
                        `);
                    } else {
                        textElement.style.animation = 'none';
                    }
                }
            }
        }
    });

    window.onload = function() {
        var mymeetingElement = document.querySelector('.appcheckcount');
        if (mymeetingElement) {
            const startDate = new Date('2021-04-27');
            const currentDate = new Date();
            const timeDiff = currentDate - startDate;
            const daysDiff = Math.floor(timeDiff / (1000 * 3600 * 24));

            GM_addStyle(`
    .large-text {
        font-size: 36px;
        font-weight: bold;
    }
    .small-text {
        font-size: 20px;
        font-weight: normal;
    }
    .right_applicat {
        margin-top: 20px;
    }
`);

            const newHtml = `
<div class="mymeeting">
    <div class="mymeeting_top">
        <span class="line"></span>
        <span class="text">在Maxvision已经</span>
    </div>
    <div class="myhuiyi">
        <div class="nonediv">
            <span class="large-text">${daysDiff}</span>
            <span class="small-text">天</span>
        </div>
    </div>
</div>
`;
            mymeetingElement.insertAdjacentHTML('beforebegin', newHtml);

            var applicatListElement = document.querySelector('.applicat_list');
    if (applicatListElement) {
        const newHtml = `
            <a href="http://it.maxvision.tech:8020/download" target="_blank">
                <div class="item">
                    <div class="image" style="position: relative">
                        <img src="http://it.maxvision.tech:8020/favicon.ico" alt="">
                    </div>
                    <div class="text">文件服务器</div>
                </div>
            </a>
        `;
        applicatListElement.insertAdjacentHTML('beforeend', newHtml);
    }
        }
    };
})();