Worldometers graph cosmetic fix and magnifier

Improve graph view

  1. // ==UserScript==
  2. // @name Worldometers graph cosmetic fix and magnifier
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  5. // @description Improve graph view
  6. // @author Konsto
  7. // @match https://www.worldometers.info/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. Element.prototype.revStyleSet = function(name, value){
  15. this.stylez = this.stylez ? this.stylez : {};
  16. this.stylez[name] = this.style[name];
  17. this.style[name] = value;
  18. }
  19.  
  20. Element.prototype.reverseTailored = function(){
  21. var thiz = this;
  22. if(this.stylez){
  23. var stylez = this.stylez;
  24. Object.keys(stylez).forEach(function(name) {
  25. thiz.style[name] = stylez[name];
  26. });
  27. this.stylez = null;
  28. }
  29. }
  30.  
  31. Element.prototype.isTailored = function(){
  32. return !!this.stylez;
  33. }
  34.  
  35. var rearrangeBars = function(gr){
  36. var bars = [];
  37. gr.querySelectorAll("g.highcharts-column-series > rect").forEach(function(bar){
  38. bars.push(bar);
  39. });
  40. var sum = 0;
  41. for(var i=1; i<bars.length-1; i++){
  42. var bar = bars[i];
  43. var prevX = parseFloat(bars[i-1].getAttribute("x"));
  44. var nextX = parseFloat(bars[i+1].getAttribute("x"));
  45. if(prevX < nextX){
  46. sum += (nextX-prevX);
  47. bar.setAttribute("x", (prevX+nextX)/2);
  48. }
  49. }
  50. var barWidth = Math.round(sum / bars.length * 0.25);
  51. barWidth = barWidth < 1 ? 1 : barWidth;
  52. bars.forEach(function(bar){
  53. bar.setAttribute("width", barWidth);
  54. });
  55. };
  56.  
  57. window.addEventListener("load", function(){
  58.  
  59. // Uncomment code below to remove annoying ads at right side
  60. /*
  61. setInterval(function(){
  62. document.querySelectorAll("iframe").forEach(function(fr){
  63. fr.remove();
  64. });
  65. }, 250);
  66. */
  67. document.querySelectorAll(".highcharts-container").forEach(function(gr){
  68.  
  69. if(!gr.querySelectorAll("input[type=checkbox]").length) return;
  70.  
  71. rearrangeBars(gr);
  72.  
  73. var open = document.createElement("span");
  74.  
  75. open.style.zIndex = 100000;
  76. open.style.position = "absolute";
  77. open.style.right = "1vh";
  78. open.style.top = "1vh";
  79. open.style.backgroundColor = "blue";
  80. open.style.color = "white";
  81. open.style.cursor = "pointer";
  82.  
  83. open.addEventListener("click", function(){
  84. rearrangeBars(gr);
  85. if(gr.isTailored()){
  86. document.getElementById("totallyWhite").remove();
  87. gr.reverseTailored();
  88. open.innerText = "[+]";
  89. return;
  90. }
  91. open.original = gr.cloneNode(true);
  92. var bg = document.createElement("span");
  93. bg.id = "totallyWhite";
  94. bg.style.position = "fixed";
  95. bg.style.left = 0;
  96. bg.style.top = 0;
  97. bg.style.color = "red";
  98. bg.style.backgroundColor = "white";
  99. bg.style.zIndex = 19;
  100. bg.style.opacity = 1;
  101. bg.innerText = "xxx";
  102. document.body.appendChild(bg);
  103.  
  104. var kX = window.innerWidth/gr.offsetWidth;
  105. var kY = window.innerHeight/gr.offsetHeight;
  106. console.info(kX + "-" + kY);
  107.  
  108. gr.revStyleSet("position", "fixed");
  109. gr.revStyleSet("left", "-" + window.innerWidth + "px");
  110. gr.revStyleSet("top", "0px");
  111. gr.revStyleSet("transform-origin", "left top");
  112.  
  113. if(kX < kY){
  114. gr.revStyleSet("transform", "scale(" + kX*2 + ", " + kX + ")");
  115. } else {
  116. gr.revStyleSet("transform", "scale(" + kX*2 + ", " + kY + ")");
  117. }
  118.  
  119. gr.revStyleSet("zIndex", 20);
  120. gr.revStyleSet("padding", 0);
  121. gr.revStyleSet("margin", 0);
  122. open.innerText = "[-]";
  123. });
  124.  
  125. open.innerText = "[+]";
  126. gr.appendChild(open);
  127. });
  128. });
  129. })();

QingJ © 2025

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