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.

当前为 2021-06-24 提交的版本,查看 最新版本

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