Add javascript to adapt design to Tumblr ADS.
This commit is contained in:
parent
1e1f56b337
commit
c8eb82b8e1
3 changed files with 36 additions and 0 deletions
23
static/scripts/tumblr-adapt.js
Normal file
23
static/scripts/tumblr-adapt.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
const isTumblr = new URLSearchParams(location.search).get("tumblr") == "true";
|
||||
console.log(isTumblr);
|
||||
|
||||
function adaptToTumblrLayout() {
|
||||
const header = document.querySelector('header');
|
||||
header.classList.add("tumblr");
|
||||
|
||||
const setHeaderOffset = () => {
|
||||
const height = header.offsetHeight + "px";
|
||||
document.documentElement.style.setProperty('--header-height', height);
|
||||
};
|
||||
|
||||
setHeaderOffset();
|
||||
window.addEventListener('resize', setHeaderOffset);
|
||||
|
||||
document.querySelectorAll("a").forEach(link => {
|
||||
const u = new URL(link.href);
|
||||
u.searchParams.set("tumblr", "true");
|
||||
link.href = u.toString();
|
||||
});
|
||||
}
|
||||
|
||||
if (isTumblr) adaptToTumblrLayout();
|
||||
Loading…
Reference in a new issue