mirror of
https://github.com/placeAtlas/atlas.git
synced 2024-12-29 08:44:33 +01:00
Extract needed values when pasting Discord and subreddit links
If possible
This commit is contained in:
parent
a95d21c77c
commit
be9e74d838
1 changed files with 21 additions and 1 deletions
|
@ -48,7 +48,7 @@ const wikiGroup = document.getElementById("wikiGroup");
|
|||
const exportArea = document.getElementById("exportString");
|
||||
|
||||
const subredditPattern = /^(?:(?:(?:(?:(?:https?:\/\/)?(?:(?:www|old|new|np)\.)?)?reddit\.com)?\/)?[rR]\/)?([A-Za-z0-9][A-Za-z0-9_]{2,20})(?:\/[^" ]*)*$/
|
||||
const discordPattern = /(?:https?:\/\/)?(?:www\.)?(?:(?:discord)?\.?gg|discord(?:app?)\.com\/invite)\/([^\s/]+?)(?=\b)/
|
||||
const discordPattern = /^(?:(?:https?:\/\/)?(?:www\.)?(?:(?:discord)?\.?gg|discord(?:app)?\.com\/invite)\/)?([^\s/]+?)(?=\b)$/
|
||||
|
||||
let entryId = 0;
|
||||
let path = [];
|
||||
|
@ -599,6 +599,16 @@ function initDraw() {
|
|||
inputButton.innerHTML = '<i class="bi bi-trash-fill" aria-hidden="true"></i>';
|
||||
inputButton.addEventListener('click', () => removeFieldButton(inputGroup, array, index));
|
||||
}
|
||||
|
||||
inputField.addEventListener('paste', (event) => {
|
||||
let paste = (event.clipboardData || window.clipboardData).getData('text')
|
||||
paste = paste.trim().match(subredditPattern)?.[1]
|
||||
if (paste) {
|
||||
event.target.value = "r/" + paste
|
||||
event.preventDefault()
|
||||
}
|
||||
})
|
||||
|
||||
inputGroup.appendChild(inputButton);
|
||||
}
|
||||
|
||||
|
@ -639,6 +649,16 @@ function initDraw() {
|
|||
inputButton.innerHTML = '<i class="bi bi-trash-fill" aria-hidden="true"></i>';
|
||||
inputButton.addEventListener('click', () => removeFieldButton(inputGroup, array, index));
|
||||
}
|
||||
|
||||
inputField.addEventListener('paste', (event) => {
|
||||
let paste = (event.clipboardData || window.clipboardData).getData('text')
|
||||
paste = paste.trim().match(discordPattern)?.[1]
|
||||
if (paste) {
|
||||
event.target.value = paste
|
||||
event.preventDefault()
|
||||
}
|
||||
})
|
||||
|
||||
inputGroup.appendChild(inputButton);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue