Derpibooru - Scroll-to

Immediately go to the part-scaled image, fill the screen as much as possible. Also adds more convenient next/prev navigation

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Derpibooru - Scroll-to
// @namespace   Selbi
// @include     http*://*derpibooru.org/images/*
// @version     2.1.2
// @description Immediately go to the part-scaled image, fill the screen as much as possible. Also adds more convenient next/prev navigation
// ==/UserScript==

let prev = document.querySelector(".js-prev").cloneNode(true);
let next = document.querySelector(".js-next").cloneNode(true);
prev.querySelector("i").classList = "fa fa-play fa-flip-horizontal";
next.querySelector("i").classList = "fa fa-play";

let jk = document.createElement("div");
jk.innerHTML = prev.outerHTML + " " + next.outerHTML;
jk.style.position = "fixed";
jk.style.right = "10px";
jk.style.bottom = "10px";
jk.style.opacity = "0.1";
jk.style.fontSize = "6em";

let body = document.querySelector("body");
body.appendChild(jk);

document.onkeyup = function(e) {
  if (document.activeElement.tagName.toLowerCase() == "body") {
    if (e.key == "ArrowLeft") {
      prev.click();
    } else if (e.key =="ArrowRight") {
      next.click();
    }
  }
};

///

document.querySelector("body").style.minHeight = "1600px";

window.addEventListener('load', function() {
  clickAndScroll();
}, true);

function clickAndScroll() {
  let img = document.querySelector(".image-show-container .image-target");
  img.click();
  let y = getTargetY(img)
  scrollToY(y);
}

function getTargetY(elem) {
  let y = Math.round(elem.getBoundingClientRect().top + window.scrollY - 3);
  return y;
}

function scrollToY(y) {
  window.scrollTo({top: y});
}