包含标签 JavaScript

使用Javascript TSS和Highlights构建一个文本阅读器

原文:https://jsdev.space/tts-sentence-reader/ 翻译:yingyu5658 yingyu5658@outlook.com

在这篇文章中,我们将构建一个简单的Web工具来探究Text-toSpeech(TTS)在JavaScript中是如何工作的。我们也将深入研究句子级高亮的工作逻辑。这两项功能经常结合在一起使用,以走到浏览器中打造无障碍的动态阅读体验。

- 阅读剩余部分 -

osu!APIv1请求示例

前言

本文章使用Nodejs环境做演示。请求用户数据。代码中的APIKEY要在osu官网‬申请。

const API_URL = "osu.ppy.sh";
const init = {
    k: "YOUR_API_KEY",
    type: "string",
    u: "kyzzz5658",
};

const https = require("https");

// 将参数序列化为查询字符串
const query = new URLSearchParams(init);
const options = {
    hostname: API_URL,
    method: "GET",
    path: `/api/get_user?${query}` // 附加参数
};

const req = https.request(options, (res) => {
    let data = '';
    res.on('data', (chunk) => data += chunk);
    res.on('end', () => {
        try {
            console.log(JSON.parse(data[0].username));
        } catch (e) {
            console.error('JSON 解析失败:', e);
        }
    });
});

// 错误处理
req.on('error', (err) => {
    console.error('请求失败:', err.code);
});

输出:

- 阅读剩余部分 -

Nodejs环境下控制台拼接字符串输出有undefind

今天在Nodejs环境下搓小工具,控制台输出拼接字符串时,发现有undefind,代码如下:

const date = new Date();
const year = date.getFullYear();
const month = date.getMonth();
const day = date.getDate();
const hour = date.getHours();
const minute = date.getMinutes();
const second = date.getSeconds();
const logTime = `[${year}-${month}-${day} ${hour}:${minute}:${second}] `;

class GenerateLog {
  static log() {
    process.stdout.write(logTime);
  }
}

console.log(GenerateLog.log() + "log output on the console");

输出确是这样:

- 阅读剩余部分 -