ScrollTo_Y | Vivre

Autoscroll to set Y-position on specific Hosts

目前为 2016-02-22 提交的版本。查看 最新版本

// ==UserScript==
// @name             ScrollTo_Y | Vivre
// @description   Autoscroll to set Y-position on specific Hosts
// @version          0.1 - 22.02.16
// @author            Vivre
// @namespace   https://greasyfork.org/en/users/31346-vivre
// @include         *
// @grant           GM_getValue
// @grant           GM_setValue
// @grant           GM_registerMenuCommand
// ==/UserScript==


// ***********************************************************************
// NOTE
// The original ScrollToY was published on userscripts.org by "@namespace henrik.nyh.se"
// It stopped runing and the author was unavailable.
// 
// This script now is an updated and altered version of the original.
// It offers a Greasemonkey menu entry to set and save the desired scrollTo-position for the current host.
// HowTo:
// Scroll to a certain position on a given page that you'd like to become the default scroll-position 
// whenever you visit that side. Than choose "ScrollTo_setY" from the GreasemonkeyMenu to save 
// this specific setting. A simple alert will popup to varify the setting took place. [*see below]
// A setting can be changed anytime by repeating the above described procedure.
// 
// enjoy ~ Vivre
// ***********************************************************************


// * Setting:
var showAlert = 1    // assign 0/1 to en-/disable the verifying popup


// ***** Scrolling to stored y ***** 

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

function scrollToY() {
	window.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 host and y-scroll value ***** 

function GM_setY(){
	ys[host] = window.pageYOffset; 
// Wrapped in setTimeout for http://wiki.greasespot.net/0.7.20080121.0_compatibility
	if (showAlert) {
	setTimeout(function() {GM_setValue('ys', ys.toSource()); alert(host +": set value - " +ys[host]); }, 500);
		}else  {
	setTimeout(function() {GM_setValue('ys', ys.toSource()); }, 500);
		}
	};


GM_registerMenuCommand("ScrollTo_setY", GM_setY);


// alert('end of script');