Skip to content

Commit 05a8bd3

Browse files
committed
scribblehub_reading_list_upgrades.user.js: Add tooltips to the "Save" and "Cancel" buttons in the notes editor popup. Add "ctrlEnterSavesNotes" setting to enable new keybind for the "Save" button (Default: on).
1 parent 0506075 commit 05a8bd3

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

scribblehub_readling_list_upgrades.user.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// @name ScribbleHub Reading List Upgrades
33
// @namespace https://github.com/StaticPH
44
// @match https://www.scribblehub.com/reading-list/
5-
// @version 1.1
5+
// @version 1.2
66
// @createdAt 10/7/2022, 11:34:28 PM
77
// @author StaticPH
88
// @description Allows hiding novels the user is caught up on from their reading lists, adds the current reading list name to the title, and more planned.
@@ -25,6 +25,7 @@
2525
const settings = {
2626
hideCaughtUpByDefault: false,
2727
improvePageTitle: true,
28+
ctrlEnterSavesNotes: true,
2829
// customTagDropdownList: true, // TODO: Not yet implemented
2930
// invertableTagFiltering: true // TODO: Not yet implemented
3031
};
@@ -62,7 +63,8 @@
6263
// Label indicates what the button does when clicked, not the current state.
6364
click2Hide: 'Hide Caught Up Novels',
6465
click2Show: 'Show Caught Up Novels'
65-
}
66+
},
67+
closeAndDiscard: 'Close and discard changes'
6668
};
6769

6870
GM.addStyle(`
@@ -112,6 +114,23 @@
112114
}
113115
}
114116

117+
async function saveNotesKeybindHandler(evnt){
118+
const notesPopup = document.querySelector('#my_popupnotes[aria-hidden="false"]');
119+
if (! notesPopup){ return; } // Notes editor is not open, allow normal event processing to occur.
120+
else if (evnt.key && evnt.key === 'Enter' && evnt.ctrlKey && !evnt.shiftKey){
121+
// Notes editor is open, and ctrl+enter has been pressed. Trigger the normal "Save" workflow.
122+
notesPopup.querySelector('.savenotes').click();
123+
evnt.stopImmediatePropagation();
124+
evnt.stopPropagation();
125+
}
126+
}
127+
128+
function setTitleForFakeButton(elem, includeElemText = false, prefix = '', suffix = ''){
129+
if(elem){
130+
elem.title = includeElemText ? prefix + elem.textContent.trim() + suffix : prefix;
131+
}
132+
}
133+
115134
const caughtUpHelper = {
116135
mainTbl: document.getElementsByClassName('rl_table')[0],
117136
hiddenTbl: (function(){
@@ -207,6 +226,12 @@
207226
document.querySelectorAll('script').forEach(s => (s.textContent.includes('urchinTracker') || s.src.includes('analytic')) && s.remove());
208227

209228
settings.improvePageTitle && improveTitle();
210-
caughtUpHelper.init();
229+
if (settings.ctrlEnterSavesNotes){
230+
document.addEventListener('keyup', saveNotesKeybindHandler);
231+
setTitleForFakeButton(document.querySelector('.rlnotes_btn.savenotes'), true, '', ' (Ctrl+Enter)');
232+
}
233+
// By default, the notes editor has already been set up to close when the Escape key is pressed, so it just needs a tooltip to say that.
234+
setTitleForFakeButton(document.querySelector('.rlnotes_btn.my_popupnotes_close'), false, labelStrings.closeAndDiscard + ' (Esc)');
211235

236+
caughtUpHelper.init();
212237
})();

0 commit comments

Comments
 (0)