Skip to content

Instantly share code, notes, and snippets.

@ElfhirDev
Last active July 15, 2016 15:23
Show Gist options
  • Save ElfhirDev/0c8cba11b13ff2f1afb4 to your computer and use it in GitHub Desktop.
Save ElfhirDev/0c8cba11b13ff2f1afb4 to your computer and use it in GitHub Desktop.
toolbar for scroll to top, scroll to bottom, other functionalities
// ==UserScript==
// @name jt-toolbar
// @namespace jt-toolbar
// @description toolbar for scroll to top, to bottom, and other functionalities
// @include *
// @version 1.22
// @grant none
// @require https://cdnjs.cloudflare.com/ajax/libs/zepto/1.1.6/zepto.min.js
// ==/UserScript==
$(document).ready(function () {
function addToolBar(selector) {
if ($('#backtotop').length == 0) {
$(selector).append('<div id="jt-toolbar"></div>');
var toolbar = $('#jt-toolbar');
toolbar.append('<div id=\'gototop\'>&#8593;</div>');
toolbar.append('<div id=\'gotobottom\'>&#8595;</div>');
toolbar.append('<div style="clear:both;"></div>');
toolbar.prepend('<div class=\'toggle\'>&#9000;</div>');
var toggle_toolbar_style = {
'cursor': 'pointer',
'float': 'left',
'margin': '-18px 0 0'
};
var jt_toolbar_style = {
'position': 'fixed',
'left': '98%',
'bottom': '6px',
'max-width':'40px',
'border': '1px solid #121212',
'z-index': '9999999'
};
var button_style_top = {
'bottom': '46px',
'margin': '1px',
'padding': '5px',
'width': '30px',
'height': '30px',
'z-index': '99999',
'font-size': '20px',
'text-align': 'center',
'line-height': '15px',
'background': 'rgba(0,0,0,0.8)',
'color': '#efefef',
'border-radius': '5px',
'box-shadow': 'inset 0 0 10px 10px rgba(0,0,0,0.5)',
'cursor': 'pointer'
};
var button_style_bottom = _.clone(button_style_top);
button_style_bottom['bottom'] = '5px';
toolbar.css(jt_toolbar_style);
var toggle = $('#jt-toolbar .toggle');
var gototop = $('#gototop');
var gotobottom = $('#gotobottom');
toggle.css(toggle_toolbar_style);
gototop.css(button_style_top);
gotobottom.css(button_style_bottom);
gototop.on('click', function (e) {
document.body.scrollTop = document.documentElement.scrollTop = 0;
});
gotobottom.on('click', function (e) {
window.scrollTo(0, document.body.scrollHeight);
});
$('#jt-toolbar .toggle').on('mousedown', function (e) {
switch (e.which) {
case 1:
gototop.toggle();
gotobottom.toggle();
break;
case 3:
$('#jt-toolbar').remove();
break;
case 2:
default:
gototop.toggle();
gotobottom.toggle();
break;
}
});
}
}
function init() {
var host = window.location.host;
console.info('init jt-toolbar !');
switch(host) {
case "tympanus.net":
addToolBar('.ct-container');
break;
case "www.deezer.com":
console.info(host);
addToolBar('body');
break;
// Exceptions
case "accounts.google.com":
case "daneden.github.io":
break;
// Exceptions
default:
console.info("Default " + host);
addToolBar('body:not(iframe html body)');
break;
}
console.info("jt-toolbar existense is " + ($('#jt-toolbar').length != 0));
}
init();
});
@ElfhirDev
Copy link
Author

ElfhirDev commented Jul 4, 2016

1.0 : Initial script
1.1 : Do not add the tool widget in iframe content.
1.2 : Add location detection for particular website (codrops)
1.21 : Try to add for deezer.com ; add status info about "is it added or not" ; remove unused underscore dependency.
1.22 : Ignore deezer.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment