Wikipedia, set "float: left" for <figure> with width over 50 em

Setting "float: left" for <figure> with width over 50 em, avoids texts(left aligned) being squeezed too short.

  1. // ==UserScript==
  2. // @name Wikipedia, set "float: left" for <figure> with width over 50 em
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-03-21.2
  5. // @description Setting "float: left" for <figure> with width over 50 em, avoids texts(left aligned) being squeezed too short.
  6. // @author Al Arcus
  7. // @match **.wikipedia.org/**
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. // Select all <figure> elements whose width is over 50em
  16. const figures = document.querySelectorAll('figure');
  17.  
  18. figures.forEach(figure => {
  19. // Get the computed width of the figure
  20. const figureWidth = parseFloat(window.getComputedStyle(figure).width);
  21. console.log('Figure width:', figureWidth);
  22.  
  23. // Check if width is over 50em
  24. if (figureWidth > 50 * parseFloat(window.getComputedStyle(document.documentElement).fontSize)) {
  25. // Set the float property to left
  26. figure.style.float = 'left';
  27. figure.style.marginLeft = '0px';
  28. }
  29. });
  30. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址