-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from noriyotcp/refactor-20241006
refactor 20241006
- Loading branch information
Showing
7 changed files
with
47 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export const setupBackToHotkeys = () => { | ||
// Get all <a> elements with the class .back-to-top | ||
const backToTopLinks = document.querySelectorAll("a.back-to-top"); | ||
|
||
backToTopLinks.forEach((link) => { | ||
const href = link.getAttribute("href"); | ||
|
||
// Regular expression to get everything after # | ||
const match = href.match(/#(.+)/); | ||
|
||
if (match && match[1]) { | ||
const content = match[1]; | ||
|
||
let hotkeyValue; | ||
if (/^\d/.test(content)) { | ||
// If it starts with a number, extract only the numbers and process them | ||
const numbers = content.replace(/-/g, ""); | ||
hotkeyValue = "b " + numbers.split("").join(" "); | ||
} else if (content === "page-title") { | ||
// If it is page-title, assign `b t` as the hotkey | ||
hotkeyValue = "b t"; | ||
} | ||
|
||
link.setAttribute("data-hotkey", hotkeyValue); | ||
} | ||
}); | ||
} |