Skip to content

Instantly share code, notes, and snippets.

@ThatsJustCheesy
Last active July 31, 2022 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThatsJustCheesy/dd4e77251265a2015eae189d0f654380 to your computer and use it in GitHub Desktop.
Save ThatsJustCheesy/dd4e77251265a2015eae189d0f654380 to your computer and use it in GitHub Desktop.
Always show side menu on UTSC's website because people (like me) forget it exists
// ==UserScript==
// @name Navigable UTSC Website
// @description Auto-shows the side menu on UTSC's website, because people forget it exists and attempt to use Google instead.
// NOTE: Small window sizes break this.
// @match *://www.utsc.utoronto.ca/*
// ==/UserScript==
function inIframe() {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
const menuButton = document.querySelector('#nav-list');
if (!inIframe()) {
menuButton.click();
menuButton.remove();
// Awful horrible hack bad.
const wrapperFrame = document.createElement('iframe');
wrapperFrame.src = window.location;
wrapperFrame.style.height = '100%';
wrapperFrame.style.width = 'calc(100% - 280px)';
wrapperFrame.style.marginLeft = '280px';
wrapperFrame.style.border = 'none';
document.body.style.overflow = 'hidden';
document.body.style.transform = 'translateX(-280px)';
jQuery('body > *').wrapAll(jQuery(wrapperFrame));
const menu = document.querySelector('#main-menu');
menu.querySelector('.search-header-button').remove();
menu.querySelector('nav').style.marginTop = '0';
document.body.appendChild(menu);
// Sync iframe location back up to window location
document.querySelector('body > iframe').addEventListener('load', event => {
if (window.location.href !== event.target.contentWindow.location.href) {
history.pushState({}, '', event.target.contentWindow.location.href);
}
});
} else {
menuButton.style.visibility = 'hidden';
menuButton.style.pointerEvents = 'none';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment