Advertisement
Guest User

GuildScreenShareResizeBorder.plugin

a guest
Feb 17th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Script made by Lisa (Lisa#3995) */
  2. /* based on the code made by Hung Nguyen */
  3. /* [.pictureInPictureWindow-1B5qSe] - там, где transform; [.pictureInPictureVideo-20ZvXn] - ниже, внутри которого сразу span */
  4. window.GSSRBInterval = 'on';
  5. function makeResizableVS(div, dis, dsiz)
  6. {
  7.     const VSDisElement = document.querySelector(dis);
  8.     const VSDisSizElement = document.querySelector(dsiz);
  9.     const VSElement = document.querySelector(div);
  10.     const VSResizers = document.querySelectorAll(div + ' .resizer');
  11.     const VSMinSize = 60;
  12.     let original_width = 0;
  13.     let original_height = 0;
  14.     let original_x = 0;
  15.     let original_y = 0;
  16.     let original_mouse_x = 0;
  17.     let original_mouse_y = 0;
  18.     for (let i = 0;i < VSResizers.length; i++)
  19.     {
  20.         const currentResizer = VSResizers[i];
  21.         currentResizer.addEventListener('mousedown', function(e)
  22.         {
  23.             e.preventDefault();
  24.             original_width = parseFloat(getComputedStyle(VSElement, null).getPropertyValue('width').replace('px', ''));
  25.             original_height = parseFloat(getComputedStyle(VSElement, null).getPropertyValue('height').replace('px', ''));
  26.             original_x = VSElement.getBoundingClientRect().left;
  27.             original_y = VSElement.getBoundingClientRect().top;
  28.             original_mouse_x = e.pageX;
  29.             original_mouse_y = e.pageY;
  30.             window.addEventListener('mousemove', VSStartResize);
  31.             window.addEventListener('mouseup', VSStopResize);
  32.         });
  33.  
  34.         function VSStartResize(e)
  35.         {
  36.             if (currentResizer.classList.contains('bottom-right'))
  37.             {
  38.                 const width = original_width + (e.pageX - original_mouse_x);
  39.                 const height = original_height + (e.pageY - original_mouse_y);
  40.                 if (width > VSMinSize)
  41.                 {
  42.                     VSElement.style.width = width + 'px';
  43.                     VSDisSizElement.style.setProperty('width', width + 'px');
  44.                 }
  45.                 if (height > VSMinSize)
  46.                 {
  47.                     VSElement.style.height = height + 'px';
  48.                     VSDisSizElement.style.setProperty('height', height + 'px');
  49.                 }
  50.             }
  51.             else if (currentResizer.classList.contains('bottom-left'))
  52.             {
  53.                 const height = original_height + (e.pageY - original_mouse_y);
  54.                 const width = original_width - (e.pageX - original_mouse_x);
  55.                 if (height > VSMinSize)
  56.                 {
  57.                     VSElement.style.height = height + 'px';
  58.                     VSDisSizElement.style.setProperty('height', height + 'px');
  59.                 }
  60.                 if (width > VSMinSize)
  61.                 {
  62.                     VSElement.style.width = width + 'px';
  63.                     VSDisSizElement.style.setProperty('width', width + 'px');
  64.                     VSElement.style.left = original_x + (e.pageX - original_mouse_x) + 'px';
  65.                     VSDisElement.style.setProperty('transform', VSDisElement.style.getPropertyValue('transform').replace(VSDisElement.style.getPropertyValue('transform').split('translate')[1], VSDisElement.style.getPropertyValue('transform').split('translate')[1].replace(VSDisElement.style.getPropertyValue('transform').split('(')[1].split(')')[0].replace('px', ''), original_x + (e.pageX - original_mouse_x))));
  66.                 }
  67.             }
  68.             else if (currentResizer.classList.contains('top-right'))
  69.             {
  70.                 const width = original_width + (e.pageX - original_mouse_x);
  71.                 const height = original_height - (e.pageY - original_mouse_y);
  72.                 if (width > VSMinSize)
  73.                 {
  74.                     VSElement.style.width = width + 'px';
  75.                     VSDisSizElement.style.setProperty('width', width + 'px');
  76.                 }
  77.                 if (height > VSMinSize)
  78.                 {
  79.                     VSElement.style.height = height + 'px';
  80.                     VSDisSizElement.style.setProperty('height', height + 'px');
  81.                     VSElement.style.top = original_y + (e.pageY - original_mouse_y) + 'px';
  82.                     VSDisElement.style.setProperty('transform', VSDisElement.style.getPropertyValue('transform').replace(VSDisElement.style.getPropertyValue('transform').split('translate')[2], VSDisElement.style.getPropertyValue('transform').split('translate')[2].replace(VSDisElement.style.getPropertyValue('transform').split('(')[2].split(')')[0].replace('px', ''), original_y + (e.pageY - original_mouse_y))));
  83.                 }
  84.             }
  85.             else
  86.             {
  87.                 const width = original_width - (e.pageX - original_mouse_x);
  88.                 const height = original_height - (e.pageY - original_mouse_y);
  89.                 if (width > VSMinSize)
  90.                 {
  91.                     VSElement.style.width = width + 'px';
  92.                     VSDisSizElement.style.setProperty('width', width + 'px');
  93.                     VSElement.style.left = original_x + (e.pageX - original_mouse_x) + 'px';
  94.                     VSDisElement.style.setProperty('transform', VSDisElement.style.getPropertyValue('transform').replace(VSDisElement.style.getPropertyValue('transform').split('translate')[1], VSDisElement.style.getPropertyValue('transform').split('translate')[1].replace(VSDisElement.style.getPropertyValue('transform').split('(')[1].split(')')[0].replace('px', ''), original_x + (e.pageX - original_mouse_x))));
  95.                 }
  96.                 if (height > VSMinSize)
  97.                 {
  98.                     VSElement.style.height = height + 'px';
  99.                     VSDisSizElement.style.setProperty('height', height + 'px');
  100.                     VSElement.style.top = original_y + (e.pageY - original_mouse_y) + 'px';
  101.                     VSDisElement.style.setProperty('transform', VSDisElement.style.getPropertyValue('transform').replace(VSDisElement.style.getPropertyValue('transform').split('translate')[2], VSDisElement.style.getPropertyValue('transform').split('translate')[2].replace(VSDisElement.style.getPropertyValue('transform').split('(')[2].split(')')[0].replace('px', ''), original_y + (e.pageY - original_mouse_y))));
  102.                 }
  103.             }
  104.         }
  105.  
  106.         function VSStopResize()
  107.         {
  108.             window.removeEventListener('mousemove', VSStartResize);
  109.         }
  110.     }
  111. }
  112.  
  113. function VShareWindowFix()
  114. {
  115.     try
  116.     {
  117.         if((document.querySelector('.pictureInPictureVideo-20ZvXn') != null) && (document.querySelector('.VSResizableWindow') != null))
  118.         {
  119.             if((document.querySelector('.VSResizableWindow').style.getPropertyValue('left') != document.querySelector('.pictureInPictureWindow-1B5qSe').style.getPropertyValue('transform').split('(')[1].split(')')[0]) || (document.querySelector('.VSResizableWindow').style.getPropertyValue('top') != document.querySelector('.pictureInPictureWindow-1B5qSe').style.getPropertyValue('transform').split('(')[2].split(')')[0]) || (document.querySelector('.pictureInPictureVideo-20ZvXn').style.getPropertyValue('width') != document.querySelector('.VSResizableWindow').style.getPropertyValue('width')) || (document.querySelector('.pictureInPictureVideo-20ZvXn').style.getPropertyValue('height') != document.querySelector('.VSResizableWindow').style.getPropertyValue('height')))
  120.             {
  121.                 document.querySelector('.VSResizableWindow').style.setProperty('left', document.querySelector('.pictureInPictureWindow-1B5qSe').style.getPropertyValue('transform').split('(')[1].split(')')[0]);
  122.                 document.querySelector('.VSResizableWindow').style.setProperty('top', document.querySelector('.pictureInPictureWindow-1B5qSe').style.getPropertyValue('transform').split('(')[2].split(')')[0]);
  123.             }
  124.         }
  125.     } catch(err){}
  126. }
  127.  
  128. var GSSRBInterval;
  129. GSSRBInterval = setInterval(function()
  130. {
  131.     try
  132.     {
  133.         if(document.querySelector('.pictureInPictureVideo-20ZvXn') != null)
  134.         {
  135.             if(document.querySelector('.VSResizableWindow') == null && document.querySelector('.pictureInPictureWindow-1B5qSe') != null)
  136.             {
  137.                 var VSResizableWindow;
  138.                 VSResizableWindow = document.createElement('div');
  139.                 VSResizableWindow.innerHTML =
  140. `
  141. <div class='resizers' style='border: 3px solid purple; box-sizing: border-box; margin-left: -3px; margin-top: -3px; width: calc(100% + 5px); height: calc(100% + 5px);'>
  142. <style type="text/css">.resizers .resizer { width: 10px; height: 10px; border-radius: 50%; background: white; border: 3px solid purple; opacity: 0.6; position: absolute; }</style>
  143. <div class='resizer top-left' style='left: -8px; top: -8px; cursor: nwse-resize;'></div>
  144. <div class='resizer top-right' style='right: -8px; top: -8px; cursor: nesw-resize;'></div>
  145. <div class='resizer bottom-left' style='left: -8px; bottom: -8px; cursor: nesw-resize;'></div>
  146. <div class='resizer bottom-right' style='right: -8px; bottom: -8px; cursor: nwse-resize;'></div>
  147. </div>
  148. `
  149.                 VSResizableWindow.setAttribute("class", "VSResizableWindow");
  150.                 VSResizableWindow.style = "width: 640px; height: 360px; position: absolute; overflow: visible;";   
  151.                 document.querySelector('.pictureInPictureWindow-1B5qSe').before(VSResizableWindow);
  152.                
  153.                 makeResizableVS('.VSResizableWindow', '.pictureInPictureWindow-1B5qSe', '.pictureInPictureVideo-20ZvXn');
  154.  
  155.                 var VShareWindowFixInterval;
  156.                 VShareWindowFixInterval = setInterval(function()
  157.                 {
  158.                     VShareWindowFix();
  159.                     if (document.querySelector('.VSResizableWindow') == null)
  160.                     {
  161.                         clearInterval(VShareWindowFixInterval);
  162.                     }
  163.                 }, 0);
  164.             }
  165.         }
  166.         else
  167.         {
  168.             if(document.querySelector('.VSResizableWindow') != null)
  169.             {
  170.                 document.querySelector('.VSResizableWindow').remove();
  171.             }
  172.         }
  173.     } catch(err){}
  174. if(window.GSSRBInterval == 'off')
  175. {
  176.     clearInterval(GSSRBInterval);
  177. }
  178. },0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement