Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. globalSearch () {
  2.   const globalSearchInput = document.getElementById('tc-global-search-input'),
  3.         globalSearchOuter = document.getElementById('tc-global-search-outer');
  4.  
  5.   if (!globalSearchOuter) return;
  6.  
  7.   function sendInput() {
  8.       const quickSwitcherInput = document.querySelector('.input-MwQhcX');
  9.  
  10.       function sendCtrlK() {
  11.         var options = { key: "k", code: "k", which: 75, keyCode: 75, "ctrlKey": true, bubbles: true };
  12.         var down = new KeyboardEvent("keydown", options);
  13.         Object.defineProperty(down, "keyCode", {value: 75});
  14.         Object.defineProperty(down, "which", {value: 75});
  15.         Object.defineProperty(down, "ctrlKey", {value: true});
  16.         var press = new KeyboardEvent("keypress", options);
  17.         Object.defineProperty(press, "keyCode", {value: 75});
  18.         Object.defineProperty(press, "which", {value: 75});
  19.         Object.defineProperty(press, "ctrlKey", {value: true});
  20.         document.querySelector('#app-mount').dispatchEvent(down);
  21.         document.querySelector('#app-mount').dispatchEvent(press);
  22.       }
  23.      
  24.       function checkForClosed(e) {
  25.         var quickSwitcher = '.container-3uJcWB, .container-3uJcWB *',
  26.             backdrop = document.querySelector('.backdrop-2ohBEd'),
  27.             backdropQuickSwitcherCheck = document.querySelector('.backdrop-2ohBEd + .modal-2LIEKY .quickswitcher-2NdiGJ'),
  28.             clickTarget = e.target;
  29.         console.log('pie');
  30.         if (clickTarget.matches(quickSwitcher)) {
  31.           return;
  32.         } else {
  33.           if (backdropQuickSwitcherCheck) {
  34.             globalSearchOuter.classList.remove('opened');
  35.             document.removeEventListener('click', checkForClosed, false);
  36.             backdrop.click();
  37.           }
  38.         }
  39.       }
  40.      
  41.       if (quickSwitcherInput) {
  42.         var quickParent = quickSwitcherInput.parentElement,
  43.         quickSwitcherContainer = '.quickswitcher-2NdiGJ';
  44.  
  45.         if (quickParent.matches(quickSwitcherContainer)) {
  46.           globalSearchInput.before(quickSwitcherInput);
  47.         }
  48.        
  49.         document.removeEventListener('click', checkForClosed, false);
  50.       } else {
  51.         sendCtrlK();
  52.         document.addEventListener('click', checkForClosed, false);
  53.       }
  54.   }
  55.   globalSearchInput.addEventListener('focus', sendInput, false);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement