Tab Scroll
-
@hlehyaric Yeah, minimise active tab changes tab when you just want to go to top or previous. Personally I never had it activated, it's far more comfortable switching tabs with shortcut. But good point.
-
Seems like there are a few more problems I have previously overlooked…
- The
mousedown
event triggers on right click too. - In Opera the scroll is triggered on click (
mouseup
left button). - When a modifier key is being used the event is triggered, but we don't intend to trigger the scroll when we want to select tabs with
shift
, view the context menu withctrl
, etc. - The event triggers when a tab is being moved.
I tried to address all of these and it seems to behave fine. But please do test this, maybe more adjustments are needed.
function tabScrollExit() { tsTarget.removeEventListener('mousemove', tabScrollExit); tsTarget.removeEventListener('click', tabScrollTrigger); }; function tabScrollTrigger() { chrome.tabs.executeScript({ code: 'var offset=window.pageYOffset;if(offset>0){window.sessionStorage.setItem("tabOffset",offset);window.scrollTo(0,0);}else{window.scrollTo(0,window.sessionStorage.getItem("tabOffset")||0);}' }); tabScrollExit(); }; function tabScroll(event) { if (event.which == 1 && !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey) { tsTarget = event.target; if (tsTarget.parentNode.classList.contains('tab-header')) { tsTarget = tsTarget.parentNode; } if (tsTarget.classList.contains('tab-header') && tsTarget.parentNode.classList.contains('active')) { tsTarget.addEventListener('mousemove', tabScrollExit); tsTarget.addEventListener('click', tabScrollTrigger); } } }; setTimeout(function wait() { const browser = document.getElementById('browser'); if (browser) { document.body.addEventListener('mousedown', tabScroll); } else { setTimeout(wait, 300); } }, 300);
- The
-
@luetage Thanks for this mod and your quick fixes.
I found a problem, it also exists in Opera version. It is the opening of a link in the current tab of the same domain that still remembers the tab location saved by the previous tab (This doesn't affect much, but I really don't like it ).- I added a url variable to determine if the link is saved and the current link is the same, which makes it work differently than the Opera version.
- Add
(function () {/ * code * /}) ();
to avoid overwriting with Vivaldi functions or other mods.
(function () { function tabScrollExit() { tsTarget.removeEventListener('mousemove', tabScrollExit); tsTarget.removeEventListener('click', tabScrollTrigger); } const tabScrollScript = '!' + function () { var tabOffset = JSON.parse(window.sessionStorage.getItem('tabOffset')) || {}; var offset = window.pageYOffset; var urlWithoutHash = document.URL.replace(/#.*$/, ''); if (offset > 0) { window.scrollTo(0, 0); tabOffset = { offset: offset, url: urlWithoutHash }; window.sessionStorage.setItem('tabOffset', JSON.stringify(tabOffset)); } else if (urlWithoutHash === tabOffset.url) { window.scrollTo(0, tabOffset.offset); } } + '();'; function tabScrollTrigger() { chrome.tabs.executeScript({ code: tabScrollScript }); tabScrollExit(); } function tabScroll(event) { if (event.which == 1 && !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey) { tsTarget = event.target; if (tsTarget.parentNode.classList.contains('tab-header')) { tsTarget = tsTarget.parentNode; } if (tsTarget.classList.contains('tab-header') && tsTarget.parentNode.classList.contains('active')) { tsTarget.addEventListener('mousemove', tabScrollExit); tsTarget.addEventListener('click', tabScrollTrigger); } } } setTimeout(function wait() { const browser = document.getElementById('browser'); if (browser) { document.body.addEventListener('mousedown', tabScroll); } else { setTimeout(wait, 300); } }, 300); })();
I hope it will make the mod better.
-
@tam710562 It definitely makes the mod better. You're fixing problems I never knew we had, which is a good thing. And apparently this versions is now superior to the Chinese Opera version, so job well done.
You're good at coding modifications, I hope you stick around. By the way, although it doesn't really matter… if you do have a github account and you care for such things, please make a pull request for your improvements. I'm trying to put all my mods up on github too and you naturally deserve credit for all of these contributions.
-
@luetage Yeah, I created a pull request for my improvements.
-
This mod ceases to function on Vivaldi version 3.7 (current snapshot). As found out by @LonM
chrome.tabs.executeScript
isn’t available anymore from the UI. Moreover Vivaldi switched from triggering the active tab on click, to triggering it on mousedown, which hurts this mod too. I don’t see what to do about either of these issues at this point in time.Workaround: Switch to Opera browser immediately.
GMO I’m joking you guys, relax. Vimium provides the functionality to set local marks on webpages, which allows to jump to top and back too. Moreover we can set more than one mark, so it’s actually more advanced, just keyboard driven.
-
@luetage Thanks to @tam710562 this mod works again, see here ☛ https://forum.vivaldi.net/topic/57191/restore-methods-for-chrome-tabs. You will have to insert the code in your modfile, then executing scripts will work as intended on webpages. Additionally I rewrote the mod to work with 2 level tab stacks and apparently we lucked out: The mousedown change implemented by Vivaldi in the latest version doesn’t influence this mod. It seems like the mousedown listener in this script is faster than the switching of tabs in Vivaldi. To make a short story longer: all functionality is restored and the mod should work as expected.
-
A minor observation about Opera forums ☛ https://forums.opera.com/topic/25279/click-the-tab-to-scroll-keyboard-shortcut. User has the right idea: provide tab scroll as keyboard shortcut, because clicking is slow. Moderator doesn’t understand Opera’s new feature, makes a suggestion which isn’t helpful and the topic is closed. User is being downvoted on top of it. Oh boy am I glad we are on an active forum with users, who are actually being helpful (most of the time).
-
@luetage said in Tab Scroll:
Moderator
But look who. It can mean
- I don't know enough of this person
- it is normal there
- it is forced-normal there
-
@guigirl Yeah, when they’re not helpful they’re either memeing or telling other people that they use Arch.
@potmeklecbohdan oh lol… @sgunhouse, you can still fix this!!
-
I could unlock it, sure - the other moderator, Leo, is prone to lock threads as soon as they are answered. But I did understand the question. The feature in Opera under discussion is that when you click on the active tab the page scrolls to the top. Which is what the Home key does if focus is not in a text field.
-
@sgunhouse Hey, that’s not what this feature does. Of course you are correct that clicking the tab scrolls the page to top, just like the home button. But the deciding factor is that clicking the active tab again moves back to the scroll position you previously had! That can’t be done with home and end buttons and is the sole reason this feature is so special and why we recreated/modded it for Vivaldi.
-
Well, if Opera actually had a way of recalling the previous scroll position ... but it doesn't for keyboard interaction.
-
-
@sgunhouse That’s why it was a feature request I suppose, it’s not like this is impossible to implement. Anyway, all of this is kinda unrelated to Vivaldi. I just stumbled upon the topic while trying to find out whether Opera had changed anything about the feature, without having to install the browser.
-
@luetage said in Tab Scroll:
@sgunhouse That’s why it was a feature request I suppose, it’s not like this is impossible to implement. Anyway, all of this is kinda unrelated to Vivaldi. I just stumbled upon the topic while trying to find out whether Opera had changed anything about the feature, without having to install the browser.
It works in Opera exactly like your nice script.
-
@Dancer18 It’s equally @tam710562's mod now, but thanks for testing.
-
You know, years ago I recall a program where the Undo shortcut would actually undo in-document navigation like Home and End. It was one of those programs where the text of the menu item changed to reflect what would be undone (as in, Undo Delete, Undo Typing) and in this case said Undo Navigation. Might actually have been an old version of Word.
-
@luetage I install the Mod and after that Vivaldi reload with a blank page. (Restore Methods for chrome.tabs is my first Mod in custom.js)
What could be the problem?
-
Try without any other mods. Except for the chrome.tabs method of course.