【chrome扩展】简 Tab (SimpTab)‘每日一句名言’样式

背景:最初参考“每日诗词”发现总是那几句,可以更换API接口完成“每日一句名言”

声明:本人不会ajax及ccs样式,非专业人士,借助CHATGPT代码生成完成。请友善交流。

每一句名言API: "https://api.xygeng.cn/openapi/one",

仅供参考:

效果图:

自定义脚本:

var tmpl = '<div class="jinrishici-bg"><div class="jinrishici"><div class="content"></div><div class="desc"><span class="dynasty"></span><span class="author"></span><span class="title"></span></div></div></div>';
$( 'body' ).append( tmpl )

var colaKey = 'e39Xj8x29YZn3k1712034292773hQhK2wGWcr';

$.ajax({
    type: "POST",
    url: "https://api.xygeng.cn/openapi/one",
    dataType: "json",
    success: function(response) {
        if (response.code === 200) {
            var origin = response.data.origin;
            var replacedOrigin = origin.replace(/《/g, "");
            var replacedOrigin = replacedOrigin.replace(/》/g, "");
            $( ".jinrishici .content" ).text( response.data.content );
            $( ".jinrishici .desc .dynasty" ).text('');
            $( ".jinrishici .desc .author" ).text('');
            $( ".jinrishici .desc .title" ).text('《' + replacedOrigin + '》');
            $( ".jinrishici" ).css( 'opacity', 1 );
        } else {
            console.error("一言获取失败:", response.msg);
        }
    },
    error: function(jqXHR, textStatus, errorThrown) {
        console.error("请求失败:", textStatus, errorThrown);
    }
});

自定义样式:

.jinrishici-bg {
    position: fixed;
    width: 90%;
    height: 100%;
    left: 0;
    top: 0;

    display: flex;
    justify-content: center;
    align-items: center;

    background: rgba(0, 0, 0, 0); /* 添加半透明背景 */
}

.jinrishici {
    color: #fff; /* 改变文字颜色为白色,以便在深色背景上更清晰 */
    opacity: 0;
    transition: all 500ms ease;
}

.jinrishici .content {
    font-size: 2vw; /* 使用视口宽度的百分比来设置字体大小 */
    width: 100%;
    height: 100%;
    padding-right: 5%;
    padding-left: 5%;
}

.jinrishici .desc {
    margin-top: 1em; /* 使用em单位来设置上外边距 */
    font-size: 2vw; /* 使用视口宽度的百分比来设置字体大小 */
    text-align: right;
}

/* 媒体查询:当屏幕宽度小于 600px 时 */
@media (max-width: 600px) {
    .jinrishici {
        opacity: 1;
    }
    .jinrishici .content {
        font-size: 5vw; /* 在小屏幕上进一步减小字体大小 */
    }
    .jinrishici .desc {
        font-size: 3.5vw; /* 在小屏幕上进一步减小字体大小 */
    }
}

相关推荐

  1. Chrome扩展之通信

    2024-04-04 21:00:05       51 阅读
  2. Chrome扩展开发纪要

    2024-04-04 21:00:05       56 阅读
  3. 话木马

    2024-04-04 21:00:05       48 阅读
  4. 话木马

    2024-04-04 21:00:05       35 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-04 21:00:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-04 21:00:05       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-04 21:00:05       82 阅读
  4. Python语言-面向对象

    2024-04-04 21:00:05       91 阅读

热门阅读

  1. MXNet库

    2024-04-04 21:00:05       34 阅读
  2. 从零学算法80

    2024-04-04 21:00:05       43 阅读
  3. 蓝桥杯算法基础(36)动态规划dp经典问题详解

    2024-04-04 21:00:05       30 阅读
  4. python笔记(11)序列

    2024-04-04 21:00:05       41 阅读
  5. Windows下Docker创建Mysql5.7

    2024-04-04 21:00:05       32 阅读
  6. 泛型(Generics)

    2024-04-04 21:00:05       36 阅读
  7. Lightroom Classic LRC安装教程介绍

    2024-04-04 21:00:05       44 阅读