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.

当前为 2024-02-04 提交的版本,查看 最新版本

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