Skip to content

Commit

Permalink
Keyboard shortcut hints now mac friendly for mac installations
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattk70 committed Jan 30, 2024
1 parent 83f943c commit 9afbfc5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
37 changes: 20 additions & 17 deletions js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ function updatePrefs() {
let appPath, tempPath;
window.onload = async () => {
window.electron.requestWorkerChannel();
replaceCtrlWithCommand()
contentWrapperElement.classList.add('loaded');
// Set config defaults
const defaultConfig = {
Expand Down Expand Up @@ -3283,23 +3284,26 @@ const populateHelpModal = async (file, label) => {
document.getElementById('helpModalBody').innerHTML = await response.text();
const help = new bootstrap.Modal(document.getElementById('helpModal'));
help.show();
function replaceTextInTitleAttributes() {
// Select all elements with title attribute in the body of the web page
const elementsWithTitle = document.querySelectorAll('[title]');

// Iterate over each element with title attribute
elementsWithTitle.forEach(element => {
// Replace 'Ctrl' with ⌘ in the title attribute value
element.title = element.title.replace(/Ctrl/g, '⌘');
});
}

function replaceTextInTextNode(node) {
node.nodeValue = node.nodeValue.replace(/Ctrl/g, '⌘');
}
document.addEventListener('shown.bs.modal', replaceCtrlWithCommand)
}
function replaceTextInTitleAttributes() {
// Select all elements with title attribute in the body of the web page
const elementsWithTitle = document.querySelectorAll('[title]');

function replaceCtrlWithCommand() {
console.log('running replacetext')
// Iterate over each element with title attribute
elementsWithTitle.forEach(element => {
// Replace 'Ctrl' with ⌘ in the title attribute value
element.title = element.title.replaceAll('Ctrl', '⌘');
});
}

function replaceTextInTextNode(node) {
node.nodeValue = node.nodeValue.replaceAll('Ctrl', '⌘');
}

function replaceCtrlWithCommand() {
const isMac = /mac/i.test(navigator.userAgentData ? navigator.userAgentData.platform : navigator.platform);
if (!isMac){
// Select all text nodes in the body of the web page
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false);
const nodes = [];
Expand All @@ -3316,7 +3320,6 @@ const populateHelpModal = async (file, label) => {
// Replace 'Ctrl' with ⌘ in title attributes of elements
replaceTextInTitleAttributes();
}
document.addEventListener('shown.bs.modal', replaceCtrlWithCommand)
}

const populateSpeciesModal = async (included, excluded) => {
Expand Down
1 change: 0 additions & 1 deletion js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2835,7 +2835,6 @@ async function onUpdateLocale(labels){
await memoryDB.runAsync('END');
await getResults()
await getSummary();
console.error('updating labels took:', performance.now() -t0, 'ms');
}

async function onSetCustomLocation({ lat, lon, place, files, db = STATE.db }) {
Expand Down

0 comments on commit 9afbfc5

Please sign in to comment.