lookup.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. (function() {
  8. "use strict";
  9. var num_tries = 0;
  10. function fix_google_markup() {
  11. var cc = document.getElementById('center_col');
  12. var max_width = 'calc(100vw - 25px)';
  13. if (!cc) {
  14. if (++num_tries > 10) return;
  15. setTimeout(fix_google_markup, 100);
  16. return;
  17. }
  18. cc.style.maxWidth = max_width;
  19. cc.style.marginLeft = '0';
  20. var rcnt = document.getElementById('rcnt');
  21. if (rcnt) rcnt.style.marginLeft = '0';
  22. cc = document.getElementById('cnt');
  23. if (cc) cc.style.paddingTop = '0';
  24. var s = document.getElementById('search');
  25. if (s) s.style.maxWidth = max_width;
  26. var params = new URLSearchParams(document.location.search.substring(1));
  27. var q = params.get('q');
  28. if (q && q.startsWith('define:')) {
  29. cc.style.position = 'absolute';
  30. cc.style.top = '0';
  31. cc.style.left = '0';
  32. cc.style.paddingLeft = '6px';
  33. cc.style.paddingRight = '6px';
  34. var remove = ['sfcnt', 'top_nav', 'before-appbar', 'appbar', 'searchform', 'easter-egg', 'topstuff'];
  35. remove.forEach(function(id) {
  36. var elem = document.getElementById(id);
  37. if (elem) elem.style.display = 'none';
  38. });
  39. // make definitions text wrap
  40. document.querySelectorAll('[data-topic]').forEach(function(elem) { elem.style.maxWidth = max_width; });
  41. }
  42. var promo = document.getElementById('promos');
  43. if (promo) promo.parentNode.removeChild(promo);
  44. // make search results wrap
  45. document.querySelectorAll('[data-ved]').forEach(function(elem) { elem.style.maxWidth = max_width; });
  46. // the above wrapping causing overlapping text of the
  47. // search results and the citation, fix that
  48. document.querySelectorAll('cite').forEach(function(elem) {
  49. var d = elem.closest('div');
  50. if (d) d.style.position = 'static';
  51. });
  52. }
  53. if (window.location.hostname === 'www.google.com') {
  54. window.addEventListener('DOMContentLoaded', fix_google_markup);
  55. }
  56. })();