【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; /* 在小屏幕上进一步减小字体大小 */
    }
}
相关推荐
xhxxx1 分钟前
prototype 是遗产,proto 是族谱:一文吃透 JS 原型链
前端·javascript
倾墨2 分钟前
Bytebot源码学习
前端
用户93816912553605 分钟前
VUE3项目--集成Sass
前端
S***H28316 分钟前
Vue语音识别案例
前端·vue.js·语音识别
啦啦9118861 小时前
【版本更新】Edge 浏览器 v142.0.3595.94 绿色增强版+官方安装包
前端·edge
蚂蚁集团数据体验技术1 小时前
一个可以补充 Mermaid 的可视化组件库 Infographic
前端·javascript·llm
LQW_home1 小时前
前端展示 接受springboot Flux数据demo
前端·css·css3
q***d1731 小时前
前端增强现实案例
前端·ar
IT_陈寒1 小时前
Vite 3.0 重磅升级:5个你必须掌握的优化技巧和实战应用
前端·人工智能·后端
JarvanMo2 小时前
Flutter 3.38 + Firebase:2025 年开发者必看的新变化
前端