Skip to content

Instantly share code, notes, and snippets.

@TheBronx
Last active March 16, 2017 11:58
Show Gist options
  • Save TheBronx/fdc532db27c17437c39c to your computer and use it in GitHub Desktop.
Save TheBronx/fdc532db27c17437c39c to your computer and use it in GitHub Desktop.
Centers the new slider on Feedly
// ==UserScript==
// @name Feedly Centered Slider
// @namespace http://salvatorelab.es
// @version 2.0
// @description Centers the slider on Feedly
// @match http://feedly.com/*
// @grant GM_addStyle
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
// ==/UserScript==
function centerContentAndArrows() {
var floatingContent = document.getElementsByClassName('floatingEntryContent')[0];
if (floatingContent !== undefined) {
var contentWidth = floatingContent.offsetWidth;
floatingContent.style = "right: calc(50% - " + (contentWidth/2) + "px) !important;";
var side = ($( window ).width() - contentWidth)/2 + 25;
GM_addStyle(".slideBumper-right {right: "+side+"px;}");
GM_addStyle(".slideBumper-left {left: "+side+"px;}");
}
}
function centerHeader() {
var floatingContent = document.getElementsByClassName('floatingEntryContent')[0];
if (floatingContent !== undefined) {
var contentWidth = floatingContent.offsetWidth;
floatingContent.style = "right: calc(50% - " + (contentWidth/2) + "px) !important;";
var header = $('.floatingEntryContentSlide .shareBarFixedHolder .headerInfo');
header.css('right', '50%').css('right', '-=' + (contentWidth/2) + 'px');
}
}
//arrows
GM_addStyle(".bumperHolder {position: relative !important;");
GM_addStyle(".slideBumper-right {position: fixed !important; right: 0px; left: auto !important;}");
GM_addStyle(".slideBumper-left {position: fixed !important; left: 0px; right: auto !important;}");
window.onresize = function() {
centerContentAndArrows();
centerHeader();
};
var insertedNodes = [];
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
for(var i = 0; i < mutation.addedNodes.length; i++) {
if (mutation.addedNodes[i].classList.contains('floatingEntryContent')) {
centerContentAndArrows();
}
if (mutation.target.classList.contains('headerInfo')) {
centerHeader();
}
}
});
});
observer.observe(document, {
childList: true,
subtree: true
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment