|
1 | | -settings.register({ |
2 | | - name: 'Disable First/Last Page Shortcut', |
3 | | - key: 'underscript.disable.quickpages', |
4 | | - page: 'Chat', |
5 | | -}); |
| 1 | +wrap(function pageShortcuts() { |
| 2 | + const disable = settings.register({ |
| 3 | + name: 'Disable First/Last Page Shortcut', |
| 4 | + key: 'underscript.disable.quickpages', |
| 5 | + page: 'Chat', |
| 6 | + }); |
6 | 7 |
|
7 | | -if (onPage('Crafting') || onPage('Decks')) { |
8 | | - function ignore(e) { |
9 | | - return settings.value('underscript.disable.quickpages') || !e.ctrlKey; |
10 | | - } |
11 | | - function firstPage(e) { |
12 | | - if (ignore(e)) return; |
13 | | - e.preventDefault(); |
14 | | - hover.hide(); |
15 | | - showPage(0); |
16 | | - $('#btnPrevious').prop('disabled', true); |
17 | | - $('#btnNext').prop('disabled', false); |
18 | | - } |
19 | | - function lastPage(e) { |
20 | | - if (ignore(e)) return; |
21 | | - e.preventDefault(); |
22 | | - hover.hide(); |
23 | | - showPage(getMaxPage()); |
24 | | - $('#btnNext').prop('disabled', true); |
25 | | - $('#btnPrevious').prop('disabled', false); |
26 | | - } |
| 8 | + if (onPage('Crafting') || onPage('Decks')) { |
| 9 | + function ignore(e) { |
| 10 | + const ignore = disable.value() || !e.ctrlKey; |
| 11 | + if (ignore && [0, global('getMaxPage')()].includes(global('currentPage'))) hover.hide(); |
| 12 | + return ignore; |
| 13 | + } |
| 14 | + function firstPage(e) { |
| 15 | + if (ignore(e)) return; |
| 16 | + e.preventDefault(); |
| 17 | + hover.hide(); |
| 18 | + global('showPage')(0); |
| 19 | + $('#btnPrevious').prop('disabled', true); |
| 20 | + $('#btnNext').prop('disabled', false); |
| 21 | + } |
| 22 | + function lastPage(e) { |
| 23 | + if (ignore(e)) return; |
| 24 | + e.preventDefault(); |
| 25 | + hover.hide(); |
| 26 | + global('showPage')(global('getMaxPage')()); |
| 27 | + $('#btnNext').prop('disabled', true); |
| 28 | + $('#btnPrevious').prop('disabled', false); |
| 29 | + } |
27 | 30 |
|
28 | | - eventManager.on('jQuery', function () { |
29 | | - $('#btnNext').on('click.script', lastPage).hover(hover.show('CTRL Click: Go to last page')); |
30 | | - $('#btnPrevious').on('click.script', firstPage).hover(hover.show('CTRL Click: Go to first page')); |
31 | | - }); |
32 | | -} |
| 31 | + eventManager.on('jQuery', function () { |
| 32 | + $('#btnNext').on('click.script', lastPage).hover(hover.show('CTRL Click: Go to last page')); |
| 33 | + $('#btnPrevious').on('click.script', firstPage).hover(hover.show('CTRL Click: Go to first page')); |
| 34 | + }); |
| 35 | + } |
| 36 | +}); |
0 commit comments