Metric Unit Converter - AliExpress (Dark Mode)

Convert metric units to standard units and kilometers to miles per hour (km/h) with a convenient popup. Toggle the conversion tool using the hotkey Ctrl+Shift+X.

  1. // ==UserScript==
  2. // @name Metric Unit Converter - AliExpress (Dark Mode)
  3. // @namespace CriminalMuppet
  4. // @version 1.0
  5. // @license MIT
  6. // @description Convert metric units to standard units and kilometers to miles per hour (km/h) with a convenient popup. Toggle the conversion tool using the hotkey Ctrl+Shift+X.
  7. // @include https://www.aliexpress.us/*
  8. // @include https://www.aliexpress.com/*
  9. // @include https://*.aliexpress.*/*
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. // Create a popup element
  14. const popup = document.createElement("div");
  15. popup.style.position = "fixed";
  16. popup.style.top = "10px";
  17. popup.style.right = "10px";
  18. popup.style.padding = "10px";
  19. popup.style.background = "#333"; // Dark background color
  20. popup.style.border = "1px solid #555"; // Dark border color
  21. popup.style.zIndex = "9999";
  22. popup.style.display = "none"; // Initially hide the popup
  23.  
  24. // Add HTML content for the popup
  25. popup.innerHTML = `
  26. <input type="text" id="inputValue" placeholder="Enter value (metric)">
  27. <select id="fromUnit">
  28. <option value="mm">mm</option>
  29. <option value="cm">cm</option>
  30. <option value="m">m</option>
  31. <option value="km">km/h</option>
  32. </select>
  33. <span>to</span>
  34. <select id="toUnit">
  35. <option value="inches">inches</option>
  36. <option value="feet">feet</option>
  37. <option value="mph">mph</option>
  38. </select>
  39. <button id="convertButton">Convert</button>
  40. <div id="result" style="color: #fff;"></div> <!-- Light text on dark background -->
  41. `;
  42.  
  43. // Append the popup to the body
  44. document.body.appendChild(popup);
  45.  
  46. // Add event listener to the hotkey combination (Ctrl+Shift+X)
  47. document.addEventListener("keydown", (event) => {
  48. if (event.ctrlKey && event.shiftKey && event.key === "X") {
  49. togglePopup();
  50. }
  51. });
  52.  
  53. // Function to toggle the popup visibility
  54. function togglePopup() {
  55. if (popup.style.display === "none" || popup.style.display === "") {
  56. popup.style.display = "block";
  57. } else {
  58. popup.style.display = "none";
  59. }
  60. }
  61.  
  62. // Function to perform the conversion
  63. function convert() {
  64. const inputValue = document.getElementById("inputValue").value;
  65. const fromUnit = document.getElementById("fromUnit").value;
  66. const toUnit = document.getElementById("toUnit");
  67. const result = document.getElementById("result");
  68.  
  69. const value = parseFloat(inputValue);
  70.  
  71. if (!isNaN(value)) {
  72. let convertedValue = value;
  73.  
  74. // Perform the metric to standard unit conversion
  75. if (fromUnit === "mm" && toUnit.value === "inches") {
  76. convertedValue = value * 0.0393701;
  77. } else if (fromUnit === "cm" && toUnit.value === "inches") {
  78. convertedValue = value * 0.393701;
  79. } else if (fromUnit === "m" && toUnit.value === "inches") {
  80. convertedValue = value * 39.3701;
  81. } else if (fromUnit === "km") {
  82. toUnit.value = "mph";
  83. convertedValue = value * 0.621371;
  84. } else if (fromUnit === "mm" && toUnit.value === "feet") {
  85. convertedValue = value * 0.00328084;
  86. } else if (fromUnit === "cm" && toUnit.value === "feet") {
  87. convertedValue = value * 0.0328084;
  88. } else if (fromUnit === "m" && toUnit.value === "feet") {
  89. convertedValue = value * 3.28084;
  90. }
  91.  
  92. result.textContent = `${value} ${fromUnit} is approximately ${convertedValue.toFixed(2)} ${toUnit.value}.`;
  93. } else {
  94. result.textContent = "Invalid input. Please enter a valid number.";
  95. }
  96. }
  97.  
  98. // Add event listener to the conversion button
  99. const convertButton = document.getElementById("convertButton");
  100. convertButton.addEventListener("click", convert);
  101.  
  102. // Add event listener to the "fromUnit" select to update "toUnit" immediately
  103. const fromUnitSelect = document.getElementById("fromUnit");
  104. fromUnitSelect.addEventListener("change", () => {
  105. const selectedFromUnit = fromUnitSelect.value;
  106. const toUnitSelect = document.getElementById("toUnit");
  107.  
  108. if (selectedFromUnit === "km") {
  109. toUnitSelect.value = "mph";
  110. }
  111. });
  112.  
  113. // Add event listener to convert when hitting Enter in the value textbox
  114. const inputValueField = document.getElementById("inputValue");
  115. inputValueField.addEventListener("keydown", (event) => {
  116. if (event.key === "Enter") {
  117. convert();
  118. }
  119. });
  120. })();

QingJ © 2025

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