Add bounding boxes to GlyphWiki

Add bounding boxes to 200px GlyphWiki preview images that approximate the one on the Glyph Editor

  1. // ==UserScript==
  2. // @name Add bounding boxes to GlyphWiki
  3. // @namespace szc
  4. // @description Add bounding boxes to 200px GlyphWiki preview images that approximate the one on the Glyph Editor
  5. // @include /^https?://(en\.|ko\.|zhs\.|zht\.|)glyphwiki\.org/.*$/
  6. // @version 1
  7. // @grant GM_addStyle
  8. // ==/UserScript==
  9.  
  10. function addClasses() {
  11. let images = document.getElementsByClassName('glyph');
  12. for (var i = 0; i < images.length; i++) {
  13. let image = images.item(i);
  14. if (
  15. image.classList.contains('thumb100')
  16. ||
  17. image.classList.contains('thumb')
  18. ) {
  19. continue;
  20. }
  21. let wrapper = document.createElement('div');
  22. let boundingBox = document.createElement('div');
  23.  
  24. wrapper.classList.add('x-glyph-200-wrapper');
  25. boundingBox.classList.add('x-glyph-200-bounding-box');
  26. wrapper.innerHTML = image.outerHTML + boundingBox.outerHTML;
  27. image.outerHTML = wrapper.outerHTML;
  28. }
  29. }
  30.  
  31. function addStyles() {
  32. GM_addStyle(`
  33. .x-glyph-200-wrapper {
  34. position: relative;
  35. display: inline-block;
  36. }
  37.  
  38. .x-glyph-200-bounding-box {
  39. position: absolute;
  40. top: 0;
  41. border: 1px dotted darkgrey;
  42. content: "";
  43. height: 176px;
  44. width: 176px;
  45. margin-top: calc(12px + 1em);
  46. margin-left: 12px;
  47. }
  48.  
  49. .compare ~ .x-glyph-200-bounding-box {
  50. margin-top: calc(12px + 1em);
  51. margin-left: calc(12px + 1em);
  52. }
  53. `);
  54. }
  55.  
  56. addClasses();
  57. addStyles();