惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Cyberwarzone
Cyberwarzone
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
小众软件
小众软件
Recent Announcements
Recent Announcements
博客园 - 三生石上(FineUI控件)
Security Archives - TechRepublic
Security Archives - TechRepublic
W
WeLiveSecurity
Cloudbric
Cloudbric
博客园 - 司徒正美
美团技术团队
N
News and Events Feed by Topic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
PCI Perspectives
PCI Perspectives
宝玉的分享
宝玉的分享
H
Help Net Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
Help Net Security
Help Net Security
Last Week in AI
Last Week in AI
S
Schneier on Security
N
News | PayPal Newsroom
B
Blog RSS Feed
L
LINUX DO - 最新话题
T
Troy Hunt's Blog
S
Secure Thoughts
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
L
Lohrmann on Cybersecurity
G
Google Developers Blog
Microsoft Azure Blog
Microsoft Azure Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Tenable Blog
S
Securelist
L
LangChain Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
I
InfoQ
H
Heimdal Security Blog
Cisco Talos Blog
Cisco Talos Blog
F
Full Disclosure
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
K
Kaspersky official blog
T
Tailwind CSS Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
阮一峰的网络日志
阮一峰的网络日志
C
Cisco Blogs

文轩夜话

09-AI:技术,人与怜悯 | 文轩夜话 OpenClaw · 我们为什么没必要为小龙虾(AI)焦虑? | 文轩夜话 2025 · 亲故何在,游子何归? | 文轩夜话 挽歌:第一次相逢与离别 | 文轩夜话 08-AGI:算力洪流与未坍缩的星光 | 文轩夜话 ChatRoom.js-在文章流中分享你的聊天记录 | 文轩夜话 逐光 · 启航:愿领航员畅行无阻 | 文轩夜话 2024 · 共赴一场烟火绚烂 | 文轩夜话 彼方的她:一场跨越时空的对话,一段孤寂宇宙的回响 | 文轩夜话 07-剧终:故事的开端与终末 | 文轩夜话 EasyPub-轻量Kindle电子书格式转换工具 | 文轩夜话 【破事水】-对于未来的前瞻于回望 | 文轩夜话 Windows工具-让你的Windows锦上添花,添了又添 | 文轩夜话 一枝红信出墙来-steam假激活入库 | 文轩夜话 飞跃13号房-对网瘾治疗披露与反抗 | 文轩夜话 06-时代造青年,还是青年造时代? | 文轩夜话 hexo + github-action持续集成 | 文轩夜话 友链区JavaScript组件-重做版 | 文轩夜话 一周年-忽而回望,不知光阴几何 | 文轩夜话 饿殍:明末千里行-岁大饥,人相食 | 文轩夜话 【总结】井冈山研学-了解历史,明见未来 | 文轩夜话 【多图警告】井冈山研学D3 | 文轩夜话 【多图警告】井冈山研学D2 | 文轩夜话 【多图警告】井冈山研学D1 | 文轩夜话 06-《你想活出怎样的人生》-高塔、苍鹭、少年、人生 | 文轩夜话 05-过程与结果 | 文轩夜话 霸凌行为-地狱空荡荡,恶魔在人间! | 文轩夜话 自建busuanzi统计API | 文轩夜话 04-写文章是为了什么? | 文轩夜话 03-早晚都得死,那我们为什么要活着? | 文轩夜话 02-成绩可以代表一切吗? | 文轩夜话 贵州消防栓事件的思考 | 文轩夜话 不要再带XXX回去了 | 文轩夜话 本站转移到云服务器了 | 文轩夜话 幻兽帕鲁-学习版-资源分享 | 文轩夜话 AI时代-汹涌而来 | 文轩夜话 十年之约-我与十年后的自己有一个约定 | 文轩夜话 01-我发现一件事 | 文轩夜话 image+onedrive 公益图床 | 文轩夜话 2023 · 年度总结 | 文轩夜话 00-少年:江湖走马,陪剑长行 | 文轩夜话 原神-米忽悠玩家预防针(厂商离谱行为)-世界树 | 文轩夜话 原神-李猛干语录MD版-世界树 Hello World | 文轩夜话
回声洞-开源html组件 | 文轩夜话
awaae001 · 2023-12-02 · via 文轩夜话

12/2/20231073 字6 min read

这是回声洞的代码

准确来说,灵感是是来自PLC2的回声洞,也可以说是我抄了他们的创意,在可不可以叫剽窃?

但是它们的回声洞是真的好玩,所以才有了这一个突发奇想的也不能被称之为作品的东西.

诶嘿!

下面是html主代码,注意,js不可以跨域。

所以:

请将js文件和.json文件放在博客的托管服务器上。

确保你的markdown编译器支持html代码内嵌。

一切正常的话

让我们开始吧


<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>格言显示</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      align-items: center;
      justify-content: center;
      min-height: 100vh;
      margin: 0;
    }
    #container {
      position: relative;
      border: 2px solid #dee2e6;
      padding: 20px;
      border-radius: 10px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    }
    #quote-container {
      border: 2px solid #3498db;
      padding: 10px;
      border-radius: 8px;
      margin-bottom: 20px;
      background-color: #f8f9fa;
      position: relative;
    }
    #quote {
      font-size: 1.5em;
    }
    #button-container {
      margin-top: 20px;
    }
    button {
      background-color: #28a745;
      color: #fff;
      padding: 10px 20px;
      font-size: 1em;
      border: none;
      border-radius: 4px;
      cursor: pointer;
    }
    #quote-count {
      margin-top: 10px;
      color: #6c757d;
    }
    #loading {
      display: none;
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-color: rgba(255, 255, 255, 0.8); /* 半透明白色背景 */
      justify-content: center;
      align-items: center;
      z-index: 1; /* 确保遮罩在最上层 */
      text-align: center; /* 将文本居中 */
    }
    .loader {
      border: 4px solid #f3f3f3;
      border-radius: 50%;
      border-top: 4px solid #3498db;
      width: 20px;
      height: 20px;
      animation: spin 1s linear infinite;
    }
    @keyframes spin {
      0% { transform: rotate(0deg); }
      100% { transform: rotate(360deg); }
    }
  </style>
</head>

<body>

  <div id="container">
    <div id="quote-container">
      <div id="loading">
        <div class="loader"></div>
        <div>加载中...</div>
      </div>
      <div id="quote">这里是回声显示的地方</div>
    </div>
    <div id="button-container">
      <button onclick="changeQuote()">再仔细听一下</button>
      <div id="quote-count">回声总数:0</div>
    </div>
  </div>

  <!-- 引入独立的JavaScript文件 -->
  <script src="https://blog.awaae001.top/script.js"></script>

</body>

</html>

这是主代码

html部分,下面是js部分

// script.js

async function loadQuotes() {
  try {
    const response = await fetch('https://example.com/mian.json', {
      method: 'GET',
      mode: 'cors',
    });

    if (!response.ok) {
      throw new Error(`HTTP error! Status: ${response.status}`);
    }

    const data = await response.json();
    return data.quotes;
  } catch (error) {
    console.error('获取格言时出错:', error.message);
    return [];
  }
}

let quotes;  // 存储加载的格言数组
let currentQuoteIndex;  // 当前显示的格言索引

// 初始化加载格言数据
loadQuotes().then(data => {
  quotes = data;
  updateQuoteCount(); // 初始化显示格言总数
  changeQuote();  // 初始显示格言
});

// 函数:切换显示随机格言
function changeQuote() {
  showLoading(); // 显示加载中动画

  // 模拟异步操作(例如加载新格言),这里使用setTimeout模拟1秒后的完成
  setTimeout(() => {
    // 生成一个随机索引
    const randomIndex = Math.floor(Math.random() * quotes.length);
    updateQuote(randomIndex);
    updateQuoteCount(); // 更新格言总数显示

    hideLoading(); // 隐藏加载中动画
  }, 640);
}

// 函数:更新显示的格言
function updateQuote(index) {
  const quoteElement = document.getElementById('quote');
  quoteElement.textContent = quotes[index];
}

// 函数:更新格言总数显示
function updateQuoteCount() {
  const quoteCountElement = document.getElementById('quote-count');
  quoteCountElement.textContent = '总格言数:' + quotes.length;
}

// 函数:显示加载中动画
function showLoading() {
  const loadingElement = document.getElementById('loading');
  loadingElement.style.display = 'block';
}

// 函数:隐藏加载中动画
function hideLoading() {
  const loadingElement = document.getElementById('loading');
  loadingElement.style.display = 'none';
}

其中,你需要将example.com的内容替换为你自己的域名

你还可以建立一个.json文件来存储格言

{
  "quotes": [
    "只要是石头,到哪里都不会发光的。",
    "没有,过不去的坎,只有过不完的坎。",
    "现在苦点没关系,人只要活着就一定会有好事,发生在别人身上。",
    "黑夜从来不会亏待晚睡的人,它会赐予你黑眼圈,和即将猝死的身体。",
    "看时间不是为了起床,而是看还能睡多久。",
    "你必须敢爱敢恨,才会发现你的爱恨,别人真的不在乎。",
    "春节假期,从跳过早午餐开始。",
    "又到了一切矛盾,都能用「大过年的」四个字,解决的时候了。",
    "遇到喜欢的人就勇敢追求,这样你才能知道,拒绝你的人远不止一个。",
    "秀恩爱的最好在中午秀,因为,早晚都会有报应。",
    "梦想还是要有的,万一见鬼了呢?",
    "好看的皮囊千篇一律,有趣的灵魂两百多斤。",
    "别看我挣的少,但是我省的多,昨天法拉利又省下两百多万。",
    "如果人生是一部电影,那你就是,中间弹出来的广告。",
    "出卖灵魂并不丢人,丢人的是,没能卖一个好价钱。",
    "不是我长大变傻了,而是傻子长大了"
  ]
}

大概的效果长这样