Guest User

Untitled

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