【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; /* 在小屏幕上进一步减小字体大小 */
    }
}
相关推荐
EndingCoder几秒前
配置 tsconfig.json:高级选项
linux·前端·ubuntu·typescript·json
木风小助理6 分钟前
JavaStreamAPI的性能审视,优雅语法背后的隐形成本与优化实践
java·前端·数据库
white-persist1 小时前
轻松抓包微信小程序:Proxifier+Burp Suite教程
前端·网络·安全·网络安全·微信小程序·小程序·notepad++
敲敲了个代码2 小时前
多标签页强提醒不重复打扰:从“弹框轰炸”到“共享待处理队列”的实战
java·前端·javascript·面试·架构
不想上班只想要钱3 小时前
动态类名在 <swiper-slide 的复制项中没有起作用的解决方法
前端·vue.js
weixin_395448913 小时前
tidl_import_mul_rmfsd_psd_u8_3x480x544_bise_raw_dynamic.txt
java·服务器·前端
Jinuss4 小时前
源码分析之React中updateContainerImpl方法更新容器
前端·react.js·前端框架
Mr Xu_4 小时前
Vue + Element Plus 实现前端导出 Excel 功能详解
前端·javascript·vue.js
仰泳之鹅4 小时前
【杂谈】使用Edge浏览器下载文件显示“Microsoft Defender SmartScreen 已阻止此不安全文件”的解决方法
前端·edge
万邦科技Lafite5 小时前
小红书评论数据一键获取,item_reviewAPI接口讲解
大数据·前端·数据库·chrome·电商开放平台