將製作ejcees(中國象棋打譜程式)
Re: 將製作ejcees(中國象棋打譜程式)
代码: 全选
(function() {
const currentHash = window.location.hash;
if (currentHash) {
const targetLink = document.querySelector('a.ejcees');
if (targetLink && targetLink.href) {
const newUrl = targetLink.href + currentHash;
window.location.href = newUrl;
}
}
})();https://ejsoon.vip/
弈趣極光:享受思維樂趣
弈趣極光:享受思維樂趣
Re: 將製作ejcees(中國象棋打譜程式)
代码: 全选
(function() {
const currentHash = window.location.hash;
// 獲取當前完整 URL 並進行編碼
const encodedCurrentUrl = encodeURIComponent(window.location.href);
if (currentHash) {
const targetLink = document.querySelector('a.ejcees');
if (targetLink && targetLink.href) {
let baseUrl = targetLink.href;
// 判斷原連結是否已經帶有參數,決定用 '?' 還是 '&' 拼接
const separator = baseUrl.includes('?') ? '&' : '?';
// 拼接順序:原連結 + ?url=當前地址 + #Hash
const newUrl = `${baseUrl}${separator}url=${encodedCurrentUrl}${currentHash}`;
window.location.href = newUrl;
}
}
})();https://ejsoon.vip/
弈趣極光:享受思維樂趣
弈趣極光:享受思維樂趣
Re: 將製作ejcees(中國象棋打譜程式)
https://ejsoon.vip/
弈趣極光:享受思維樂趣
弈趣極光:享受思維樂趣
Re: 將製作ejcees(中國象棋打譜程式)
只需給出所要修改的地方,所有的代碼和注釋都要使用英文。
代码: 全选
根據您的要求,我找到了位於程式碼最下方的「Boot the app」部分。
您需要修改 `window.addEventListener('DOMContentLoaded', ...)` 回調函數中處理 `window.location.hash` 的邏輯。
以下是修改後的程式碼片段(所有程式碼與註釋均使用英文):
```javascript
// 1. Resolve initial state from localStorage or URL hash
const savedState = localStorage.getItem(STORAGE_KEY);
let initialHistory = null;
// --- Modified Section: Handle URL parameters and Hash ---
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('url')) {
baseUrl = decodeURIComponent(urlParams.get('url'));
}
if (window.location.hash) {
const hash = window.location.hash.substring(1);
if (hash) {
try {
initialHistory = parseUrlHash(hash);
} catch (e) {
console.error("Failed to parse hash:", e);
}
}
}
// Clean up the address bar: remove everything after '?' and '#'
if (window.location.search || window.location.hash) {
const cleanUrl = window.location.protocol + "//" + window.location.host + window.location.pathname;
window.history.replaceState({}, document.title, cleanUrl);
}
// --- End of Modified Section ---
if (!initialHistory && savedState) {
// ... (rest of the existing logic to load from savedState)
```
### 修改說明:
1. **獲取 `?url=`**:使用 `URLSearchParams` 從 `window.location.search` 中提取 `url` 參數並解碼賦值給 `baseUrl`。
2. **獲取 Hash**:保留原有的邏輯,從 `window.location.hash` 中提取並解析棋局數據。
3. **清除地址欄**:使用 `window.history.replaceState` 將地址欄重置為僅包含 `protocol`、`host` 和 `pathname` 的路徑,從而去掉所有的查詢參數(`?` 後面)和片段標識符(`#` 後面)。https://ejsoon.vip/
弈趣極光:享受思維樂趣
弈趣極光:享受思維樂趣
Re: 將製作ejcees(中國象棋打譜程式)
去掉問號及後面的字符。編輯評論後可以ctrl+enter。
https://ejsoon.vip/wp-content/uploads/2 ... 97775.html
- 附件
-
ejcees20260406url9997775.7z- (45.58 KiB) 已下载 1 次
https://ejsoon.vip/
弈趣極光:享受思維樂趣
弈趣極光:享受思維樂趣
在线用户
正浏览此版面之用户: 没有注册用户 和 1 访客
