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

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

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

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

仅供参考:

效果图:

自定义脚本:

javascript 复制代码
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);
    }
});

自定义样式:

css 复制代码
.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; /* 在小屏幕上进一步减小字体大小 */
    }
}
相关推荐
web守墓人32 分钟前
【前端】ikun-markdown: 纯js实现markdown到富文本html的转换库
前端·javascript·html
Savior`L38 分钟前
CSS知识复习5
前端·css
许白掰39 分钟前
Linux入门篇学习——Linux 工具之 make 工具和 makefile 文件
linux·运维·服务器·前端·学习·编辑器
中微子5 小时前
🔥 React Context 面试必考!从源码到实战的完整攻略 | 99%的人都不知道的性能陷阱
前端·react.js
中微子6 小时前
React 状态管理 源码深度解析
前端·react.js
加减法原则7 小时前
Vue3 组合式函数:让你的代码复用如丝般顺滑
前端·vue.js
yanlele8 小时前
我用爬虫抓取了 25 年 6 月掘金热门面试文章
前端·javascript·面试
lichenyang4538 小时前
React移动端开发项目优化
前端·react.js·前端框架
你的人类朋友8 小时前
🍃Kubernetes(k8s)核心概念一览
前端·后端·自动化运维
web_Hsir8 小时前
vue3.2 前端动态分页算法
前端·算法