Discussions » Creation Requests

write/fix script to scroll to vertical position on page: ScrollToY

§
Posted: 20.02.2016.
Edited: 20.02.2016.

write/fix script to scroll to vertical position on page: ScrollToY

There actually was a script that automatically scrolls to a set position on a webpage upon loading called ScrollToY ("Scroll-To-Y") on userscripts but it no longer works. i tweeted the author exactly a year ago (!) but he didn't fix it. https://twitter.com/DyNama/statuses/567927087459397632

Here's the old script:

// ==UserScript==
// @name ScrollToY
// @namespace http://henrik.nyh.se
// @description Automatically scrolls to some vertical position on page load, to facilitate browsing e.g. image galleries with big headers. To configure the vertical position, scroll there and run "javascript:GM_setY()" in the address bar, ideally as a bookmarklet with the keyword "y". The position is saved per host, ignoring "www." – so setting a position at "http://www.example.com/foo" will scroll there when visiting "http://example.com/bar", but not "http://two.example.com/foo".
// @include *
// ==/UserScript==


// Scrolling to stored y

var ys = eval(GM_getValue('ys', '({})'));
var host = location.hostname.replace( /^www\./i, '');
var y = ys[host];

function scrollToY() {
scrollTo(window.pageXOffset, y);
}

if (y) {
scrollToY();
if (y && window.pageYOffset != y) // Wait for images to load and extend page
window.addEventListener("load", scrollToY, false);
}


// Storing y

//unsafeWindow.GM_setY = function(){
// ys[host] = window.pageYOffset;
// Wrapped in setTimeout for http://wiki.greasespot.net/0.7.20080121.0_compatibility
// setTimeout(function() { GM_setValue('ys', ys.toSource()) }, 0);
//};

You have a bookmarklet on your Bookmark Toolbar that has this in the Location box:

javascript:if(typeof%20yzWypZ==typeof%20alert)yzWypZ();GM_setY()

To use, you scroll to the desired vertical position on the page, press the Set ScrollToY button on the toolbar, then every time a page at that domain loads, it scrolls down to the set position.

Tho it hasn't worked in a while, I still have in loaded and enabled in firefox! Can somebody please fix this?

§
Posted: 20.02.2016.

I have a script which seems doing what you need: Y-marker

§
Posted: 20.02.2016.

Thanx, trespassersW, I'll check it out. I do need to change the modifier keys right away as you've provided cuz i have a couple dozen hotkeys defined in AutoHotkey.

§
Posted: 22.02.2016.

One thing I like about ScrollToY is that it sets just one vertical position for the whole domain. ScrollToY is used to scroll down the same amount on every page automatically, like for scrolling past a header or banner ads. I would only have to set it just once to automatically scroll down past the GreasyFork header on every thread I looked at in this forum. With Y-marker, I would have to set it manually on each and every thread. So Y-marker looks very useful, but I'd still like to have ScrollToY working again.

§
Posted: 22.02.2016.

Well, I've improved my script. If you press Alt-Shift-0 twice, current position becomes the starting point for any page inside the whole domain.

§
Posted: 22.02.2016.

Hello DyNama
I can very much understand your wish and I much appreciate that you shared the small script :smile:

As far as I could figure out, in the end the script fails because of one command. If you can edit your local script version you might only need to change the one line from:
scrollTo(window.pageXOffset, y);
to:
window.scrollTo(window.pageXOffset, y);
and continue to use it like you've been doing before.

Or maybe you'd like to try the altered version that I have created: ScrollTo_Y which offers a GM-menu entry to set the settings.

greets ~ Vivre


Dear trespassersW ~ hope you don't mind me tuning in :smile:

§
Posted: 22.02.2016.

Suddenly I have an embarrassment of riches!

trespassersW, your new Y-marker does seem to be doing the trick, once i remembered reinstalling the script would change back the hotkeys :wink:

Vivre, thanx very much for the ScrollToY edit, i thought it'd be something small like that! I will check out your script too :smile:

Besides posting here, I also posted on the original author's blog from 2007--and he replied to a comment on a 9-year-old blog! He said I'm free to find people to fix it for him, so thanx to him, and trespassersW and Vivre, and the javascript community!

§
Posted: 22.02.2016.

wow ~ that was a quick response :smile:

and I'm glad to hear that the author kind of set it free :wink:
so many more can benefit from it.

§
Posted: 22.02.2016.
As far as I could figure out, in the end the script fails because of one command. If you can edit your local script version you might only need to change the one line from:
scrollTo(window.pageXOffset, y);
to:
window.scrollTo(window.pageXOffset, y);
and continue to use it like you've been doing before.

Did you actually try that? Both Firefox and Chrome evaluate window.scrollTo === scrollTo as true:

§
Posted: 22.02.2016.
Edited: 22.02.2016.

Here's 2 webpages i'm using these scripts on:
I'm using ScrollTo_Y on http://www.affordablevapingny.com cuz of their monstrous header;
and Y-marker on http://www.girlgeniusonline.com cuz of the big ornate border.

Both seem to be doing what I want!

Vivre, your repair to the original ScrollToY does not seem to help, like perhaps Farow is pointing out. Nevermind, I much prefer a GM menu to a bookmarklet. Thanx all!

§
Posted: 22.02.2016.

Hello Farow ~ nice to meet you :smile:
While trying to figure out how to get it working at all that was the last and to me essential change on my side. If I'd only use scrollTo it wouldn't run for me - on an old FF on Linux.
But I didn't go back to check the original code on it's own again afterwards, assuming that had been the basic drawback. I can give it an second try by checking it against the other changes that I've made.

Hi DyNama, you're welcome ~ I'm glad to hear my version runs for you too and that you also prefer the gm_menu comfort :smile:

§
Posted: 23.02.2016.

i didn't delete the original but i did disable it and remove the bookmarklet, so that shows my commitment :smile:

§
Posted: 23.02.2016.

lol ~ DyNama :smile:
I can't see your commitment but I can surely feel it :-) xxx

ps 2cents:
I'm still not sure why the original stopped working for you, BUT if in your script the whole // Storing y block is commented out (like posted by you) it would be no surprise. I had skiped this issue assuming it might have been due to posting circumstances (or whatever reason).
Also: I don't understand what the middle part of your bookmark is intended to do. It's somewhat strange, doesn't make sence and isn't needed at all to call the setting.

However ~ it's great to have various working options now :smile:

§
Posted: 23.02.2016.
Edited: 24.02.2016.

Addendum - re-check of the original script

Like mentioned above I've re-checked the script from the opening posting and now got it working without the need of significant changes. Also scrollTo now processes for me and I have no idea why it broke previously.
For for the sake of completeness and as credit to the author I'll share the reworked script right here ~ so everyone can easily use it if wanted.


// ==UserScript==
// @name ScrollToY
// @namespace http://henrik.nyh.se
// @description Automatically scrolls to some vertical position on page load, to facilitate browsing e.g. image galleries with big headers. To configure the vertical position, scroll there and run "javascript:GM_setY()" in the address bar, ideally as a bookmarklet with the keyword "y". The position is saved per host, ignoring "www." - so setting a position at "http://www.example.com/foo" will scroll there when visiting "http://example.com/bar", but not "http://two.example.com/foo".
// @include *
// @grant    GM_getValue
// @grant    GM_setValue
// @grant    GM_registerMenuCommand
// @mirroredScript    http://userscripts-mirror.org/scripts/show/7126
// ==/UserScript==

// Scrolling to stored y

var ys = eval(GM_getValue('ys', '({})'));
var host = location.hostname.replace( /^www\./i, '');
var y = ys[host];

function scrollToY() {
	scrollTo(window.pageXOffset, y);
	}

if (y) {
	scrollToY();

	if (y && window.pageYOffset != y) // Wait for images to load and extend page
	window.addEventListener("load", scrollToY, false);
	}


// Storing y

unsafeWindow.GM_setY = function(){
	ys[host] = window.pageYOffset;
	
// Wrapped in setTimeout for http://wiki.greasespot.net/0.7.20080121.0_compatibility
// choose one of the following lines as active to dis- / enable a verification-alert:
	// setTimeout(function() { GM_setValue('ys', ys.toSource()) }, 0);
	setTimeout(function() { GM_setValue('ys', ys.toSource()); alert(host +": set value - " +ys[host]);}, 100);
	};

 
// ******* USAGE *******
 
//   use this command to evoke a saving of the desired setting: javascript:GM_setY()
 
// A - copy the command - paste into Browser-Address-Field - click ENTER
 
// B - copy the command and save it as a BookMark -!- afterwards only call /click this bookmark
 
// ******* end *******

edit: applied missing @grant's, added: @mirroredScript

___________
ps: can someone please tell me which html-tag is used on board to embrace the code for it to apear consistent, because the code-tag doesn't do the trick.

§
Posted: 23.02.2016.
Edited: 23.02.2016.

Seems like it works for you because you're running it on a 7 year old browser, presumably with a just as old Greasemonkey version. Since version 2.0, Greasemonkey requires the usage of @grant keys to let your userscript access GM_* functions. This is only part of the issue for newer versions though.

As for the code tag, I'd suggest using markdown and prepending it with 4 spaces:

line 1
line 2
§
Posted: 23.02.2016.

Ah ~ thanks for the missing @grant hint Farow. I added them to the original header above.

And for the markdown hint. Still I have absolutely no idea what that is [nothing happens when chosen] and I couldn'd find anything about it in all the help-files. I noticed there are scripts about it (applying buttons etc.) but didn't have the time to investigate into the subject for now.
... and I miss a place where to do testings without making public postings by chance. Maybe the "Draft-function" is an option, but haven't tried it yet.

§
Posted: 23.02.2016.
... and I miss a place where to do testings without making public postings ...

-- there is a Preview button - dont u try 2 clik it?

§
Posted: 23.02.2016.
Edited: 23.02.2016.
... and I miss a place where to do testings without making public postings ...
-- there is a Preview button - dont u try 2 clik it?

On contraire ~ I'm useing this feature already. But it doesn't display the comment like it will show up after it's been submitted.
~ thanks for the suggestion :smile:

Meanwhile I've tested the draft-function and it too doesn't show up like a posted comment. It also doesn't have its own edit/preview-area (instead redirecting me back to the thread and a hard time to find the way back to the drafts afterwards).

Well - maybe the mail-feature allows a real testing and the freedom to save some notes. I'll find that out soon. ... addendum: no - no way

§
Posted: 23.02.2016.

Vivre, the original script posted here was a simple copy-and-paste, I have no idea why that section was commented out or what it means, or what the "javascript:if(typeof%20yzWypZ" in the bookmarklet means. That's the way it was when installed from userscripts in April 2009. I noticed the script was broken in July 2014.

To use the original script you say "A - copy the command - paste into Browser-Address-Field - click ENTER", you mean paste "javascript:GM_setY()" in the address field? the command you're referring to in both A and B is the "javascript:GM_setY()"?

§
Posted: 24.02.2016.
Edited: 24.02.2016.

Hi DyNama, I don't think, we will resolve how it came to be that you ended up with your posted script and that bookmark-command [while the desciption tells you different].

Last night I researched and succefully found the script's mirrored page: http://userscripts-mirror.org/scripts/show/7126
Even though Henrik must have been active until 2011 the script dates: Last update Apr 12, 2008

Hey ~ on that mirrored script I saw your great review :smile:

Answers to both of your questions is: YES

To give you a small explanation: javascript: in the browser address tells the browser not to surf the net but to process another command. In this case it shall be javascript to be executed. The script itself follows behind that preceded invocation.
A most famous command of all is: alert("Hello World")

Combining it into a real example ~ paste the following line into the address-field - click ENTER and enjoy:
javascript:alert("Good morning DyNama \n\n\t =^•◡•^= ")

... and of course you can make it a bookmarklet for to enjoy all time ever after :wink:

§
Posted: 26.02.2016.
Edited: 26.02.2016.

I've updated Y-marker. The new features are:
- dialogue for settings keyboard shortcuts;
- bookmarklet interface .

§
Posted: 28.02.2016.
Edited: 28.02.2016.

Vivre, I looked for it several months ago but couldn't find userscripts-mirror to make sure my copy was unchanged from the original. it is changed, that Storing Y function wasn't commented out in the original. i don't recall doing that, maybe i just tried something to get it to work. i notice mirrored site says it was installed 665 times, but it only got 1 review.

oddly, i copy the "javascript:alert("Hello World")" code (i can see it's in my clipboard) but when i paste it in firefox's address bar, the "javascript:" gets eaten. i have to type that manually.

trespassersW, Y-marker gets better and better! i've made a bookmarklet!

§
Posted: 28.02.2016.

Yes DyNama, that makes sence that you had tried to fix it and left it at that when nothing helped. And I too found 1 review to be too few for this neat helper ... but at least it's not left behind without one :smiley:

oddly, i copy the "javascript:alert("Hello World")" code (i can see it's in my clipboard) but when i paste it in firefox's address bar, the "javascript:" gets eaten. i have to type that manually.

As I didn't post that line as one line you've likely copied one part after the other and so the second copy-action was the latest clipboard-content that gets pasted.
Sorry you didn't try the prepared line.

ps: my ScrollTo_Y got an update as well :smile:

§
Posted: 28.02.2016.
Edited: 29.02.2016.

Vivre, i was being succinct, pasting

javascript:alert("Good morning DyNama \n\n\t =^•◡•^= "), 
javascript:alert("Hello world"), 
javascript:GM_setY(),```
all of them eat the "javascript:". 

Thanx for the update. Even if it updates automagically, i've been updating both [ScrollTo_Y](https://greasyfork.org/en/scripts/17321-scrollto-y-vivre) and [Y-marker](https://greasyfork.org/en/scripts/236-y-marker) manually.
§
Posted: 29.02.2016.

Oh well, I have no idea about that "javascript:"-removement but only a guess that it might be due to a browsers safety-setting to pervent processing links that contain javascript.
But maybe someone else reading this will enlighten us :relaxed:

ps: I too don't fancy auto-updates and prefer to know what's going to come first.

Post reply

Sign in to post a reply.