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-03-02 提交的版本,查看 最新版本

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