ScrollTo_Y | Vivre

Autoscroll to set Y-position on specific Hosts

目前為 2016-02-22 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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');