Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.14 KB | None | 0 0
  1. (function() {
  2. let strict = true
  3.  
  4. function addControls() {
  5. // control panel
  6. const controlPanel = document.createElement('div');
  7. controlPanel.setAttribute('id', 'edsControlPanel');
  8.  
  9. const header = document.createElement('h3');
  10. header.innerText = 'EDS GitHub Control Panel';
  11. controlPanel.append(header);
  12.  
  13. const input = document.createElement('input');
  14. input.setAttribute('id', 'edsControlTextInput');
  15. input.setAttribute('placeholder', 'source/webapp-');
  16. input.setAttribute('type', 'text');
  17. controlPanel.append(input);
  18.  
  19. const strictCheckbox = document.createElement('input');
  20. strictCheckbox.setAttribute('type', 'checkbox');
  21. strictCheckbox.setAttribute('checked', strict);
  22.  
  23. const strictLabel = document.createElement('label');
  24. strictLabel.setAttribute('id', 'strictLabel');
  25. strictLabel.innerText = 'Strict: ';
  26. strictLabel.append(strictCheckbox);
  27. controlPanel.append(strictLabel);
  28.  
  29. const commonButton = document.createElement('button');
  30. commonButton.setAttribute('id', 'commonControlClearInputAndDisplayCss');
  31. commonButton.innerText = 'Common';
  32. controlPanel.append(commonButton);
  33.  
  34. const boxbeButton = document.createElement('button');
  35. boxbeButton.setAttribute('id', 'boxbeControlClearInputAndDisplayCss');
  36. boxbeButton.innerText = 'Boxbe';
  37. controlPanel.append(boxbeButton);
  38.  
  39. const analystButton = document.createElement('button');
  40. analystButton.setAttribute('id', 'analystControlClearInputAndDisplayCss');
  41. analystButton.innerText = 'Analyst';
  42. controlPanel.append(analystButton);
  43.  
  44. const adminButton = document.createElement('button');
  45. adminButton.setAttribute('id', 'adminControlClearInputAndDisplayCss');
  46. adminButton.innerText = 'Admin';
  47. controlPanel.append(adminButton);
  48.  
  49. const diButton = document.createElement('button');
  50. diButton.setAttribute('id', 'dIControlClearInputAndDisplayCss');
  51. diButton.innerText = 'DI';
  52. controlPanel.append(diButton);
  53.  
  54. const button = document.createElement('button');
  55. button.setAttribute('id', 'edsControlClearInputAndDisplayCss');
  56. button.style.marginLeft = '10px';
  57. button.innerText = 'Clear';
  58. controlPanel.append(button);
  59.  
  60. document.querySelector('.application-main #js-repo-pjax-container').append(controlPanel);
  61.  
  62. // control panel styles
  63. var sheet = document.createElement('style');
  64. sheet.innerHTML = `#edsControlPanel {
  65. padding: 10px;
  66. position: fixed;
  67. left: 10px;
  68. bottom: 10px;
  69. width: 400px;
  70. height: 150px;
  71. z-index: 1000;
  72. display: block;
  73. background: white;
  74. border: 1px solid black;
  75. border-radius: 4px;
  76. color: black;
  77. }
  78.  
  79. #edsControlTextInput {
  80. margin-top: 42px;
  81. width: 100%;
  82. }
  83.  
  84. #strictLabel {
  85. position: absolute;
  86. left: 10px;
  87. }
  88. `;
  89.  
  90. document.head.appendChild(sheet);
  91. }
  92. addControls();
  93.  
  94. const input = document.getElementById('edsControlTextInput');
  95.  
  96. const strictLabel = document.getElementById('strictLabel');
  97. const strictCheckbox = document.querySelectorAll('#strictLabel > input')[0];
  98.  
  99. const ctrlClearButton = document.getElementById('edsControlClearInputAndDisplayCss');
  100.  
  101. const commonButton = document.getElementById('commonControlClearInputAndDisplayCss');
  102. const boxbeButton = document.getElementById('boxbeControlClearInputAndDisplayCss');
  103. const analystButton = document.getElementById('analystControlClearInputAndDisplayCss')
  104. const adminButton = document.getElementById('adminControlClearInputAndDisplayCss')
  105. const diButton = document.getElementById('dIControlClearInputAndDisplayCss')
  106.  
  107. function addListener() {
  108. function filter() {
  109. const files = document.querySelectorAll('.file-info');
  110.  
  111. for (var i = files.length - 1; i >= 0; i--) {
  112. let title = files[i].querySelector('a[title]').title;
  113. if (input && !input.value) {
  114. files[i].parentElement.parentElement.style.display = 'block';
  115. return;
  116. }
  117.  
  118. let regexMatches = strict ? new RegExp('^' + input.value).test(title) : new RegExp(input.value).test(title);
  119. if (regexMatches) {
  120. files[i].parentElement.parentElement.style.display = 'block';
  121. } else {
  122. files[i].parentElement.parentElement.style.display = 'none';
  123. }
  124. }
  125. }
  126. input.addEventListener('blur', filter);
  127.  
  128. strictLabel.addEventListener('click', (e) => {
  129. strict = !strict;
  130. });
  131.  
  132. ctrlClearButton.addEventListener('click', (e) => {
  133. for (var i = files.length - 1; i >= 0; i--) {
  134. files[i].parentElement.parentElement.style.display = 'block';
  135. }
  136. input.value = '';
  137. });
  138.  
  139. commonButton.addEventListener('click', (e) => {
  140. input.value = 'common/';
  141. window.setTimeout(function() {
  142. filter();
  143. }, 500);
  144. });
  145.  
  146. boxbeButton.addEventListener('click', (e) => {
  147. input.value = 'boxbe/';
  148. window.setTimeout(function() {
  149. filter();
  150. }, 500);
  151. });
  152.  
  153. analystButton.addEventListener('click', (e) => {
  154. input.value = 'source/webapp-analyst-ng/';
  155. window.setTimeout(function() {
  156. filter();
  157. }, 500);
  158. });
  159.  
  160. adminButton.addEventListener('click', (e) => {
  161. input.value = 'source/webapp-admin-ng/';
  162. window.setTimeout(function() {
  163. filter();
  164. }, 500);
  165. });
  166.  
  167. diButton.addEventListener('click', (e) => {
  168. input.value = 'source/webapp-delivery-index/';
  169. window.setTimeout(function() {
  170. filter();
  171. }, 500);
  172. });
  173. };
  174.  
  175. addListener();
  176. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement