Greasy Fork is available in English.
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.
- // ==UserScript==// @name Metric Unit Converter - Alibaba (Dark Mode)// @namespace CriminalMuppet// @version 1.0// @license MIT// @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.// @include https://www.alibaba.*/*// @include https://www.alibaba.com/*// @include https://*.alibaba.*/*// ==/UserScript==(function() {// Create a popup elementconst popup = document.createElement("div");popup.style.position = "fixed";popup.style.top = "10px";popup.style.right = "10px";popup.style.padding = "10px";popup.style.background = "#333"; // Dark background colorpopup.style.border = "1px solid #555"; // Dark border colorpopup.style.zIndex = "9999";popup.style.display = "none"; // Initially hide the popup// Add HTML content for the popuppopup.innerHTML = `<input type="text" id="inputValue" placeholder="Enter value (metric)"><select id="fromUnit"><option value="mm">mm</option><option value="cm">cm</option><option value="m">m</option><option value="km">km/h</option></select><span>to</span><select id="toUnit"><option value="inches">inches</option><option value="feet">feet</option><option value="mph">mph</option></select><button id="convertButton">Convert</button><div id="r###lt" style="color: #fff;"></div> <!-- Light text on dark background -->`;// Append the popup to the bodydocument.body.appendChild(popup);// Add event listener to the hotkey combination (Ctrl+Shift+X)document.addEventListener("keydown", (event) => {if (event.ctrlKey && event.shiftKey && event.key === "X") {togglePopup();}});// Function to toggle the popup visibilityfunction togglePopup() {if (popup.style.display === "none" || popup.style.display === "") {popup.style.display = "block";} else {popup.style.display = "none";}}// Function to perform the conversionfunction convert() {const inputValue = document.getElementById("inputValue").value;const fromUnit = document.getElementById("fromUnit").value;const toUnit = document.getElementById("toUnit");const r###lt = document.getElementById("r###lt");const value = parseFloat(inputValue);if (!isNaN(value)) {let convertedValue = value;// Perform the metric to standard unit conversionif (fromUnit === "mm" && toUnit.value === "inches") {convertedValue = value * 0.0393701;} else if (fromUnit === "cm" && toUnit.value === "inches") {convertedValue = value * 0.393701;} else if (fromUnit === "m" && toUnit.value === "inches") {convertedValue = value * 39.3701;} else if (fromUnit === "km") {toUnit.value = "mph";convertedValue = value * 0.621371;} else if (fromUnit === "mm" && toUnit.value === "feet") {convertedValue = value * 0.00328084;} else if (fromUnit === "cm" && toUnit.value === "feet") {convertedValue = value * 0.0328084;} else if (fromUnit === "m" && toUnit.value === "feet") {convertedValue = value * 3.28084;}r###lt.textContent = `${value} ${fromUnit} is approximately ${convertedValue.toFixed(2)} ${toUnit.value}.`;} else {r###lt.textContent = "Invalid input. Please enter a valid number.";}}// Add event listener to the conversion buttonconst convertButton = document.getElementById("convertButton");convertButton.addEventListener("click", convert);// Add event listener to the "fromUnit" select to update "toUnit" immediatelyconst fromUnitSelect = document.getElementById("fromUnit");fromUnitSelect.addEventListener("change", () => {const selectedFromUnit = fromUnitSelect.value;const toUnitSelect = document.getElementById("toUnit");if (selectedFromUnit === "km") {toUnitSelect.value = "mph";}});// Add event listener to convert when hitting Enter in the value textboxconst inputValueField = document.getElementById("inputValue");inputValueField.addEventListener("keydown", (event) => {if (event.key === "Enter") {convert();}});})();