Last active
September 11, 2018 05:53
-
-
Save summersab/9f08f1bacbece054ab547943bea39c06 to your computer and use it in GitHub Desktop.
Modifications to Order Desk side-menu and order number float
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Order Desk | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author summersab | |
// @include https://app.orderdesk.me* | |
// @grant none | |
// @run-at document-body | |
// @updateURL https://cdn.rawgit.com/summersab/9f08f1bacbece054ab547943bea39c06/raw/91f0375de7c6fb51020d9344feacd8c6ed58a933/order-desk-userscript.js | |
// ==/UserScript== | |
// This script turns the drop-down menu in Order Desk into a side-menu when the window width is below 780px. | |
// It also turns the order number into a sticky-nav/float at the top of the screen when scrolling down | |
// MAKE SURE to change the "Run at" parameter to document-body or else it will conflict with the template editor. | |
// | |
(function() { | |
'use strict'; | |
if (document.documentURI == "https://app.orderdesk.me/dashboard") { | |
var time = new Date().getTime(); | |
$(document.body).bind("keypress", function(e) { | |
time = new Date().getTime(); | |
}); | |
function refresh() { | |
if(new Date().getTime() - time >= 60000) | |
window.location.reload(true); | |
else | |
setTimeout(refresh, 10000); | |
} | |
setTimeout(refresh, 10000); | |
} | |
$('#mainsidebar').children().first().on("click", function(){ | |
$('#mainsidebar').next().attr('style', 'margin-left: 275px !important'); | |
$('#mainsidebar').attr('style', 'position: fixed; z-index: 100'); | |
$('#sidebar-menu').attr('style', 'overflow-y: scroll; height: -webkit-fill-available;'); | |
}); | |
var $div = $('#mainsidebar').children().first(); | |
var observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
if (mutation.attributeName === "class") { | |
var attributeValue = $(mutation.target).prop(mutation.attributeName); | |
if (attributeValue == "btn btn-navbar hidden-desktop collapsed") { | |
$('#mainsidebar').next().attr('style', 'margin-left: 20px !important'); | |
$('#mainsidebar').removeAttr('style', 'position: fixed'); | |
$('#sidebar-menu').removeAttr('style', 'overflow-y: scroll; height: -webkit-fill-available;'); | |
} | |
} | |
}); | |
}); | |
observer.observe($div[0], { | |
attributes: true | |
}); | |
var sibling = $("#mainsidebar").next().children().first(); | |
$("#mainsidebar").next().children().first().html(sibling.html() + '<div class="row-fluid" style="position: fixed; background-color: rgb(255, 255, 255); top: 40px; display: none; opacity: 1;" id="sticky-nav"><div class="span12" style="margin-bottom: 6px;"><h1 class="pull-left" style="white-space: nowrap;">Order #<span class="unc_path">1490532458</span></h1><h1 class="pull-left" style="margin-left: 15px; color: #B1B0AD;"><small style="color: #B1B0AD;">2018-07-04 19:56:40</small></h1></div></div>'); | |
$(window).scroll(function() { | |
var pos = $(this).scrollTop(); | |
var sliderHeight = window.innerHeight; | |
var windowWidth = $(window).width(); | |
if ((pos >= (sliderHeight - 65)) && (windowWidth > 700)) { | |
$("#sticky-nav").slideDown(250); | |
} else if ((pos < (sliderHeight - 65)) && (windowWidth > 700)) { | |
$("#sticky-nav").slideUp(250); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment