// ==UserScript== // @name Opera Browser Rocker+Mouse Gestures + Search HighLight // @namespace OperaBrowserGestures // @description This script works on any browser and simulates the Opera Browser Mouse+Rocker Gestures, along with the Search HighLight and Units+Currency Converters, but with this script you can modify or disable them as you want. // @version 0.0.28 // @author hacker09 // @include * // @icon https://www.google.com/s2/favicons?domain=www.opera.com // @require https://code.jquery.com/jquery-3.5.1.min.js // @grant GM_registerMenuCommand // @grant GM_openInTab // @grant window.close // @grant GM_setValue // @grant GM_getValue // @run-at document-end // @downloadURL none // ==/UserScript== // *** Mouse Gesture Settings Below ***************************************************************************************************************************************** GM_registerMenuCommand("Enable/Disable Mouse Gestures", MouseGestures); //Adds an option to the tampermonkey menu if (GM_getValue("MouseGestures") !== true && GM_getValue("MouseGestures") !== false) { //If the value doesn't exist define as true GM_setValue("MouseGestures", true); //Defines the variable as true } //Finishes the if condition function MouseGestures() //Function to enable or disable the MouseGestures { //Starts the function MouseGestures if (GM_getValue("MouseGestures") === true) { //If the last config was true, set as false GM_setValue("MouseGestures", false); //Defines the variable as false } //Finishes the if condition else { //If the last config was false, set as true GM_setValue("MouseGestures", true); //Defines the variable as true location.reload(); //Reloads the page } //Finishes the else condition } //Finishes the function MouseGestures if (GM_getValue("MouseGestures") === true) //If the MouseGestures is enabled { //Starts the if condition const SENSITIVITY = 3; // Adjust the script mouse senvity here between 1 ~ 5 const TOLERANCE = 3; // Adjust the script mouse tolerance here between 1 ~ 5 const funcs = { //Variable to store the functions 'L': function() { //Function that will run when the mouse movement Left is performed window.history.back(); //Go Back }, //Finishes the mouse movement Left 'R': function() { //Function that will run when the mouse movement Right is performed window.history.forward(); //Go Foward }, //Finishes the mouse movement Right 'D': function() { //Function that will run when the mouse movement Down is performed if (IsShiftNotPressed === true) { //If the shift key isn't being pressed GM_openInTab(link, { //Open the link on a new tab active: true, //Focus on the new tab insert: true, //Insert the new tab after the actual tab setParent: true //Return to the tab the user was in }); //Open the link that was hovered setTimeout(function() { //Starts the settimeout function link = 'about:newtab'; //Make the script open a new browser tab if no links were hovered }, 100); //Finishes the settimeout function } //Finishes the if condition }, //Finishes the mouse movement Down 'UD': function() { //Function that will run when the mouse movement Up+Down is performed window.location.reload(); //Reload the Tab }, //Finishes the mouse movement Up+Down 'DR': function(e) { //Function that will run when the mouse movement Down+Right is performed window.top.close(); //Close the tab e.preventDefault(); //Prevent the default context menu from being opened e.stopPropagation(); //Prevent the default context menu from being opened }, //Finishes the mouse movement Down+Right 'DU': function() { //Function that will run when the mouse movement Down+Up is performed GM_openInTab(link, { //Open the link that was hovered active: false, //Don't focus on the new tab insert: true, //Insert the new tab after the actual tab setParent: true //Return to the tab the user was in }); //Open the link that was hovered on a new background tab setTimeout(function() { //Starts the setimeout function link = 'about:newtab'; //Make the script open a browser tab if no links were hovered }, 100); //Finishes the setimeout function } //Finishes the mouse movement Down+Up }; //Finishes the variable to store the functions // *** Below this line is the math codes that track the mouse movement gestures ******************************************************************************************* const s = 1 << ((7 - SENSITIVITY) << 1); const t1 = Math.tan(0.15708 * TOLERANCE), t2 = 1 / t1; let x, y, path; const tracer = function(e) { //Starts the const tracer let cx = e.clientX, cy = e.clientY, deltaX = cx - x, deltaY = cy - y, distance = deltaX * deltaX + deltaY * deltaY; if (distance > s) { let slope = Math.abs(deltaY / deltaX), direction = ''; if (slope > t1) { direction = deltaY > 0 ? 'D' : 'U'; } else if (slope <= t2) { direction = deltaX > 0 ? 'R' : 'L'; } if (path.charAt(path.length - 1) !== direction) { path += direction; } x = cx; y = cy; } }; //Finishes the const tracer window.addEventListener('mousedown', function(e) { //Add an advent listener to the page to detect when the mouse is clicked if (e.which === 3) { //Starts the if condition x = e.clientX; y = e.clientY; path = ""; window.addEventListener('mousemove', tracer, false); //Add an advent listener to the page to detect the mouse position } //Finishes the if condition }, false); //Finishes the advent listener var IsShiftNotPressed = true; //Variable to hold the shift key status window.addEventListener("contextmenu", function(e) { //Adds an advent listener to the page to know when the shift key is pressed or not if (e.shiftKey) { //If the shift key was pressed IsShiftNotPressed = false; //Variable to hold the shift key status window.open(link, '_blank', 'height=' + window.screen.height + ',width=' + window.screen.width); //Open the link on a new window } //Finishes the if condition if (LeftClicked === true) { //If the Left Click was released when the Rocker Mouse Gestures are activated e.preventDefault(); //Prevent the default context menu from being opened e.stopPropagation(); //Prevent the default context menu from being opened } //Finishes the if condition setTimeout(function() { //Starts the settimeout function IsShiftNotPressed = true; //Variable to hold the shift key status }, 500); //Finishes the settimeout function }, false); //Finishes the advent listener window.addEventListener('contextmenu', function(e) { //When the right click button is released window.removeEventListener('mousemove', tracer, false); //Stop tracking the mouse movements if (path !== "") { //Starts the if condition e.preventDefault(); //Prevent the default context menu from being opened if (funcs.hasOwnProperty(path)) { //Starts the if condition funcs[path](); } //Finishes the if condition } //Finishes the if condition }, false); //Finishes the advent listener var link; //Make the variable global Array.from(document.querySelectorAll('a')).forEach(Element => Element.onmouseover = function() { //Get all the a link elements and add an advent listener to the link element link = this.href; //Store the actual hovered link to a variable }); //Finishes the forEach } //Finishes the if condition // *** Rocker Mouse Gesture Settings Below *********************************************************************************************************************************** GM_registerMenuCommand("Enable/Disable Rocker Mouse Gestures", RockerMouseGestures); //Adds an option to the tampermonkey menu if (GM_getValue("RockerMouseGestures") !== true && GM_getValue("RockerMouseGestures") !== false) { //If the value doesn't exist define as false GM_setValue("RockerMouseGestures", false); //Defines the variable as false } //Finishes the if condition function RockerMouseGestures() //Function to enable or disable the RockerMouseGestures { //Starts the function RockerMouseGestures if (GM_getValue("RockerMouseGestures") === true) { //If the last config was true, set as false GM_setValue("RockerMouseGestures", false); //Defines the variable as false } //Finishes the if condition else { //If the last config was false, set as true GM_setValue("RockerMouseGestures", true); //Defines the variable as true location.reload(); //Reloads the page } //Finishes the else condition } //Finishes the function RockerMouseGestures if (GM_getValue("RockerMouseGestures") === true || GM_getValue("SearchHiLight") === true) //If the RockerMouseGestures or the SearchHiLight is enabled { //Starts the if condition var LeftClicked, RightClicked; //Make these variables global window.addEventListener("mousedown", function(e) { //Detect the right and left mouse clicks presses on the page switch (e.button) { //Start the switch condition case 0: //If Left Click was Pressed LeftClicked = true; //Set the variable LeftClicked as true break; //Don't execute the lines below if the Left Key was Pressed case 2: //If Right Click was Pressed RightClicked = true; //Set the variable RightClicked as true break; //Don't execute the lines below if the Right Key was Pressed } //Finishes the switch condition }, false); //Finishes the adventlistener mousedown window.addEventListener("mouseup", function(e) { //Detect the right and left mouse clicks releases on the page switch (e.button) { //Start the switch condition case 0: //If Left Click was released LeftClicked = false; //Set the variable LeftClicked as false break; //Don't execute the lines below if the Left Key was Pressed case 2: //If Right Click was released RightClicked = false; //Set the variable RightClicked as false break; //Don't execute the lines below if the Left Key was Pressed } //Finishes the switch condition if (LeftClicked && RightClicked === false) { //If Left was Clicked and then Right Click was released window.history.back(); //Go Back } //Finishes the if condition if (RightClicked && LeftClicked === false) { //If Right was Clicked and then Left Click was released window.history.forward(); //Go Foward } //Finishes the if condition }, false); //Finishes the adventlistener mouseup } //Finishes the if condition // *** SearchHighLight Below ************************************************************************************************************************************************* GM_registerMenuCommand("Enable/Disable SearchHiLight", SearchHiLight); //Adds an option to the tampermonkey menu if (GM_getValue("SearchHiLight") !== true && GM_getValue("SearchHiLight") !== false) { //If the value doesn't exist define as true GM_setValue("SearchHiLight", true); //Defines the variable as true } //Finishes the if condition if (GM_getValue("CurrenciesConverter") !== true && GM_getValue("CurrenciesConverter") !== false) { //If the value doesn't exist define as true GM_setValue("CurrenciesConverter", true); //Defines the variable as true } //Finishes the if condition if (GM_getValue("UnitsConverter") !== true && GM_getValue("UnitsConverter") !== false) { //If the value doesn't exist define as true GM_setValue("UnitsConverter", true); //Defines the variable as true } //Finishes the if condition function SearchHiLight() //Function to enable or disable the SearchHiLight and the Currency/Unit converters { //Starts the function SearchHiLight if (GM_getValue("SearchHiLight") === true) { //If the last config was true, set as false GM_setValue("SearchHiLight", false); //Defines the variable as false GM_setValue("CurrenciesConverter", false); //Defines the variable as false GM_setValue("UnitsConverter", false); //Defines the variable as false } //Finishes the if condition else { //If the last config was false, set as true GM_setValue("SearchHiLight", true); //Defines the variable as true if (confirm('If you want to enable the Currency Converter press OK.')) //Show the confimation alert box text { //Starts the if condition GM_setValue("CurrenciesConverter", true); //Defines the variable as true } //Finishes the if condition else //If the user pressed cancel { //Starts the else condition GM_setValue("CurrenciesConverter", false); //Defines the variable as false } //Finishes the else condition if (confirm('If you want to enable the Units Converter press OK.')) //Show the confimation alert box text { //Starts the if condition GM_setValue("UnitsConverter", true); //Defines the variable as true } //Finishes the if condition else //If the user pressed cancel { //Starts the else condition GM_setValue("UnitsConverter", false); //Defines the variable as false } //Finishes the else condition location.reload(); //Reloads the page } //Finishes the else condition } //Finishes the function SearchHiLight if (GM_getValue("SearchHiLight") === true) //If the SearchHiLight is enabled { //Starts the if condition var $ = window.jQuery; //Defines That The Symbol $ Is A jQuery var SelectedTextIsLink; //Creates a new global variable var Links = new RegExp(/\.org|\.ly|\.net|\.co|\.tv|\.me|\.biz|\.club|\.site|\.br|\.gov|\.io|\.jp|\.edu|\.au|\.in|\.it|\.ca|\.mx|\.fr|\.tw|\.il|\.uk/i); //Creates a global variable to check if a link is matched var FinalCurrency, SelectedText = ''; //Make these variables global $(function() { //Starts the function var menu = $("#highlight_menu", $("#highlight_menu_div")[0].shadowRoot); //Creates a variable to hold the menu element $(document.body).on('mouseup', function() { //When the user releases the mouse click after selecting something if (window.getSelection().toString() !== '') //If the actual selection is not null { //Starts the if condition SelectedText = window.getSelection().toString(); //Creates a variable to store the selected text } //Finishes the if condition if (GM_getValue("CurrenciesConverter") === true) { //If the Currencies Converter option is activated document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = ''; //Remove the previous Currency text var Currencies = new RegExp(/^[ \t\xA0]*(?=.*?(\d+(?:.\d+)?))(?=(?:\1[ \t\xA0]*)?(Dólares|dolares|dólares|dollars|AUD|BGN|BRL|BCH|BTC|BYN|CAD|CHF|CNY|CZK|DKK|EUR|EGP|ETH|GBP|GEL|HKD|HRK|HUF|IDR|ILS|INR|JPY|LTC|KRW|MXN|MYR|NOK|NZD|PHP|PLN|RON|RM|RUB|SEK|SGD|THB|TRY|USD|UAH|ZAR|KZT|YTL|\$|R\$|HK\$|US\$|\$US|¥|€|Rp|kn|Kč|kr|zł|£|฿|₩))(?:\1[ \t\xA0]*\2|\2[ \t\xA0]*\1)[ \t\xA0]*$/); //Adds an regex expression to the Currencies variable if (SelectedText.match(Currencies) !== null) //If the selected text is a currency { //Starts the if condition if (GM_getValue("YourLocalCurrency") === undefined) { //If the value is undefined var UserInput = prompt('This is the first time that you selected a currency.\nThis is the first and last time this popup will appear, so please write your local currency so that the script will always use your local currency to make exchange rate conversions.\n*Example of what you should write: BRL\nCAD\nUSD\netc...\n*Press OK'); //Gets the user input GM_setValue("YourLocalCurrency", UserInput); //Defines the variable as the UserInput } //Finishes the if condition (async () => { //Creates a function to get the final value var CurrencySymbol = SelectedText.match(Currencies)[2]; //Get the actual currency symbol supposing "it's correct" var CurrencySymbols = new RegExp(/\$|R\$|HK\$|US\$|\$US|¥|€|Rp|kn|Kč|kr|zł|£|฿|₩/i); //Create a variable to check for the selected currency symbols if (SelectedText.match(Currencies)[2].match(CurrencySymbols) !== null) //If the selected currency contains a symbol { //Starts the if condition switch (SelectedText.match(CurrencySymbols)[0].toLowerCase()) { //If the selected currency constains a symbol case '$': //Get the actual selected currency symbol case 'us$': //Get the actual selected currency symbol case '$us': //Get the actual selected currency symbol CurrencySymbol = 'USD'; //"Convert" the symbol to the Currency Letters break; //Stop trying to get the correct Currency Letters case 'r$': //Get the actual selected currency symbol CurrencySymbol = 'BRL'; //"Convert" the symbol to the Currency Letters break; //Stop trying to get the correct Currency Letters case 'hk$': //Get the actual selected currency symbol CurrencySymbol = 'HKD'; //"Convert" the symbol to the Currency Letters break; //Stop trying to get the correct Currency Letters case "¥": //Get the actual selected currency symbol CurrencySymbol = 'JPY'; //"Convert" the symbol to the Currency Letters break; //Stop trying to get the correct Currency Letters case '€': //Get the actual selected currency symbol CurrencySymbol = 'EUR'; //"Convert" the symbol to the Currency Letters break; //Stop trying to get the correct Currency Letters case 'rp': //Get the actual selected currency symbol CurrencySymbol = 'IDR'; //"Convert" the symbol to the Currency Letters break; //Stop trying to get the correct Currency Letters case 'kn': //Get the actual selected currency symbol CurrencySymbol = 'HRK'; //"Convert" the symbol to the Currency Letters break; //Stop trying to get the correct Currency Letters case 'kč': //Get the actual selected currency symbol CurrencySymbol = 'CZK'; //"Convert" the symbol to the Currency Letters break; //Stop trying to get the correct Currency Letters case 'kr': //Get the actual selected currency symbol CurrencySymbol = 'DKK'; //"Convert" the symbol to the Currency Letters break; //Stop trying to get the correct Currency Letters case 'zł': //Get the actual selected currency symbol CurrencySymbol = 'PLN'; //"Convert" the symbol to the Currency Letters break; //Stop trying to get the correct Currency Letters case '£': //Get the actual selected currency symbol CurrencySymbol = 'GBP'; //"Convert" the symbol to the Currency Letters break; //Stop trying to get the correct Currency Letters case '฿': //Get the actual selected currency symbol CurrencySymbol = 'THB'; //"Convert" the symbol to the Currency Letters break; //Stop trying to get the correct Currency Letters case '₩': //Get the actual selected currency symbol CurrencySymbol = 'KRW'; //"Convert" the symbol to the Currency Letters break; //Stop trying to get the correct Currency Letters } //Finishes the switch condition } //Finishes the if condition const responsehtml = await (await fetch(`https://api.allorigins.win/raw?url=${encodeURIComponent('https://www.google.com/search?q=' + SelectedText.match(Currencies)[1] + ' ' + CurrencySymbol + ' in ' + GM_getValue("YourLocalCurrency"))}`)).text(); //Fetch const newDocument = new DOMParser().parseFromString(responsehtml, 'text/html'); //Parses the fetch response FinalCurrency = parseFloat(newDocument.querySelector("div.BNeawe.iBp4i.AP7Wnd").innerText.split(' ')[0].replaceAll(',', '')); //Gets the final amount of money if (SelectedText.match(Currencies)[2].match(CurrencySymbols) !== null) //If the selected currency contains a symbol { //Starts the if condition document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = CurrencySymbol + ' 🠂 ' + Intl.NumberFormat(navigator.language, { style: 'currency', currency: GM_getValue("YourLocalCurrency") }).format(FinalCurrency) + ' | '; //Show the FinalCurrency on the menu } //Finishes the if condition else //If the selected currency contains no symbol { //Starts the else condition document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = Intl.NumberFormat(navigator.language, { style: 'currency', currency: GM_getValue("YourLocalCurrency") }).format(FinalCurrency) + ' | '; //Show the FinalCurrency on the menu } //Finishes the else condition var text = document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText; //Save the actual currency text document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").onmousemove = function() { //When the mouse is hovering the currency document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = "Copy | "; //Change the element text to copy }; //Finishes the onmousemove advent listener document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").onmouseout = function() { //When the mouse leaves the button document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = text; //Return the previous text }; //Finishes the onmouseout advent listener document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").onclick = function() { //When the user clicks on the currency document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = "Done | "; //Change the element text to copy navigator.clipboard.writeText(Intl.NumberFormat(navigator.language, { style: 'currency', currency: GM_getValue("YourLocalCurrency") }).format(FinalCurrency)); //Copy the Final Currency }; //Finishes the onclick advent listener })(); //Finishes the async function } //Finishes the if condition } //Finishes the if condition //___________________________________________________________________________________________________________________________________________________________________________ if (GM_getValue("UnitsConverter") === true) { //If the Units Converter option is activated document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = ''; //Remove the previous Units text var Units = new RegExp(/^[ \t\xA0]*(\d+(?:[., ]\d+)?)[ \t\xA0]*(inch|inches|in|cms?|centimeters?|meters?|ft|kg|lbs?|pounds?|kilograms?|ounces?|g|ozs?|fl oz|fl oz (us)|fluid ounces?|kphs?|km\/h|kilometers per hours?|mphs?|meters per hours?|°[CF]|km\/hs?|ml|milliliters?|l|liters?|litres?|gal|gallons?|yards?|yd|Millimeter|millimetre|kilometers?|mi|mm|miles?|km|ft|fl|feets?|mts?|grams?|kilowatts?|kws?|brake horsepower|mechanical horsepower|hps?|bhps?|miles per gallons?|mpgs?|liters per 100 kilometers?|l\/100km|liquid quarts?|lqs?|foot-pounds?|foot pounds?|ft-lbs?|ft lbs?|lb fts?|newton-meters?|newton meters?|nm)[ \t\xA0]*(?:\(\w+\)[ \t\xA0]*)?$/i); //Adds an regex expression to the Units variable if (SelectedText.match(Units) !== null) //If the selected text is an unit { //Starts the if condition var SelectedUnitValue = SelectedText.match(Units)[1].replaceAll(',', '.'); //Get the selected unit value and store the value to a variable switch (SelectedText.match(Units)[2].toLowerCase()) { //Set all letters to Lower Case and convert the selected unit to another unit the same way the Opera Browser does case 'inch': //Get the actual selected unit type case 'inches': //Get the actual selected unit type case 'in': //Get the actual selected unit type var NewUnit = 'cm'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue * 2.54).toFixed(2); //Gets the converted unit result break; //Stop case 'centimeter': //Get the actual selected unit type case 'centimeters': //Get the actual selected unit type case 'cm': //Get the actual selected unit type case 'cms': //Get the actual selected unit type NewUnit = 'in'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue / 2.54).toFixed(2); //Gets the converted unit result break; //Stop case 'mt': //Get the actual selected unit type case 'mts': //Get the actual selected unit type case 'meters': //Get the actual selected unit type case 'meter': //Get the actual selected unit type NewUnit = 'ft'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue * 3.281).toFixed(2); //Gets the converted unit result break; //Stop case 'kg': //Get the actual selected unit type case 'kilograms': //Get the actual selected unit type case 'kilogram': //Get the actual selected unit type NewUnit = 'lb'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue * 2.205).toFixed(2); //Gets the converted unit result break; //Stop case 'pound': //Get the actual selected unit type case 'pounds': //Get the actual selected unit type case 'lb': //Get the actual selected unit type case 'lbs': //Get the actual selected unit type NewUnit = 'kg'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue / 2.205).toFixed(2); //Gets the converted unit result break; //Stop case 'ounce': //Get the actual selected unit type case 'ounces': //Get the actual selected unit type case 'oz': //Get the actual selected unit type case 'ozs': //Get the actual selected unit type NewUnit = 'g'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue * 28.35).toFixed(2); //Gets the converted unit result break; //Stop case 'g': //Get the actual selected unit type case 'gram': //Get the actual selected unit type case 'grams': //Get the actual selected unit type NewUnit = 'oz'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue / 28.35).toFixed(2); //Gets the converted unit result break; //Stop case 'kilometer': //Get the actual selected unit type case 'kilometers': //Get the actual selected unit type NewUnit = 'mi'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue / 1.609).toFixed(2); //Gets the converted unit result break; //Stop case 'kph': //Get the actual selected unit type case 'kphs': //Get the actual selected unit type case 'km/h': //Get the actual selected unit type case 'km/hs': //Get the actual selected unit type case 'kilometers per hour': //Get the actual selected unit type case 'kilometers per hours': //Get the actual selected unit type NewUnit = 'mph'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue / 1.609).toFixed(2); //Gets the converted unit result break; //Stop case 'mph': //Get the actual selected unit type case 'mphs': //Get the actual selected unit type case 'meters per hour': //Get the actual selected unit type case 'meters per hours': //Get the actual selected unit type NewUnit = 'km/h'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue * 1.609).toFixed(2); //Gets the converted unit result break; //Stop case 'mi': //Get the actual selected unit type case 'mile': //Get the actual selected unit type case 'miles': //Get the actual selected unit type NewUnit = 'km'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue * 1.609).toFixed(2); //Gets the converted unit result break; //Stop case '°c': //Get the actual selected unit type NewUnit = '°F'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat((SelectedUnitValue * 9 / 5) + 32).toFixed(2); //Gets the converted unit result break; //Stop case '°f': //Get the actual selected unit type NewUnit = '°C'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat((SelectedUnitValue - 32) * 5 / 9).toFixed(2); //Gets the converted unit result break; //Stop case 'ml': //Get the actual selected unit type case 'milliliter': //Get the actual selected unit type case 'milliliters': //Get the actual selected unit type NewUnit = 'fl oz (US)'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue / 29.574).toFixed(2); //Gets the converted unit result break; //Stop case 'fl oz (US)': //Get the actual selected unit type case 'fl oz': //Get the actual selected unit type case 'fl': //Get the actual selected unit type case 'fluid ounce': //Get the actual selected unit type case 'fluid ounces': //Get the actual selected unit type NewUnit = 'ml'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue * 29.574).toFixed(2); //Gets the converted unit result break; //Stop case 'l': //Get the actual selected unit type case 'litre': //Get the actual selected unit type case 'liter': //Get the actual selected unit type case 'litres': //Get the actual selected unit type case 'liters': //Get the actual selected unit type NewUnit = 'gal (US)'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue / 3.785).toFixed(2); //Gets the converted unit result break; //Stop case 'gal': //Get the actual selected unit type case 'gallon': //Get the actual selected unit type case 'gallons': //Get the actual selected unit type NewUnit = 'lt'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue * 3.785).toFixed(2); //Gets the converted unit result break; //Stop case 'yard': //Get the actual selected unit type case 'yards': //Get the actual selected unit type case 'yd': //Get the actual selected unit type NewUnit = 'm'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue / 1.094).toFixed(2); //Gets the converted unit result break; //Stop case 'mm': //Get the actual selected unit type case 'millimetre': //Get the actual selected unit type case 'Millimeters': //Get the actual selected unit type NewUnit = 'in'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue / 25.4).toFixed(2); //Gets the converted unit result break; //Stop case 'ft': //Get the actual selected unit type case 'feet': //Get the actual selected unit type case 'feets': //Get the actual selected unit type NewUnit = 'mt'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue * 0.3048).toFixed(2); //Gets the converted unit result break; //Stop case 'kw': //Get the actual selected unit type case 'kws': //Get the actual selected unit type case 'kilowatt': //Get the actual selected unit type case 'kilowatts': //Get the actual selected unit type NewUnit = 'mhp'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue * 1.341).toFixed(2); //Gets the converted unit result break; //Stop case 'mhp': //Get the actual selected unit type case 'mhps': //Get the actual selected unit type case 'hp': //Get the actual selected unit type case 'hps': //Get the actual selected unit type case 'brake horsepower': //Get the actual selected unit type case 'mechanical horsepower': //Get the actual selected unit type NewUnit = 'kw'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue / 1.341).toFixed(2); //Gets the converted unit result break; //Stop case 'mpg': //Get the actual selected unit type case 'mpgs': //Get the actual selected unit type case 'miles per gallon': //Get the actual selected unit type case 'miles per gallons': //Get the actual selected unit type NewUnit = 'l/100km'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(235.215 / SelectedUnitValue).toFixed(2); //Gets the converted unit result break; //Stop case 'l/100km': //Get the actual selected unit type case 'liters per 100 kilometer': //Get the actual selected unit type case 'liters per 100 kilometers': //Get the actual selected unit type NewUnit = 'US mpg'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(235.215 / SelectedUnitValue).toFixed(2); //Gets the converted unit result break; //Stop case 'lq': //Get the actual selected unit type case 'lqs': //Get the actual selected unit type case 'liquid quart': //Get the actual selected unit type case 'liquid quarts': //Get the actual selected unit type NewUnit = 'l'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue / 1.057).toFixed(2); //Gets the converted unit result break; //Stop case 'liter': //Get the actual selected unit type case 'liters': //Get the actual selected unit type NewUnit = 'lqs'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue * 1.057).toFixed(2); //Gets the converted unit result break; //Stop case 'foot-pound': //Get the actual selected unit type case 'foot-pounds': //Get the actual selected unit type case 'foot pound': //Get the actual selected unit type case 'foot pounds': //Get the actual selected unit type case 'ft-lbs': //Get the actual selected unit type case 'ft-lb': //Get the actual selected unit type case 'ft lbs': //Get the actual selected unit type case 'ft lb': //Get the actual selected unit type case 'lb ft': //Get the actual selected unit type case 'lb fts': //Get the actual selected unit type NewUnit = 'Nm'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue * 1.3558179483).toFixed(2); //Gets the converted unit result break; //Stop case 'newton-meter': //Get the actual selected unit type case 'newton-meters': //Get the actual selected unit type case 'newton meter': //Get the actual selected unit type case 'newton meters': //Get the actual selected unit type case 'nm': //Get the actual selected unit type NewUnit = 'ft lb'; //"Convert" the current unit to another unit ConvertedUnit = parseFloat(SelectedUnitValue / 1.3558179483).toFixed(2); //Gets the converted unit result break; //Stop } //Finishes the switch condition setTimeout(function() { //Starts the settimeout function document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = ConvertedUnit + ' ' + NewUnit + ' | '; //Display the converted unit results var text = document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText; //Save the actual converted unit value document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").onmousemove = function() { //When the mouse is hovering the converted unit value document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = "Copy | "; //Change the element text to copy }; //Finishes the onmousemove advent listener document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").onmouseout = function() { //When the mouse leaves the button document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = text; //Return the previous text }; //Finishes the onmouseout advent listener document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").onclick = function() { //When the user clicks on the converted unit value document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = "Done | "; //Change the element text to copy navigator.clipboard.writeText(ConvertedUnit); //Copy the Final converted unit value }; //Finishes the onclick advent listener }, 0); //Finishes the settimeout } //Finishes the if condition } //Finishes the if condition //___________________________________________________________________________________________________________________________________________________________________________ if (document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#SearchBTN").innerText === 'Open') //If the Search butotn text is 'Open' { //Starts the if condition document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#highlight_menu > ul").style.paddingLeft = '7px'; //Change the ul menu element padding left css style document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#SearchBTN").innerText = 'Search'; //The next time that the menu is shown display the button text as Search again SelectedTextIsLink = false; //Add the value false to the variable to make common words searchable again } //Finishes the if condition if (SelectedText.match(Links) !== null) //If the selected text is a link { //Starts the if condition SelectedTextIsLink = true; //Add the value true to the variable document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#highlight_menu > ul").style.paddingLeft = '15px'; //Change the ul menu element padding left css style document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#SearchBTN").innerText = 'Open'; //Change the button text to Done } //Finishes the if condition //___________________________________________________________________________________________________________________________________________________________________________ if (document.getSelection().toString().trim() !== '') { //If the user selected something var p = document.getSelection().getRangeAt(0).getBoundingClientRect(); //Create a new variable to get the positions later menu.css({ //Set the menu css left: (p.left + (p.width / 2)) - (menu.width() / 2), //Make the menu show on the correct left position top: (p.top - menu.height() - 10), //Make the menu show on the correct top position display: '' //Show the menu on the page }).animate({ //Creates the animation opacity: 1 //Set the animation opacity }, 0); //Add an animation to the menu menu.addClass('highlight_menu_animate'); //Add the class to animate the menu //$('head').append(''); //Create a class to animate the menu return; //Keep displaying the menu box } //Finishes the if condition menu.animate({ //Creates the animation opacity: 0 //Set the animation opacity }); //Hide the menu If the user clicked on any of the options setTimeout(function() { //Hide the menu after some time menu.css({ //Set the menu css display: 'none' //Hide the menu on the page }); //Hide the menu If the user clicked on any of the options }, 300); //Finishes the setTimeout function }); //Finishes the mouseup advent listener }); //Finishes the function //___________________________________________________________________________________________________________________________________________________________________________ var HtmlMenu = document.createElement('div'); //Creates a variable HtmlMenu.setAttribute("id", "highlight_menu_div"); //Set the div id to the HtmlMenu variable HtmlMenu.attachShadow({ mode: 'open' }).innerHTML = '
'; //Set the HtmlMenu div html document.body.appendChild(HtmlMenu); //Append the HtmlMenu div to the page document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#SearchBTN").onmousedown = function() { //When the user clicks on the Search button var LinkfyOrSearch = 'https://www.google.com/search?q='; //Creates a variable to open google if (SelectedTextIsLink === true) //If the selected text is a link { //Starts the if condition LinkfyOrSearch = 'https://'; //Make the non http and non https links able to be opened } //Finishes the if condition if (SelectedText.match(/http:|https:/) !== null) //If the selected text is a link that already has http or https { //Starts the if condition LinkfyOrSearch = ''; //Remove the https:// that was previsouly added to this variable } //Finishes the if condition window.open(LinkfyOrSearch + SelectedText); //Open google and search for the selected word(s) window.getSelection().removeAllRanges(); //UnSelect the selected text after the search button is clicked so that if the user clicks on the past selected text the menu won't show up again. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#highlight_menu").style.display = 'none'; //Hide the menu }; //Finishes the onmousedown advent listener document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#CopyBTN").onmousedown = function() { //When the user clicks on the copy button navigator.clipboard.writeText(SelectedText); //Copy the selected word(s) document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#CopyBTN").innerText = ' | Done'; //Change the button text to Done setTimeout(function() { //Starts the setTimeout function document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#CopyBTN").innerText = ' | Copy'; //The next time that the menu is shown display the button text as Copy again, instead of Done }, 400); //Finishes the setTimeout function }; //Finishes the onmousedown advent listener //___________________________________________________________________________________________________________________________________________________________________________ setTimeout(function() { //Starts the setTimeout function var AllIframes = document.querySelectorAll("iframe"); //Get all iframes on the page for (var i = AllIframes.length; i--;) { //Starts the for condition if (AllIframes[i].allow.match('clipboard-write;') === null && AllIframes[i].src.match(Links) !== null && AllIframes[i].src.match(/youtube|dailymotion|vimeo|streamtape.com|mcloud2.to|vidstream.pro|mp4upload.com/) === null) //If the iframe doesn't have the clipboard-write attribute yet and the iframed source attribute has a link. And if the iframe isn't an YT/dailymotion or vimeo video. { //Starts the if condition AllIframes[i].allow = AllIframes[i].allow + 'clipboard-write;'; //Add he permission to copy the iframe text AllIframes[i].src = AllIframes[i].src; //Reload the iframe to make the iframe have the new permission } //Finishes the if condition } //Finishes the for condition }, 3000); //Finishes the setTimeout function window.onscroll = async function() { //When the page is scrolled document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#highlight_menu").style.display = 'none'; //Hide the menu if (LeftClicked === false && SelectedText !== '') { //If the Left Click isn't being holded, and if something is currently selected window.getSelection().removeAllRanges(); //UnSelect the selected text when scrolling the page down so that if the user clicks on the past selected text the menu won't show up again. } //Finishes the if condition }; //Finishes the onscroll advent listener } //Finishes the if condition