1
1
mirror of https://github.com/neosubhamoy/neosubhamoy-portfolio.git synced 2025-12-19 20:33:06 +05:30

(refactor): made keybinding links fully dynamic

This commit is contained in:
2024-02-02 01:09:33 +05:30
parent 2416cfae1f
commit 1b27da85e7
2 changed files with 24 additions and 4 deletions

View File

@@ -3,6 +3,26 @@
let pressedKeys = {};
function getJsonDataset(element) {
return new Promise((resolve, reject) => {
$.getJSON('assets/dataset.json', function(datasetData) {
resolve(datasetData[element]);
}).fail(function(jqxhr, textStatus, error) {
reject(error);
});
});
}
async function redirectToURL(item) {
try {
const url = await getJsonDataset(item);
window.open(url, '_blank');
location.reload();
} catch (error) {
console.error('Error:', error);
}
}
document.addEventListener('keydown', function(event) {
pressedKeys[event.key] = true;
@@ -19,13 +39,13 @@ document.addEventListener('keydown', function(event) {
window.location.href = basePath + "/contact";
}
else if (pressedKeys['q'] && pressedKeys['e']) {
window.location.href = "mailto:hey@neosubhamoy.com";
redirectToURL('email');
}
else if (pressedKeys['q'] && pressedKeys['m']) {
window.location.href = "#";
redirectToURL('chat');
}
else if (pressedKeys['q'] && pressedKeys['s']) {
window.location.href = "#";
redirectToURL('sources');
}
});