NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name Coub Scroll Arrows
// @version 0.1.2
// @license MIT
// @description Adds up and down arrow buttons for scrolling by clicks
// @author Gertykhon
// @match https://coub.com
// @match https://coub.com/*
// @exclude https://coub.com/view/*
// @exclude https://coub.com/embed/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=coub.com
// @grant none
// ==/UserScript==
(function () {
'use strict';
var b = "auto"; //scroll behavior smooth/auto
var adown = document.createElement("div");
var aup = document.createElement("div");
var style = "position:fixed;z-index:9900;right:20px;opacity:50%;background-color:#555;color:#fff;font-weight:900;display:table-cell;" +
"width:50px;height:50px;border-radius:25px;font-size:20pt;padding:8px 0 0 0;margin:0px;text-align:center;cursor:pointer;";
adown.style = style + "bottom:20px;";
adown.innerHTML = '<span style="line-height:0;">↓</span>';
aup.style = style + "bottom:90px;";
aup.innerHTML = '<span style="line-height:0;">↑</span>';
adown.onclick = function () {
scroll(false);
};
aup.onclick = function () {
scroll(true);
};
document.body.append(adown);
document.body.append(aup);
function scroll(direction) {
var story = document.querySelector("div.story__coub");
var active, target;
if (story) {
active = document.querySelector("div.story__coub>div.coub.active");
target = direction ? active.parentElement.previousElementSibling.previousElementSibling.firstChild :
active.parentElement.nextSibling.nextElementSibling.firstChild;
}
else {
active = document.querySelector("div.coub.active");
target = direction ? active.previousSibling : active.nextSibling;
if (!target) target = direction ? active.parentElement.previousSibling.lastChild : active.parentElement.nextSibling.firstChild;
if (!target.classList.contains("coub")) target = direction ? target.previousSibling : target.nextSibling;
}
if (!target) return;
target.scrollIntoView({
behavior: b,
block: "end"
});
}
})();