Opera Browser Rocker+Mouse Gestures + Search HighLight

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.

当前为 2022-05-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Opera Browser Rocker+Mouse Gestures + Search HighLight
  3. // @namespace OperaBrowserGestures
  4. // @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.
  5. // @version 52
  6. // @author hacker09
  7. // @include *
  8. // @icon https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://www.opera.com/&size=64
  9. // @require https://code.jquery.com/jquery-3.5.1.min.js
  10. // @grant GM_registerMenuCommand
  11. // @grant GM_openInTab
  12. // @grant window.close
  13. // @grant GM_setValue
  14. // @grant GM_getValue
  15. // @grant GM_deleteValue
  16. // @run-at document-end
  17. // ==/UserScript==
  18.  
  19. // *** Mouse Gesture Settings Below *****************************************************************************************************************************************
  20. GM_registerMenuCommand("Enable/Disable Mouse Gestures", MouseGestures); //Adds an option to the tampermonkey menu
  21. if (GM_getValue("MouseGestures") !== true && GM_getValue("MouseGestures") !== false) { //If the value doesn't exist define as true
  22. GM_setValue("MouseGestures", true); //Defines the variable as true
  23. } //Finishes the if condition
  24.  
  25. function MouseGestures() //Function to enable or disable the MouseGestures
  26. { //Starts the function MouseGestures
  27. if (GM_getValue("MouseGestures") === true) { //If the last config was true, set as false
  28. GM_setValue("MouseGestures", false); //Defines the variable as false
  29. } //Finishes the if condition
  30. else { //If the last config was false, set as true
  31. GM_setValue("MouseGestures", true); //Defines the variable as true
  32. location.reload(); //Reloads the page
  33. } //Finishes the else condition
  34. } //Finishes the function MouseGestures
  35.  
  36. if (GM_getValue("MouseGestures") === true) //If the MouseGestures is enabled
  37. { //Starts the if condition
  38. const SENSITIVITY = 3; // Adjust the script mouse senvity here between 1 ~ 5
  39. const TOLERANCE = 3; // Adjust the script mouse tolerance here between 1 ~ 5
  40.  
  41. const funcs = { //Variable to store the functions
  42.  
  43. 'L': function() { //Function that will run when the mouse movement Left is performed
  44. window.history.back(); //Go Back
  45. }, //Finishes the mouse movement Left
  46.  
  47. 'R': function() { //Function that will run when the mouse movement Right is performed
  48. window.history.forward(); //Go Forward
  49. }, //Finishes the mouse movement Right
  50.  
  51. 'D': function() { //Function that will run when the mouse movement Down is performed
  52. if (IsShiftNotPressed === true) { //If the shift key isn't being pressed
  53. GM_openInTab(link, { //Open the link on a new tab
  54. active: true, //Focus on the new tab
  55. insert: true, //Insert the new tab after the actual tab
  56. setParent: true //Return to the tab the user was in
  57. }); //Open the link that was hovered
  58. } //Finishes the if condition
  59. }, //Finishes the mouse movement Down
  60.  
  61. 'UD': function() { //Function that will run when the mouse movement Up+Down is performed
  62. window.location.reload(); //Reload the Tab
  63. }, //Finishes the mouse movement Up+Down
  64.  
  65. 'DR': function(e) { //Function that will run when the mouse movement Down+Right is performed
  66. window.top.close(); //Close the tab
  67. e.preventDefault(); //Prevent the default context menu from being opened
  68. e.stopPropagation(); //Prevent the default context menu from being opened
  69. }, //Finishes the mouse movement Down+Right
  70.  
  71. 'DU': function() { //Function that will run when the mouse movement Down+Up is performed
  72. GM_openInTab(link, { //Open the link that was hovered
  73. active: false, //Don't focus on the new tab
  74. insert: true, //Insert the new tab after the actual tab
  75. setParent: true //Return to the tab the user was in
  76. }); //Open the link that was hovered on a new background tab
  77. } //Finishes the mouse movement Down+Up
  78.  
  79. }; //Finishes the variable to store the functions
  80.  
  81. // *** Below this line is the math codes that track the mouse movement gestures *******************************************************************************************
  82. const s = 1 << ((7 - SENSITIVITY) << 1);
  83. const t1 = Math.tan(0.15708 * TOLERANCE),
  84. t2 = 1 / t1;
  85.  
  86. let x, y, path;
  87.  
  88. const tracer = function(e) { //Starts the const tracer
  89. let cx = e.clientX,
  90. cy = e.clientY,
  91. deltaX = cx - x,
  92. deltaY = cy - y,
  93. distance = deltaX * deltaX + deltaY * deltaY;
  94. if (distance > s) {
  95. let slope = Math.abs(deltaY / deltaX),
  96. direction = '';
  97. if (slope > t1) {
  98. direction = deltaY > 0 ? 'D' : 'U';
  99. } else if (slope <= t2) {
  100. direction = deltaX > 0 ? 'R' : 'L';
  101. }
  102. if (path.charAt(path.length - 1) !== direction) {
  103. path += direction;
  104. }
  105. x = cx;
  106. y = cy;
  107. }
  108. }; //Finishes the const tracer
  109.  
  110. window.addEventListener('mousedown', function(e) { //Add an advent listener to the page to detect when the mouse is clicked
  111. if (e.which === 3) { //Starts the if condition
  112. x = e.clientX;
  113. y = e.clientY;
  114. path = "";
  115. window.addEventListener('mousemove', tracer, false); //Add an advent listener to the page to detect the mouse position
  116. } //Finishes the if condition
  117. }, false); //Finishes the advent listener
  118.  
  119. var IsShiftNotPressed = true; //Variable to hold the shift key status
  120. window.addEventListener("contextmenu", function(e) { //Adds an advent listener to the page to know when the shift key is pressed or not
  121. if (e.shiftKey) { //If the shift key was pressed
  122. IsShiftNotPressed = false; //Variable to hold the shift key status
  123. window.open(link, '_blank', 'height=' + window.screen.height + ',width=' + window.screen.width); //Open the link on a new window
  124. } //Finishes the if condition
  125. if (LeftClicked === true) { //If the Left Click was released when the Rocker Mouse Gestures are activated
  126. e.preventDefault(); //Prevent the default context menu from being opened
  127. e.stopPropagation(); //Prevent the default context menu from being opened
  128. } //Finishes the if condition
  129. setTimeout(function() { //Starts the settimeout function
  130. IsShiftNotPressed = true; //Variable to hold the shift key status
  131. }, 500); //Finishes the settimeout function
  132. }, false); //Finishes the advent listener
  133.  
  134. window.addEventListener('contextmenu', function(e) { //When the right click button is released
  135. window.removeEventListener('mousemove', tracer, false); //Stop tracking the mouse movements
  136. if (path !== "") { //Starts the if condition
  137. e.preventDefault(); //Prevent the default context menu from being opened
  138. if (funcs.hasOwnProperty(path)) { //Starts the if condition
  139. funcs[path]();
  140. } //Finishes the if condition
  141. } //Finishes the if condition
  142. }, false); //Finishes the advent listener
  143.  
  144. var link; //Make the variable global
  145. 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
  146. link = this.href; //Store the actual hovered link to a variable
  147. }); //Finishes the forEach
  148.  
  149. Array.from(document.querySelectorAll('a')).forEach(Element => Element.onmouseout = function() { //Get all the a link elements and add an advent listener to the link element
  150. var PreviousLink = link; //Save the actual hovered link to another variable
  151. setTimeout(function() { //Starts the settimeout function
  152. if (PreviousLink === link) //If he actual hovered link is still the same as the Previously hovered Link
  153. { //Starts the if condition
  154. link = 'about:newtab'; //Make the script open a new browser tab when the mouse leaves any link that was hovered
  155. } //Finishes the if condition
  156. }, 200); //Finishes the settimeout function
  157. }); //Finishes the forEach
  158.  
  159. } //Finishes the if condition
  160.  
  161. // *** Rocker Mouse Gesture Settings Below ***********************************************************************************************************************************
  162. GM_registerMenuCommand("Enable/Disable Rocker Mouse Gestures", RockerMouseGestures); //Adds an option to the tampermonkey menu
  163. if (GM_getValue("RockerMouseGestures") !== true && GM_getValue("RockerMouseGestures") !== false) { //If the value doesn't exist define as false
  164. GM_setValue("RockerMouseGestures", false); //Defines the variable as false
  165. } //Finishes the if condition
  166.  
  167. function RockerMouseGestures() //Function to enable or disable the RockerMouseGestures
  168. { //Starts the function RockerMouseGestures
  169. if (GM_getValue("RockerMouseGestures") === true) { //If the last config was true, set as false
  170. GM_setValue("RockerMouseGestures", false); //Defines the variable as false
  171. } //Finishes the if condition
  172. else { //If the last config was false, set as true
  173. GM_setValue("RockerMouseGestures", true); //Defines the variable as true
  174. location.reload(); //Reloads the page
  175. } //Finishes the else condition
  176. } //Finishes the function RockerMouseGestures
  177.  
  178. if (GM_getValue("RockerMouseGestures") === true || GM_getValue("SearchHiLight") === true) //If the RockerMouseGestures or the SearchHiLight is enabled
  179. { //Starts the if condition
  180. var LeftClicked, RightClicked; //Make these variables global
  181. window.addEventListener("mousedown", function(e) { //Detect the right and left mouse clicks presses on the page
  182. switch (e.button) { //Start the switch condition
  183. case 0: //If Left Click was Pressed
  184. LeftClicked = true; //Set the variable LeftClicked as true
  185. break; //Don't execute the lines below if the Left Key was Pressed
  186. case 2: //If Right Click was Pressed
  187. RightClicked = true; //Set the variable RightClicked as true
  188. break; //Don't execute the lines below if the Right Key was Pressed
  189. } //Finishes the switch condition
  190. }, false); //Finishes the adventlistener mousedown
  191.  
  192. window.addEventListener("mouseup", function(e) { //Detect the right and left mouse clicks releases on the page
  193. switch (e.button) { //Start the switch condition
  194. case 0: //If Left Click was released
  195. LeftClicked = false; //Set the variable LeftClicked as false
  196. break; //Don't execute the lines below if the Left Key was Pressed
  197. case 2: //If Right Click was released
  198. RightClicked = false; //Set the variable RightClicked as false
  199. break; //Don't execute the lines below if the Left Key was Pressed
  200. } //Finishes the switch condition
  201. if (LeftClicked && RightClicked === false) { //If Left was Clicked and then Right Click was released
  202. window.history.back(); //Go Back
  203. } //Finishes the if condition
  204. if (RightClicked && LeftClicked === false) { //If Right was Clicked and then Left Click was released
  205. window.history.forward(); //Go Forward
  206. } //Finishes the if condition
  207. }, false); //Finishes the adventlistener mouseup
  208. } //Finishes the if condition
  209.  
  210. // *** SearchHighLight Below *************************************************************************************************************************************************
  211. GM_registerMenuCommand("Enable/Disable SearchHiLight", SearchHiLight); //Adds an option to the tampermonkey menu
  212. if (GM_getValue("SearchHiLight") !== true && GM_getValue("SearchHiLight") !== false) { //If the value doesn't exist define as true
  213. GM_setValue("SearchHiLight", true); //Defines the variable as true
  214. } //Finishes the if condition
  215.  
  216. if (GM_getValue("CurrenciesConverter") !== true && GM_getValue("CurrenciesConverter") !== false) { //If the value doesn't exist define as true
  217. GM_setValue("CurrenciesConverter", true); //Defines the variable as true
  218. } //Finishes the if condition
  219.  
  220. if (GM_getValue("UnitsConverter") !== true && GM_getValue("UnitsConverter") !== false) { //If the value doesn't exist define as true
  221. GM_setValue("UnitsConverter", true); //Defines the variable as true
  222. } //Finishes the if condition
  223.  
  224. function SearchHiLight() //Function to enable or disable the SearchHiLight and the Currency/Unit converters
  225. { //Starts the function SearchHiLight
  226. if (GM_getValue("SearchHiLight") === true) { //If the last config was true, set as false
  227. GM_setValue("SearchHiLight", false); //Defines the variable as false
  228. GM_setValue("CurrenciesConverter", false); //Defines the variable as false
  229. GM_deleteValue('YourLocalCurrency'); //Remove the YourLocalCurrency variable of the tampermonkey storage
  230. GM_setValue("UnitsConverter", false); //Defines the variable as false
  231. } //Finishes the if condition
  232. else { //If the last config was false, set as true
  233. GM_setValue("SearchHiLight", true); //Defines the variable as true
  234.  
  235. if (confirm('If you want to enable the Currency Converter press OK.')) //Show the confimation alert box text
  236. { //Starts the if condition
  237. GM_setValue("CurrenciesConverter", true); //Defines the variable as true
  238. } //Finishes the if condition
  239. else //If the user pressed cancel
  240. { //Starts the else condition
  241. GM_setValue("CurrenciesConverter", false); //Defines the variable as false
  242. } //Finishes the else condition
  243.  
  244. if (confirm('If you want to enable the Units Converter press OK.')) //Show the confimation alert box text
  245. { //Starts the if condition
  246. GM_setValue("UnitsConverter", true); //Defines the variable as true
  247. } //Finishes the if condition
  248. else //If the user pressed cancel
  249. { //Starts the else condition
  250. GM_setValue("UnitsConverter", false); //Defines the variable as false
  251. } //Finishes the else condition
  252.  
  253. location.reload(); //Reloads the page
  254. } //Finishes the else condition
  255. } //Finishes the function SearchHiLight
  256.  
  257. if (GM_getValue("SearchHiLight") === true) //If the SearchHiLight is enabled
  258. { //Starts the if condition
  259.  
  260. var $ = window.jQuery; //Defines That The Symbol $ Is A jQuery
  261. var SelectedTextIsLink; //Creates a new global variable
  262. 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|\.zoom\.us|\youtu.be/i); //Creates a global variable to check if a link is matched
  263. var FinalCurrency, SelectedText, SelectedTextSearch = ''; //Make these variables global
  264.  
  265. $(function() { //Starts the function
  266. var menu = $("#highlight_menu", $("#highlight_menu_div")[0].shadowRoot); //Creates a variable to hold the menu element
  267. $(document.body).on('mouseup', function() { //When the user releases the mouse click after selecting something
  268. SelectedText = window.getSelection().toString(); //Creates a variable to store the selected text
  269. SelectedTextSearch = window.getSelection().toString().replaceAll('&', '%26'); //Creates a variable to store the selected text to be opened on google
  270.  
  271. if (GM_getValue("CurrenciesConverter") === true) { //If the Currencies Converter option is activated
  272. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = ''; //Remove the previous Currency text
  273. 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]*$/i); //Adds an regex expression to the Currencies variable
  274.  
  275. if (SelectedText.match(Currencies) !== null) //If the selected text is a currency
  276. { //Starts the if condition
  277.  
  278. if (GM_getValue("YourLocalCurrency") === undefined) { //If the value is undefined
  279. 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
  280. GM_setValue("YourLocalCurrency", UserInput); //Defines the variable as the UserInput
  281. } //Finishes the if condition
  282.  
  283. (async () => { //Creates a function to get the final value
  284. var CurrencySymbol = SelectedText.match(Currencies)[2]; //Get the actual currency symbol supposing "it's correct"
  285. var CurrencySymbols = new RegExp(/\$|R\$|HK\$|US\$|\$US|¥|€|Rp|kn|Kč|kr|zł|£|฿|₩/i); //Create a variable to check for the selected currency symbols
  286. if (SelectedText.match(Currencies)[2].match(CurrencySymbols) !== null) //If the selected currency contains a symbol
  287. { //Starts the if condition
  288.  
  289. switch (SelectedText.match(CurrencySymbols)[0].toLowerCase()) { //If the selected currency constains a symbol
  290. case '$': //Get the actual selected currency symbol
  291. case 'us$': //Get the actual selected currency symbol
  292. case '$us': //Get the actual selected currency symbol
  293. CurrencySymbol = 'USD'; //"Convert" the symbol to the Currency Letters
  294. break; //Stop trying to get the correct Currency Letters
  295. case 'r$': //Get the actual selected currency symbol
  296. CurrencySymbol = 'BRL'; //"Convert" the symbol to the Currency Letters
  297. break; //Stop trying to get the correct Currency Letters
  298. case 'hk$': //Get the actual selected currency symbol
  299. CurrencySymbol = 'HKD'; //"Convert" the symbol to the Currency Letters
  300. break; //Stop trying to get the correct Currency Letters
  301. case "¥": //Get the actual selected currency symbol
  302. CurrencySymbol = 'JPY'; //"Convert" the symbol to the Currency Letters
  303. break; //Stop trying to get the correct Currency Letters
  304. case '€': //Get the actual selected currency symbol
  305. CurrencySymbol = 'EUR'; //"Convert" the symbol to the Currency Letters
  306. break; //Stop trying to get the correct Currency Letters
  307. case 'rp': //Get the actual selected currency symbol
  308. CurrencySymbol = 'IDR'; //"Convert" the symbol to the Currency Letters
  309. break; //Stop trying to get the correct Currency Letters
  310. case 'kn': //Get the actual selected currency symbol
  311. CurrencySymbol = 'HRK'; //"Convert" the symbol to the Currency Letters
  312. break; //Stop trying to get the correct Currency Letters
  313. case 'kč': //Get the actual selected currency symbol
  314. CurrencySymbol = 'CZK'; //"Convert" the symbol to the Currency Letters
  315. break; //Stop trying to get the correct Currency Letters
  316. case 'kr': //Get the actual selected currency symbol
  317. CurrencySymbol = 'DKK'; //"Convert" the symbol to the Currency Letters
  318. break; //Stop trying to get the correct Currency Letters
  319. case 'zł': //Get the actual selected currency symbol
  320. CurrencySymbol = 'PLN'; //"Convert" the symbol to the Currency Letters
  321. break; //Stop trying to get the correct Currency Letters
  322. case '£': //Get the actual selected currency symbol
  323. CurrencySymbol = 'GBP'; //"Convert" the symbol to the Currency Letters
  324. break; //Stop trying to get the correct Currency Letters
  325. case '฿': //Get the actual selected currency symbol
  326. CurrencySymbol = 'THB'; //"Convert" the symbol to the Currency Letters
  327. break; //Stop trying to get the correct Currency Letters
  328. case '₩': //Get the actual selected currency symbol
  329. CurrencySymbol = 'KRW'; //"Convert" the symbol to the Currency Letters
  330. break; //Stop trying to get the correct Currency Letters
  331. } //Finishes the switch condition
  332. } //Finishes the if condition
  333.  
  334. const responsehtml = await (await fetch(`https://api.allorigins.win/get?url=${encodeURIComponent('https://www.google.com/search?q=' + SelectedText.match(Currencies)[1] + ' ' + CurrencySymbol + ' in ' + GM_getValue("YourLocalCurrency"))}`)).json(); //Fetch
  335. const newDocument = new DOMParser().parseFromString(responsehtml.contents, 'text/html'); //Parses the fetch response
  336. FinalCurrency = parseFloat(newDocument.querySelector("div.BNeawe.iBp4i.AP7Wnd").innerText.split(' ')[0].replaceAll(',', '')); //Gets the final amount of money
  337.  
  338. if (SelectedText.match(Currencies)[2].match(CurrencySymbols) !== null) //If the selected currency contains a symbol
  339. { //Starts the if condition
  340.  
  341. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = CurrencySymbol + ' 🠂 ' + Intl.NumberFormat(navigator.language, {
  342. style: 'currency',
  343. currency: GM_getValue("YourLocalCurrency")
  344. }).format(FinalCurrency) + ' | '; //Show the FinalCurrency on the menu
  345. } //Finishes the if condition
  346. else //If the selected currency contains no symbol
  347. { //Starts the else condition
  348. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = Intl.NumberFormat(navigator.language, {
  349. style: 'currency',
  350. currency: GM_getValue("YourLocalCurrency")
  351. }).format(FinalCurrency) + ' | '; //Show the FinalCurrency on the menu
  352. } //Finishes the else condition
  353.  
  354. var text = document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText; //Save the actual currency text
  355.  
  356. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").onmousemove = function() { //When the mouse is hovering the currency
  357. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = "Copy | "; //Change the element text to copy
  358. }; //Finishes the onmousemove advent listener
  359.  
  360. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").onmouseout = function() { //When the mouse leaves the button
  361. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = text; //Return the previous text
  362. }; //Finishes the onmouseout advent listener
  363.  
  364. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").onclick = function() { //When the user clicks on the currency
  365. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = "Done | "; //Change the element text to copy
  366. navigator.clipboard.writeText(Intl.NumberFormat(navigator.language, {
  367. style: 'currency',
  368. currency: GM_getValue("YourLocalCurrency")
  369. }).format(FinalCurrency)); //Copy the Final Currency
  370. }; //Finishes the onclick advent listener
  371.  
  372. })(); //Finishes the async function
  373. } //Finishes the if condition
  374. } //Finishes the if condition
  375. //___________________________________________________________________________________________________________________________________________________________________________
  376.  
  377. if (GM_getValue("UnitsConverter") === true) { //If the Units Converter option is activated
  378. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = ''; //Remove the previous Units text
  379. 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?|ft-?lbs?|lb fts?|newton-?meters?|nm|\^\d+)[ \t\xA0]*(?:\(\w+\)[ \t\xA0]*)?$/i); //Adds an regex expression to the Units variable
  380.  
  381. if (SelectedText.match(Units) !== null) //If the selected text is an unit
  382. { //Starts the if condition
  383.  
  384. var SelectedUnitValue = SelectedText.match(Units)[1].replaceAll(',', '.'); //Get the selected unit value and store the value to a variable
  385.  
  386. 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
  387. case 'inch': //Get the actual selected unit type
  388. case 'inches': //Get the actual selected unit type
  389. case 'in': //Get the actual selected unit type
  390. case '"': //Get the actual selected unit type
  391. var NewUnit = 'cm'; //"Convert" the current unit to another unit
  392. var ConvertedUnit = parseFloat(SelectedUnitValue * 2.54).toFixed(2); //Gets the converted unit result
  393. break; //Stop
  394. case 'centimeter': //Get the actual selected unit type
  395. case 'centimeters': //Get the actual selected unit type
  396. case 'cm': //Get the actual selected unit type
  397. case 'cms': //Get the actual selected unit type
  398. NewUnit = 'in'; //"Convert" the current unit to another unit
  399. ConvertedUnit = parseFloat(SelectedUnitValue / 2.54).toFixed(2); //Gets the converted unit result
  400. break; //Stop
  401. case 'mt': //Get the actual selected unit type
  402. case 'mts': //Get the actual selected unit type
  403. case 'meters': //Get the actual selected unit type
  404. case 'meter': //Get the actual selected unit type
  405. NewUnit = 'ft'; //"Convert" the current unit to another unit
  406. ConvertedUnit = parseFloat(SelectedUnitValue * 3.281).toFixed(2); //Gets the converted unit result
  407. break; //Stop
  408. case 'kg': //Get the actual selected unit type
  409. case 'kilograms': //Get the actual selected unit type
  410. case 'kilogram': //Get the actual selected unit type
  411. NewUnit = 'lb'; //"Convert" the current unit to another unit
  412. ConvertedUnit = parseFloat(SelectedUnitValue * 2.205).toFixed(2); //Gets the converted unit result
  413. break; //Stop
  414. case 'pound': //Get the actual selected unit type
  415. case 'pounds': //Get the actual selected unit type
  416. case 'lb': //Get the actual selected unit type
  417. case 'lbs': //Get the actual selected unit type
  418. NewUnit = 'kg'; //"Convert" the current unit to another unit
  419. ConvertedUnit = parseFloat(SelectedUnitValue / 2.205).toFixed(2); //Gets the converted unit result
  420. break; //Stop
  421. case 'ounce': //Get the actual selected unit type
  422. case 'ounces': //Get the actual selected unit type
  423. case 'oz': //Get the actual selected unit type
  424. case 'ozs': //Get the actual selected unit type
  425. NewUnit = 'g'; //"Convert" the current unit to another unit
  426. ConvertedUnit = parseFloat(SelectedUnitValue * 28.35).toFixed(2); //Gets the converted unit result
  427. break; //Stop
  428. case 'g': //Get the actual selected unit type
  429. case 'gram': //Get the actual selected unit type
  430. case 'grams': //Get the actual selected unit type
  431. NewUnit = 'oz'; //"Convert" the current unit to another unit
  432. ConvertedUnit = parseFloat(SelectedUnitValue / 28.35).toFixed(2); //Gets the converted unit result
  433. break; //Stop
  434. case 'kilometer': //Get the actual selected unit type
  435. case 'kilometers': //Get the actual selected unit type
  436. NewUnit = 'mi'; //"Convert" the current unit to another unit
  437. ConvertedUnit = parseFloat(SelectedUnitValue / 1.609).toFixed(2); //Gets the converted unit result
  438. break; //Stop
  439. case 'kph': //Get the actual selected unit type
  440. case 'kphs': //Get the actual selected unit type
  441. case 'km/h': //Get the actual selected unit type
  442. case 'km/hs': //Get the actual selected unit type
  443. case 'kilometers per hour': //Get the actual selected unit type
  444. case 'kilometers per hours': //Get the actual selected unit type
  445. NewUnit = 'mph'; //"Convert" the current unit to another unit
  446. ConvertedUnit = parseFloat(SelectedUnitValue * 1000).toFixed(2); //Gets the converted unit result
  447. break; //Stop
  448. case 'mph': //Get the actual selected unit type
  449. case 'mphs': //Get the actual selected unit type
  450. case 'meters per hour': //Get the actual selected unit type
  451. case 'meters per hours': //Get the actual selected unit type
  452. NewUnit = 'km/h'; //"Convert" the current unit to another unit
  453. ConvertedUnit = parseFloat(SelectedUnitValue / 1.000).toFixed(2); //Gets the converted unit result
  454. break; //Stop
  455. case 'mi': //Get the actual selected unit type
  456. case 'mile': //Get the actual selected unit type
  457. case 'miles': //Get the actual selected unit type
  458. NewUnit = 'km'; //"Convert" the current unit to another unit
  459. ConvertedUnit = parseFloat(SelectedUnitValue * 1.609).toFixed(2); //Gets the converted unit result
  460. break; //Stop
  461. case '°c': //Get the actual selected unit type
  462. NewUnit = '°F'; //"Convert" the current unit to another unit
  463. ConvertedUnit = parseFloat((SelectedUnitValue * 9 / 5) + 32).toFixed(2); //Gets the converted unit result
  464. break; //Stop
  465. case '°f': //Get the actual selected unit type
  466. NewUnit = '°C'; //"Convert" the current unit to another unit
  467. ConvertedUnit = parseFloat((SelectedUnitValue - 32) * 5 / 9).toFixed(2); //Gets the converted unit result
  468. break; //Stop
  469. case 'ºc': //Get the actual selected unit type
  470. NewUnit = 'ºF'; //"Convert" the current unit to another unit
  471. ConvertedUnit = parseFloat((SelectedUnitValue * 9 / 5) + 32).toFixed(2); //Gets the converted unit result
  472. break; //Stop
  473. case 'ºf': //Get the actual selected unit type
  474. NewUnit = 'ºC'; //"Convert" the current unit to another unit
  475. ConvertedUnit = parseFloat((SelectedUnitValue - 32) * 5 / 9).toFixed(2); //Gets the converted unit result
  476. break; //Stop
  477. case 'ml': //Get the actual selected unit type
  478. case 'milliliter': //Get the actual selected unit type
  479. case 'milliliters': //Get the actual selected unit type
  480. NewUnit = 'fl oz (US)'; //"Convert" the current unit to another unit
  481. ConvertedUnit = parseFloat(SelectedUnitValue / 29.574).toFixed(2); //Gets the converted unit result
  482. break; //Stop
  483. case 'fl oz (US)': //Get the actual selected unit type
  484. case 'fl oz': //Get the actual selected unit type
  485. case 'fl': //Get the actual selected unit type
  486. case 'fluid ounce': //Get the actual selected unit type
  487. case 'fluid ounces': //Get the actual selected unit type
  488. NewUnit = 'ml'; //"Convert" the current unit to another unit
  489. ConvertedUnit = parseFloat(SelectedUnitValue * 29.574).toFixed(2); //Gets the converted unit result
  490. break; //Stop
  491. case 'l': //Get the actual selected unit type
  492. case 'litre': //Get the actual selected unit type
  493. case 'liter': //Get the actual selected unit type
  494. case 'litres': //Get the actual selected unit type
  495. case 'liters': //Get the actual selected unit type
  496. NewUnit = 'gal (US)'; //"Convert" the current unit to another unit
  497. ConvertedUnit = parseFloat(SelectedUnitValue / 3.785).toFixed(2); //Gets the converted unit result
  498. break; //Stop
  499. case 'gal': //Get the actual selected unit type
  500. case 'gallon': //Get the actual selected unit type
  501. case 'gallons': //Get the actual selected unit type
  502. NewUnit = 'lt'; //"Convert" the current unit to another unit
  503. ConvertedUnit = parseFloat(SelectedUnitValue * 3.785).toFixed(2); //Gets the converted unit result
  504. break; //Stop
  505. case 'yard': //Get the actual selected unit type
  506. case 'yards': //Get the actual selected unit type
  507. case 'yd': //Get the actual selected unit type
  508. NewUnit = 'm'; //"Convert" the current unit to another unit
  509. ConvertedUnit = parseFloat(SelectedUnitValue / 1.094).toFixed(2); //Gets the converted unit result
  510. break; //Stop
  511. case 'mm': //Get the actual selected unit type
  512. case 'millimetre': //Get the actual selected unit type
  513. case 'Millimeters': //Get the actual selected unit type
  514. NewUnit = 'in'; //"Convert" the current unit to another unit
  515. ConvertedUnit = parseFloat(SelectedUnitValue / 25.4).toFixed(2); //Gets the converted unit result
  516. break; //Stop
  517. case 'ft': //Get the actual selected unit type
  518. case 'feet': //Get the actual selected unit type
  519. case 'feets': //Get the actual selected unit type
  520. NewUnit = 'mt'; //"Convert" the current unit to another unit
  521. ConvertedUnit = parseFloat(SelectedUnitValue * 0.3048).toFixed(2); //Gets the converted unit result
  522. break; //Stop
  523. case 'kw': //Get the actual selected unit type
  524. case 'kws': //Get the actual selected unit type
  525. case 'kilowatt': //Get the actual selected unit type
  526. case 'kilowatts': //Get the actual selected unit type
  527. NewUnit = 'mhp'; //"Convert" the current unit to another unit
  528. ConvertedUnit = parseFloat(SelectedUnitValue * 1.341).toFixed(2); //Gets the converted unit result
  529. break; //Stop
  530. case 'mhp': //Get the actual selected unit type
  531. case 'mhps': //Get the actual selected unit type
  532. case 'hp': //Get the actual selected unit type
  533. case 'hps': //Get the actual selected unit type
  534. case 'brake horsepower': //Get the actual selected unit type
  535. case 'mechanical horsepower': //Get the actual selected unit type
  536. NewUnit = 'kw'; //"Convert" the current unit to another unit
  537. ConvertedUnit = parseFloat(SelectedUnitValue / 1.341).toFixed(2); //Gets the converted unit result
  538. break; //Stop
  539. case 'mpg': //Get the actual selected unit type
  540. case 'mpgs': //Get the actual selected unit type
  541. case 'miles per gallon': //Get the actual selected unit type
  542. case 'miles per gallons': //Get the actual selected unit type
  543. NewUnit = 'l/100km'; //"Convert" the current unit to another unit
  544. ConvertedUnit = parseFloat(235.215 / SelectedUnitValue).toFixed(2); //Gets the converted unit result
  545. break; //Stop
  546. case 'l/100km': //Get the actual selected unit type
  547. case 'liters per 100 kilometer': //Get the actual selected unit type
  548. case 'liters per 100 kilometers': //Get the actual selected unit type
  549. NewUnit = 'US mpg'; //"Convert" the current unit to another unit
  550. ConvertedUnit = parseFloat(235.215 / SelectedUnitValue).toFixed(2); //Gets the converted unit result
  551. break; //Stop
  552. case 'lq': //Get the actual selected unit type
  553. case 'lqs': //Get the actual selected unit type
  554. case 'liquid quart': //Get the actual selected unit type
  555. case 'liquid quarts': //Get the actual selected unit type
  556. NewUnit = 'l'; //"Convert" the current unit to another unit
  557. ConvertedUnit = parseFloat(SelectedUnitValue / 1.057).toFixed(2); //Gets the converted unit result
  558. break; //Stop
  559. case 'liter': //Get the actual selected unit type
  560. case 'liters': //Get the actual selected unit type
  561. NewUnit = 'lqs'; //"Convert" the current unit to another unit
  562. ConvertedUnit = parseFloat(SelectedUnitValue * 1.057).toFixed(2); //Gets the converted unit result
  563. break; //Stop
  564. case 'foot-pound': //Get the actual selected unit type
  565. case 'foot-pounds': //Get the actual selected unit type
  566. case 'foot pound': //Get the actual selected unit type
  567. case 'foot pounds': //Get the actual selected unit type
  568. case 'ft-lbs': //Get the actual selected unit type
  569. case 'ft-lb': //Get the actual selected unit type
  570. case 'ft lbs': //Get the actual selected unit type
  571. case 'ft lb': //Get the actual selected unit type
  572. case 'lb ft': //Get the actual selected unit type
  573. case 'lb fts': //Get the actual selected unit type
  574. NewUnit = 'Nm'; //"Convert" the current unit to another unit
  575. ConvertedUnit = parseFloat(SelectedUnitValue * 1.3558179483).toFixed(2); //Gets the converted unit result
  576. break; //Stop
  577. case 'newton-meter': //Get the actual selected unit type
  578. case 'newton-meters': //Get the actual selected unit type
  579. case 'newton meter': //Get the actual selected unit type
  580. case 'newton meters': //Get the actual selected unit type
  581. case 'nm': //Get the actual selected unit type
  582. NewUnit = 'ft lb'; //"Convert" the current unit to another unit
  583. ConvertedUnit = parseFloat(SelectedUnitValue / 1.3558179483).toFixed(2); //Gets the converted unit result
  584. break; //Stop
  585. case (SelectedText.match(Units)[2].replaceAll(',', '.').match(/\^/)).input: //Get the actual selected unit type
  586. NewUnit = 'power'; //"Convert" the current unit to another unit
  587. ConvertedUnit = Math.pow(parseFloat(SelectedUnitValue), parseFloat(SelectedText.split('^')[1])); //Gets the converted unit result
  588. break; //Stop
  589. } //Finishes the switch condition
  590.  
  591. setTimeout(function() { //Starts the settimeout function
  592. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = ConvertedUnit + ' ' + NewUnit + ' | '; //Display the converted unit results
  593.  
  594. var text = document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText; //Save the actual converted unit value
  595.  
  596. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").onmousemove = function() { //When the mouse is hovering the converted unit value
  597. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = "Copy | "; //Change the element text to copy
  598. }; //Finishes the onmousemove advent listener
  599.  
  600. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").onmouseout = function() { //When the mouse leaves the button
  601. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = text; //Return the previous text
  602. }; //Finishes the onmouseout advent listener
  603.  
  604. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").onclick = function() { //When the user clicks on the converted unit value
  605. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#ShowCurrencyORUnits").innerText = "Done | "; //Change the element text to copy
  606. navigator.clipboard.writeText(ConvertedUnit); //Copy the Final converted unit value
  607. }; //Finishes the onclick advent listener
  608. }, 0); //Finishes the settimeout
  609. } //Finishes the if condition
  610. } //Finishes the if condition
  611. //___________________________________________________________________________________________________________________________________________________________________________
  612. if (document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#SearchBTN").innerText === 'Open') //If the Search butotn text is 'Open'
  613. { //Starts the if condition
  614. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#highlight_menu > ul").style.paddingLeft = '7px'; //Change the ul menu element padding left css style
  615. 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
  616. SelectedTextIsLink = false; //Add the value false to the variable to make common words searchable again
  617. } //Finishes the if condition
  618.  
  619. if (SelectedText.match(Links) !== null) //If the selected text is a link
  620. { //Starts the if condition
  621. SelectedTextIsLink = true; //Add the value true to the variable
  622. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#highlight_menu > ul").style.paddingLeft = '7px'; //Change the ul menu element padding left css style
  623. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#SearchBTN").innerText = 'Open'; //Change the button text to Open
  624. } //Finishes the if condition
  625. //___________________________________________________________________________________________________________________________________________________________________________
  626. if (document.getSelection().toString().trim() !== '') { //If the user selected something
  627. var p = document.getSelection().getRangeAt(0).getBoundingClientRect(); //Create a new variable to get the positions later
  628. menu.css({ //Set the menu css
  629. left: (p.left + (p.width / 2)) - (menu.width() / 2), //Make the menu show on the correct left position
  630. top: (p.top - menu.height() - 10), //Make the menu show on the correct top position
  631. display: '' //Show the menu on the page
  632. }).animate({ //Creates the animation
  633. opacity: 1 //Set the animation opacity
  634. }, 0); //Add an animation to the menu
  635.  
  636. menu.addClass('highlight_menu_animate'); //Add the class to animate the menu
  637. //$('head').append('<style>.highlight_menu_animate .popuptext::after { content: ""; top: 100%; left: 50%; margin-left: -10px; position: absolute; border-style: solid; border-color: #292929 transparent transparent transparent; }</style>'); //Create a class to animate the menu
  638. return; //Keep displaying the menu box
  639. } //Finishes the if condition
  640. menu.animate({ //Creates the animation
  641. opacity: 0 //Set the animation opacity
  642. }); //Hide the menu If the user clicked on any of the options
  643.  
  644. setTimeout(function() { //Hide the menu after some time
  645. menu.css({ //Set the menu css
  646. display: 'none' //Hide the menu on the page
  647. }); //Hide the menu If the user clicked on any of the options
  648. }, 300); //Finishes the setTimeout function
  649.  
  650. }); //Finishes the mouseup advent listener
  651. }); //Finishes the function
  652. //___________________________________________________________________________________________________________________________________________________________________________
  653. var HtmlMenu = document.createElement('div'); //Creates a variable
  654. HtmlMenu.setAttribute("id", "highlight_menu_div"); //Set the div id to the HtmlMenu variable
  655.  
  656. HtmlMenu.attachShadow({
  657. mode: 'open'
  658. }).innerHTML = '<style>.highlight_menu_animate .popuptext::after { content: ""; top: 100%; left: 50%; margin-left: -10px; border-top-width: 10px; border-right-width: 10px; border-left-width: 10px; position: absolute; border-style: solid; border-color: #292929 transparent transparent transparent; }</style><div id="highlight_menu" style="display:none; color: #fff; position: fixed; background-color: #292929; font-size: 13.4px; font-family: monospace; z-index: 9999;"> <ul style="margin-block-end: 10px; padding-left: 7px; padding-right: 7px; margin-top:10px;"><li class="popuptext" id="ShowCurrencyORUnits" style="cursor: pointer; display: inline;">' + FinalCurrency + '</li><li class="popuptext" id="SearchBTN" style="cursor: pointer; display: inline;">Search</li><li class="popuptext" id="CopyBTN" style="cursor: pointer; display: inline;"> | Copy</li></ul></div>'; //Set the HtmlMenu div html
  659.  
  660. if (document.body.textContent !== '' || document.body.innerText !== '') //If the body has any text
  661. { //Starts the if condition
  662. document.body.appendChild(HtmlMenu); //Append the HtmlMenu div to the page
  663. } //Finishes the if condition
  664.  
  665. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#SearchBTN").onmousedown = function() { //When the user clicks on the Search button
  666. var LinkfyOrSearch = 'https://www.google.com/search?q='; //Creates a variable to open google
  667. if (SelectedTextIsLink === true) //If the selected text is a link
  668. { //Starts the if condition
  669. LinkfyOrSearch = 'https://'; //Make the non http and non https links able to be opened
  670. } //Finishes the if condition
  671. if (SelectedText.match(/http:|https:/) !== null) //If the selected text is a link that already has http or https
  672. { //Starts the if condition
  673. LinkfyOrSearch = ''; //Remove the https:// that was previsouly added to this variable
  674. } //Finishes the if condition
  675.  
  676. window.open(LinkfyOrSearch + SelectedTextSearch); //Open google and search for the selected word(s)
  677. 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.
  678. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#highlight_menu").style.display = 'none'; //Hide the menu
  679. }; //Finishes the onmousedown advent listener
  680.  
  681. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#CopyBTN").onmousedown = function() { //When the user clicks on the copy button
  682. navigator.clipboard.writeText(SelectedText); //Copy the selected word(s)
  683. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#CopyBTN").innerText = ' | Done'; //Change the button text to Done
  684. setTimeout(function() { //Starts the setTimeout function
  685. 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
  686. }, 400); //Finishes the setTimeout function
  687. }; //Finishes the onmousedown advent listener
  688. //___________________________________________________________________________________________________________________________________________________________________________
  689. setTimeout(function() { //Starts the setTimeout function
  690. var AllIframes = document.querySelectorAll("iframe"); //Get all iframes on the page
  691. for (var i = AllIframes.length; i--;) { //Starts the for condition
  692. if (AllIframes[i].allow.match('clipboard-write;') === null && AllIframes[i].src.match(Links) !== null && AllIframes[i].src.match(/youtube|dailymotion|vimeo|streamtape|mcloud|vidstream|mp4upload|googlevideo|kaltura|crunchyroll|animesup|google.com\/recaptcha\/|blank.html|\.mp4/) === null && location.href.match(/animeshouse.net|nowanimes.com\/play/) === 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.
  693. { //Starts the if condition
  694. AllIframes[i].allow = AllIframes[i].allow + 'clipboard-write;'; //Add the permission to copy the iframe text
  695. AllIframes[i].src = AllIframes[i].src; //Reload the iframe to make the iframe have the new permission
  696. } //Finishes the if condition
  697. } //Finishes the for condition
  698. }, 4000); //Finishes the setTimeout function
  699.  
  700. window.addEventListener('scroll', async function() { //When the page is scrolled
  701. document.querySelector("#highlight_menu_div").shadowRoot.querySelector("#highlight_menu").style.display = 'none'; //Hide the menu
  702. if (LeftClicked === false && SelectedText !== '') { //If the Left Click isn't being holded, and if something is currently selected
  703. 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.
  704. } //Finishes the if condition
  705. }); //Finishes the onscroll advent listener
  706. } //Finishes the if condition