Skip to content

Instantly share code, notes, and snippets.

@thekalinga
Last active January 11, 2022 21:06
Show Gist options
  • Save thekalinga/3920b61085bfabcea538609b9797718d to your computer and use it in GitHub Desktop.
Save thekalinga/3920b61085bfabcea538609b9797718d to your computer and use it in GitHub Desktop.
Lexico beautifier.user.js
// ==UserScript==
// @name Lexico beautifier
// @namespace http://tampermonkey.net/
// @version 0.1
// @author You
// @match https://www.lexico.com/en/definition/*
// @match https://lexico.com/en/definition/*
// @match https://www.lexico.com/definition/*
// @match https://lexico.com/definition/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function undo() {
removeClass(document.getElementsByTagName('body')[0], 'toggle');
toggle.src = showNavIcon;
}
function apply() {
addClass(document.getElementsByTagName('body')[0], 'toggle');
toggle.src = hideNavIcon;
}
function addToggleClass(el) {
addClass(el, 'toggleable');
}
function addToggleableClasses() {
document.querySelectorAll('.topHeader').forEach(el => {
addToggleClass(el);
});
document.querySelectorAll('.burger').forEach(el => {
addToggleClass(el);
});
document.querySelectorAll('#sidebar').forEach(el => {
addToggleClass(el);
});
document.querySelectorAll('.sideBanner').forEach(el => {
addToggleClass(el);
});
document.querySelectorAll('.violbox').forEach(el => {
addToggleClass(el);
});
document.querySelectorAll('#feedbackTab').forEach(el => {
addToggleClass(el);
});
document.querySelectorAll('#footer').forEach(el => {
addToggleClass(el);
});
document.querySelectorAll('.socials').forEach(el => {
addToggleClass(el);
});
document.querySelectorAll('.mobile_banner').forEach(el => {
addToggleClass(el);
});
}
function applyMiscChanges() {
var headerTransitionFromAbsoluteToFixed = document.querySelector('.mainHeader');
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type == "attributes" && mutation.attributeName === 'class' && mutation.target.classList.contains('fixed')) {
document.querySelectorAll('.lex-content').forEach(el => {
addClass(el, 'fixed-header');
});
}
});
});
observer.observe(headerTransitionFromAbsoluteToFixed, {
attributes: true //configure it to listen to attribute changes
});
}
addToggleableClasses();
applyMiscChanges();
// misc
document.querySelectorAll('.headerContent .logo').forEach(el => {
el.style.margin = '44px 20px 33px 20px';
});
document.querySelectorAll('.headerContent .searchField').forEach(el => {
el.style.marginLeft = '20px';
});
var showing = false;
var hideNavIcon = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+DQo8c3ZnDQogICB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciDQogICB3aWR0aD0iMTAwJSINCiAgIGhlaWdodD0iMTAwJSINCiAgIHZpZXdCb3g9IjAgMCAyMDQ4IDE3OTIiPg0KICA8cGF0aA0KICAgICBkPSJNMCA4OTZxMC0xMzAgNTEtMjQ4LjV0MTM2LjUtMjA0IDIwNC0xMzYuNSAyNDguNS01MWg3NjhxMTMwIDAgMjQ4LjUgNTF0MjA0IDEzNi41IDEzNi41IDIwNCA1MSAyNDguNS01MSAyNDguNS0xMzYuNSAyMDQtMjA0IDEzNi41LTI0OC41IDUxaC03NjhxLTEzMCAwLTI0OC41LTUxdC0yMDQtMTM2LjUtMTM2LjUtMjA0LTUxLTI0OC41ek0xNDA4IDE0MDhxMTA0IDAgMTk4LjUtNDAuNXQxNjMuNS0xMDkuNSAxMDkuNS0xNjMuNSA0MC41LTE5OC41LTQwLjUtMTk4LjUtMTA5LjUtMTYzLjUtMTYzLjUtMTA5LjUtMTk4LjUtNDAuNS0xOTguNSA0MC41LTE2My41IDEwOS41LTEwOS41IDE2My41LTQwLjUgMTk4LjUgNDAuNSAxOTguNSAxMDkuNSAxNjMuNSAxNjMuNSAxMDkuNSAxOTguNSA0MC41eiINCiAgICAgaWQ9InBhdGgyIg0KICAgICBzdHlsZT0iZmlsbDojZmZhYTc1O2ZpbGwtb3BhY2l0eToxIiAvPg0KPC9zdmc+';
var showNavIcon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIHZpZXdCb3g9IjAgMCAyMDQ4IDE3OTIiPjxwYXRoIGZpbGw9InJnYigxODksMTg5LDE4OSkiIGQ9Ik0xMTUyIDg5NnEwLTEwNC00MC41LTE5OC41dC0xMDkuNS0xNjMuNS0xNjMuNS0xMDkuNS0xOTguNS00MC41LTE5OC41IDQwLjUtMTYzLjUgMTA5LjUtMTA5LjUgMTYzLjUtNDAuNSAxOTguNSA0MC41IDE5OC41IDEwOS41IDE2My41IDE2My41IDEwOS41IDE5OC41IDQwLjUgMTk4LjUtNDAuNSAxNjMuNS0xMDkuNSAxMDkuNS0xNjMuNSA0MC41LTE5OC41ek0xOTIwIDg5NnEwLTEwNC00MC41LTE5OC41dC0xMDkuNS0xNjMuNS0xNjMuNS0xMDkuNS0xOTguNS00MC41aC0zODZxMTE5IDkwIDE4OC41IDIyNHQ2OS41IDI4OC02OS41IDI4OC0xODguNSAyMjRoMzg2cTEwNCAwIDE5OC41LTQwLjV0MTYzLjUtMTA5LjUgMTA5LjUtMTYzLjUgNDAuNS0xOTguNXpNMjA0OCA4OTZxMCAxMzAtNTEgMjQ4LjV0LTEzNi41IDIwNC0yMDQgMTM2LjUtMjQ4LjUgNTFoLTc2OHEtMTMwIDAtMjQ4LjUtNTF0LTIwNC0xMzYuNS0xMzYuNS0yMDQtNTEtMjQ4LjUgNTEtMjQ4LjUgMTM2LjUtMjA0IDIwNC0xMzYuNSAyNDguNS01MWg3NjhxMTMwIDAgMjQ4LjUgNTF0MjA0IDEzNi41IDEzNi41IDIwNCA1MSAyNDguNXoiLz48L3N2Zz4=';
var toggle = document.createElement('img');
toggle.src = hideNavIcon;
toggle.style.position = 'fixed';
toggle.style.bottom = "10px";
toggle.style.right = "10px";
toggle.style.width = "20px";
toggle.style.height = "20px";
toggle.style.cursor = "pointer";
toggle.style.zIndex = "9999";
toggle.addEventListener("click", function() {
if (!showing) {
apply();
} else {
undo();
}
showing = !showing;
});
document.getElementsByTagName('body')[0].appendChild(toggle);
var newStyleToBeApplied = document.createElement('style');
newStyleToBeApplied.type= 'text/css';
newStyleToBeApplied.innerHTML = `
.toggle .toggleable {
display: none;
}
.toggle .mainHeader.fixed .burger.toggleable {
display: none;
}
.toggle .mainHeader.fixed .headerContent .searchField {
margin-right: 20px;
}
.toggle .lex-filling {
padding: 0 20px;
}
.toggle .lex-content {
margin-top: 40px;
}
.toggle .lex-content.fixed-header {
margin-top: 120px;
}
`;
document.getElementsByTagName('head')[0].appendChild(newStyleToBeApplied);
document.querySelectorAll('.wih-spa').forEach(v => { v.style.display = 'none'; });
document.querySelectorAll('.wih-player').forEach(v => { v.style.display = 'none'; });
document.querySelectorAll('.wih-spot-container').forEach(v => { v.style.display = 'none'; });
apply();
showing = !showing;
function hasClass(el, className) {
if (el.classList) {
return el.classList.contains(className);
} else {
return !!el.className.match(new RegExp('(\\s|^)' + className + '(\\s|$)'));
}
}
function addClass(el, className) {
if (el.classList) {
el.classList.add(className);
}
else if (!hasClass(el, className)) {
el.className += " " + className;
}
}
function removeClass(el, className) {
if (el.classList) {
el.classList.remove(className);
} else if (hasClass(el, className)) {
var reg = new RegExp('(\\s|^)' + className + '(\\s|$)');
el.className=el.className.replace(reg, ' ');
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment