From 893a8ca9549a29e20c632b016e0b91b4646af300 Mon Sep 17 00:00:00 2001 From: Cp0204 Date: Wed, 1 May 2024 17:20:39 +0800 Subject: [PATCH] add MOD: Add hostname to title --- README.md | 1 + README_CN.md | 1 + app/mod/add-hostname-to-title/mod.js | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 app/mod/add-hostname-to-title/mod.js diff --git a/README.md b/README.md index 99598eb..c84b398 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ In addition, you can access the files in the `/DATA/AppData/casamod/icon` direct | Name | Description | Author | | ---- | ----------- | ------ | +| add-hostname-to-title | Add hostname to title ➕ | Cp0204 | | small-app-icon | Smaller app icons 🤏 | Cp0204 | | allow-modify-image | Allow modify image settings ✏️ | Cp0204 | | add-widget-quotable | Add Quotable widget 💬 | Cp0204 | diff --git a/README_CN.md b/README_CN.md index c6a0f47..533b422 100644 --- a/README_CN.md +++ b/README_CN.md @@ -42,6 +42,7 @@ | 名称 | 功能描述 | 作者 | | --- | -------- | ---- | +| add-hostname-to-title | 添加主机名到网页标题 ➕ | Cp0204 | | small-app-icon | 更小的应用图标 🤏 | Cp0204 | | allow-modify-image | 允许编辑镜像设置 ✏️ | Cp0204 | | add-widget-quotable | 增加一言小部件 💬 | Cp0204 | diff --git a/app/mod/add-hostname-to-title/mod.js b/app/mod/add-hostname-to-title/mod.js new file mode 100644 index 0000000..310aa91 --- /dev/null +++ b/app/mod/add-hostname-to-title/mod.js @@ -0,0 +1,25 @@ +// name: add-hostname-to-title +// author: Cp0204 +// date: 2024-05-01 +// description: 添加访问地址到网页标题,用以区分多个主机;因为没有后端获取主机名,所以默认用访问地址;你也可以直接修改本 js 用自定义字符串。 +// description: Add the access address to the page title to differentiate between multiple hosts; since there is no backend to get the hostname, the default is the access address; you can also modify this js directly to use a custom string. + +(function () { + // 自定义字符 + // Custom Strings + let additionalTitle = ""; + + if (additionalTitle == "") { + const hostname = window.location.hostname; + const port = window.location.port; + if (hostname) { + additionalTitle += hostname; + if (port) { + additionalTitle += ":" + port; + } + } + } + if (additionalTitle != "") { + document.title = document.title + " - " + additionalTitle; + } +})(); \ No newline at end of file