Advertisement
Guest User

Untitled

a guest
Feb 10th, 2021
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   $(function() { //Starts the function
  2.     var menu = $("#highlight_menu_div")[0].shadowRoot.querySelector("#highlight_menu"); //Creates a variable to hold the menu element
  3.     $(document.body).on('mouseup', function() { //When the user releases the mouse click after selecting something
  4.  
  5.       if (document.getSelection().toString() !== '') { //If the user selected something
  6.         var p = document.getSelection().getRangeAt(0).getBoundingClientRect(); //Create a new variable to get the positions later
  7.         menu.css({ //Set the menu css
  8.           left: (p.left + (p.width / 2)) - (menu.width() / 2), //Make the menu show on the correct left position
  9.           top: (p.top - menu.height() - 10), //Make the menu show on the correct top position
  10.           display: '' //Show the menu on the page
  11.         }).animate({ //Creates the animation animation
  12.           opacity: 1 //Set the animation opacity
  13.         }, 0); //Add an animation to the menu
  14.  
  15.         menu.addClass('highlight_menu_animate'); //Add the class to animate the menu
  16.         $('head').append('<style>.highlight_menu_animate .popuptext::after { content: ""; height: 35px; 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
  17.         return; //Keep displaying the menu box
  18.       } //Finishes the if condition
  19.       menu.animate({ //Creates the animation animation
  20.         opacity: 0 //Set the animation opacity
  21.       }); //Hide the menu If the user clicked on any of the options
  22.     }); //Finishes the mouseup advent listener
  23.   }); //Finishes the function
  24.  
  25.  
  26.   var el = document.createElement('div');
  27.   el.setAttribute("id", "highlight_menu_div");
  28.  
  29. el.attachShadow({ mode: 'open' }).innerHTML = '<div id="highlight_menu" style="width: 110px; display:none; color: #fff; position: fixed; background-color: #292929; font-size: 13.4px; font-family: monospace;box-sizing: unset; z-index: 999;"> <ul style="font-size: unset; margin-left: unset; margin-bottom: unset; margin-inline-end: unset; margin-inline-start: unset;  margin-block-end: 10px;  margin-block-start: unset; padding-left: 7px; padding-right: 7px; margin-top:10px;"><li class="popuptext" id="SearchBTN" style="cursor: pointer; display: inline; padding: unset; background-color: unset; font-size: unset; line-height: unset;">Search</li><li class="popuptext" id="CopyBTN" style="cursor: pointer; display: inline; padding: unset; background-color: unset; font-size: unset; line-height: unset;"> | Copy</li></ul></div>';
  30.  
  31.  
  32. document.body.appendChild(el);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement