| 1 |
/* vim:fileencoding=utf-8 |
| 2 |
* |
| 3 |
* Copyright (C) 2019 Kovid Goyal <kovid at kovidgoyal.net> |
| 4 |
* |
| 5 |
* Distributed under terms of the GPLv3 license |
| 6 |
*/ |
| 7 |
|
| 8 |
(function() { |
| 9 |
"use strict"; |
| 10 |
|
| 11 |
var num_tries = 0; |
| 12 |
var style_id = 'a' + Math.random().toString(36).slice(2); |
| 13 |
|
| 14 |
function fix_google_markup() { |
| 15 |
try { |
| 16 |
var cc = document.getElementById('center_col'); |
| 17 |
if (!cc) { |
| 18 |
if (++num_tries > 10) return; |
| 19 |
return setTimeout(fix_google_markup, 100); |
| 20 |
} |
| 21 |
|
| 22 |
// figure out if they actually got a dictionary card |
| 23 |
var is_dictionary_result = !!document.querySelector('.lr_container, .lr_dct_ent'); |
| 24 |
// grab the raw query |
| 25 |
var q = new URLSearchParams(location.search.slice(1)).get('q') || '' |
| 26 |
|
| 27 |
if (is_dictionary_result) { |
| 28 |
var maxW = 'calc(100vw - 25px)'; |
| 29 |
cc.style.maxWidth = maxW; |
| 30 |
cc.style.marginLeft = '0'; |
| 31 |
|
| 32 |
['rcnt','cnt','search'] |
| 33 |
.forEach(function(id) { |
| 34 |
var e = document.getElementById(id); |
| 35 |
if (e) { |
| 36 |
if (id==='search') e.style.maxWidth = maxW; |
| 37 |
else if (id==='cnt') e.style.paddingTop = '0'; |
| 38 |
else e.style.marginLeft = '0'; |
| 39 |
} |
| 40 |
}); |
| 41 |
|
| 42 |
cc.style.paddingLeft = '0'; |
| 43 |
cc.style.paddingRight = '6px'; |
| 44 |
|
| 45 |
// constrain define text |
| 46 |
document.querySelectorAll('[data-topic]') |
| 47 |
.forEach(e => e.style.maxWidth = maxW); |
| 48 |
|
| 49 |
// Ensure footer stays at bottom - with null check |
| 50 |
var cnt = document.getElementById('cnt'); |
| 51 |
if (cnt) cnt.style.minHeight = '100vh'; |
| 52 |
} |
| 53 |
|
| 54 |
// hide bunch of useful UI elements |
| 55 |
['sfcnt', 'top_nav', 'easter-egg', 'topstuff', 'searchform', 'appbar', 'before-appbar'] |
| 56 |
.forEach(function(id){ |
| 57 |
var e = document.getElementById(id); |
| 58 |
if (e && e.style) e.style.display = 'none'; |
| 59 |
}); |
| 60 |
// remove that promo sidebar, wrap rest nicely |
| 61 |
var promo = document.getElementById('promos'); |
| 62 |
if (promo) promo.remove(); |
| 63 |
|
| 64 |
document.querySelectorAll('[data-ved]') |
| 65 |
.forEach(e => e.style.maxWidth = '100%'); |
| 66 |
|
| 67 |
document.querySelectorAll('cite') |
| 68 |
.forEach(c => { |
| 69 |
var wrap = c.closest('div'); |
| 70 |
if (wrap) wrap.style.position = 'static'; |
| 71 |
}); |
| 72 |
} catch(e) { |
| 73 |
console.error("fix_google_markup() failed with error:"); |
| 74 |
console.error(e); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
if (location.hostname === 'www.google.com') { |
| 79 |
window.addEventListener('DOMContentLoaded', fix_google_markup); |
| 80 |
|
| 81 |
// Re-run on resize to handle Google's dynamic layout changes |
| 82 |
window.addEventListener('resize', function() { |
| 83 |
// Reset try counter to handle DOM changes |
| 84 |
num_tries = 0; |
| 85 |
fix_google_markup(); |
| 86 |
}); |
| 87 |
} |
| 88 |
})(); |