Skip to content

Commit

Permalink
Added ability to switch continuously between notes
Browse files Browse the repository at this point in the history
  • Loading branch information
klaudiosinani committed Sep 11, 2017
1 parent b0669db commit 859ddea
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
69 changes: 69 additions & 0 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,82 @@ function goToNote(key) {
selectNote(index);
}

const noteSelector = '.focus-NotesView-Note';
const notesList = '.NotesView-ScrollWindow > div';
const notesListSelector = '.NotesView-ScrollWindow';
const selectedNoteSelector = '.focus-NotesView-Note-selected';

function selectNote(index) {
// Select the appropriate note based on given index
document.querySelector(notesList).children[index].firstChild.firstChild.click();
}

function goToNextNote() {
// Navigate to the next note
const index = getCurrentIndex();
const nextIndex = getNextIndex(index);
console.log('Next note index is: ' + nextIndex);
selectNote(nextIndex);
}

function goToPreviewsNote() {
// Navigate to the previews note
const index = getCurrentIndex();
const previewsIndex = getPreviewsIndex(index);
console.log('Previews note index is: ' + previewsIndex);
selectNote(previewsIndex);
}

// Calculate the index of the current note
function getCurrentIndex() {
let i;
let currentIndex; // Index of current note
let notesArray = []; // Array of notes
// Get the css meta of the currently selected note
const selectedNote = document.querySelector(selectedNoteSelector);

// Create an array of notes relative to the currently selected note
// NOTE: Evernote adds and removes notes from the notes-list dynamically
// in function with the user's behavior, i.e. scrolling etc, thus the
// `notesArray` array holds only the notes that are available to user
// at that particular time
// TODO: Create the array dynamically so all notes can be included
notesArray = document.querySelector(notesListSelector).querySelectorAll(noteSelector);

// Traverse the array and find the index of selected note
for (i = 0; i < notesArray.length; i++) {
if (notesArray[i] === selectedNote) {
// Increment the selected note index
// since selectNote() navigates to
// positive non-zero values only
currentIndex = i + 1;
console.log('The currently selected note has an index of: ' + currentIndex);
}
}
// Return the current note index
return currentIndex;
}

// Calculate the index of the next note
// relatively to the current note index
function getNextIndex(currentIndex) {
const nextIndex = currentIndex + 1; // Index value of next note
console.log('The next note will have an index of: ' + nextIndex);
return nextIndex;
}

// Calculate the index of the previews note
// relatively to the current note index
function getPreviewsIndex(currentIndex) {
const previewsIndex = currentIndex - 1; // Index value of previews note
console.log('The previews note will have an index of: ' + previewsIndex);
return previewsIndex;
}

ipc.on('next-note', goToNextNote);

ipc.on('previous-note', goToPreviewsNote);

ipc.on('toggle-notebooks', () => {
// Toggle notebooks list
document.querySelector('#gwt-debug-Sidebar-notebooksButton').click();
Expand Down
28 changes: 28 additions & 0 deletions menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ const darwinTpl = [{
role: 'about'
}, {
type: 'separator'
}, {
label: 'Navigate to Next Note',
accelerator: 'Ctrl+Tab',
click() {
activate('next-note');
}
}, {
label: 'Navigate to Previous Note',
accelerator: 'Ctrl+Shift+Tab',
click() {
activate('previous-note');
}
}, {
type: 'separator'
}, {
label: 'Switch to Yinxiang',
visible: !config.get('useYinxiang'),
Expand Down Expand Up @@ -495,6 +509,20 @@ const otherTpl = [{
}
}, {
type: 'separator'
}, {
label: 'Navigate to Next Note',
accelerator: 'Ctrl+Tab',
click() {
activate('next-note');
}
}, {
label: 'Navigate to Previous Note',
accelerator: 'Ctrl+Shift+Tab',
click() {
activate('previous-note');
}
}, {
type: 'separator'
}, {
label: 'Switch to Yinxiang',
visible: !config.get('useYinxiang'),
Expand Down

0 comments on commit 859ddea

Please sign in to comment.