virtualmanager.com - Employee show stars and role

Shows stars and role on employeesearch

  1. // ==UserScript==
  2. // @name virtualmanager.com - Employee show stars and role
  3. // @namespace https://greasyfork.org/en/users/884999-l%C3%A6ge-manden
  4. // @version 0.6
  5. // @description Shows stars and role on employeesearch
  6. // @author VeryDoc
  7. // @match https://www.virtualmanager.com/employees/search?*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=virtualmanager.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. window.addEventListener('load', () => {
  16. setInterval(function () {
  17. loadPlugin();
  18. }, 500);
  19. });
  20.  
  21. window.addEventListener('popstate', function (event) {
  22. loadPlugin();
  23. });
  24.  
  25. function loadPlugin() {
  26. let myTable = document.getElementsByTagName("table")[0].getElementsByTagName('tbody')[0];
  27. let foundOne = false;
  28. let rows = myTable.rows;
  29.  
  30. for (let row of rows) {
  31. if (row.classList.contains('toprow') === true) {
  32. if (row.classList.contains('changed') === true) {
  33. return;
  34. }
  35.  
  36. addSearch();
  37. getValuesFromLocalStorage();
  38.  
  39. let youth = document.getElementById('custom-youth').value;
  40. let goalkeeper = document.getElementById('custom-goalkeeper').value;
  41. let field = document.getElementById('custom-field').value;
  42. let disiplin = document.getElementById('custom-disiplin').value;
  43. let motivation = document.getElementById('custom-motivation').value;
  44.  
  45. if (youth === '' && goalkeeper === '' && field === '' && disiplin === '' && motivation === '') {
  46. let newCell = row.insertCell();
  47. newCell.colSpan = 2;
  48. let newText = document.createTextNode('Please select one or more attributes to start search..');
  49. newCell.appendChild(newText);
  50. } else {
  51. let newCell = row.insertCell();
  52. let newText = document.createTextNode('Ability');
  53. newCell.appendChild(newText);
  54.  
  55. newCell = row.insertCell();
  56. newText = document.createTextNode('Should buy!');
  57. newCell.appendChild(newText);
  58. }
  59.  
  60. row.classList.add('changed');
  61. } else {
  62. let a = row.cells[7];
  63. let skillstable = a.getElementsByTagName("table")[0].getElementsByTagName('tbody')[0];
  64. let skills = skillstable.children;
  65. let youthSkills = parseInt(skills[0].innerText.trim().replace(' ', '').replace('\n', ':').split(':')[1]);
  66. let goalkeepingSkills = parseInt(skills[1].innerText.trim().replace(' ', '').replace('\n', ':').split(':')[1]);
  67. let fieldplayerSkills = parseInt(skills[2].innerText.trim().replace(' ', '').replace('\n', ':').split(':')[1]);
  68. let disiplinSkills = parseInt(skills[3].innerText.trim().replace(' ', '').replace('\n', ':').split(':')[1]);
  69. let scountPotential = parseInt(skills[4].innerText.trim().replace(' ', '').replace('\n', ':').split(':')[1]);
  70. let motivationSkills = parseInt(skills[7].innerText.trim().replace(' ', '').replace('\n', ':').split(':')[1]);
  71.  
  72. let totalSkills = youthSkills + goalkeepingSkills + fieldplayerSkills + disiplinSkills + motivationSkills;
  73. let newCell = row.insertCell();
  74.  
  75. let newText = document.createTextNode('⭐');
  76.  
  77. switch (true) {
  78. case (totalSkills > 80):
  79. newText = document.createTextNode('⭐⭐⭐⭐⭐');
  80. break;
  81. case (totalSkills > 60 && totalSkills < 80):
  82. newText = document.createTextNode('⭐⭐⭐⭐');
  83. break;
  84. case (totalSkills > 40 && totalSkills < 60):
  85. newText = document.createTextNode('⭐⭐⭐');
  86. break;
  87. case (totalSkills > 20 && totalSkills < 40):
  88. newText = document.createTextNode('⭐⭐');
  89. break;
  90. }
  91.  
  92. let youth = parseInt(document.getElementById('custom-youth').value);;
  93. let goalkeeper = parseInt(document.getElementById('custom-goalkeeper').value);
  94. let field = parseInt(document.getElementById('custom-field').value);
  95. let disiplin = parseInt(document.getElementById('custom-disiplin').value);
  96. let motivation = parseInt(document.getElementById('custom-motivation').value);
  97. let scout = parseInt(document.getElementById('custom-scouting').value);
  98.  
  99. newCell.appendChild(newText);
  100. if (youth === '' && goalkeeper === '' && field === '' && disiplin === '' && motivation === '') {
  101. } else {
  102. if (youthSkills >= youth && fieldplayerSkills >= field && goalkeepingSkills >= goalkeeper && disiplinSkills >= disiplin && motivationSkills >= motivation && scountPotential >= scout) {
  103. newCell = row.insertCell();
  104. newCell.style.fontSize = "9px";
  105. newText = document.createTextNode("Yes");
  106. newCell.appendChild(newText);
  107. newCell.style.backgroundColor = "green";
  108. foundOne = true;
  109. }
  110. else {
  111. newCell = row.insertCell();
  112. newCell.style.fontSize = "9px";
  113. newText = document.createTextNode("No");
  114. newCell.appendChild(newText);
  115. newCell.style.backgroundColor = "red";
  116. }
  117. }
  118. }
  119. }
  120.  
  121. // if (foundOne === false) {
  122. // let time = 1000 + Math.random() * 1000;
  123. // setTimeout(function () {
  124. // let a = document.getElementsByClassName('next_page');
  125. // window.location = a[0].href;
  126. // }, time);
  127. // } else {
  128. // alert('Found one!!!');
  129. // }
  130. };
  131.  
  132. function addSearch() {
  133. let box = document.createElement('div');
  134. box.className = 'box';
  135. box.id = 'custom-search-box';
  136.  
  137. let header = document.createElement('h2');
  138. header.innerText = 'Søgning';
  139.  
  140. box.appendChild(header);
  141.  
  142. let table = document.createElement('table');
  143. table.className = 'stretch';
  144. table.id = 'custom-search-table';
  145. let row = table.insertRow(0);
  146. addRowWithTextbox(table, 'Ungdomstræning', 'custom-youth');
  147. addRowWithTextbox(table, 'Målmandstræning', 'custom-goalkeeper');
  148. addRowWithTextbox(table, 'Markspillertræning', 'custom-field');
  149. addRowWithTextbox(table, 'Scouting potentiale', 'custom-scouting');
  150. addRowWithTextbox(table, 'Disiplin', 'custom-disiplin');
  151. addRowWithTextbox(table, 'Motivation', 'custom-motivation');
  152.  
  153. row = table.insertRow(-1);
  154. let cell1 = row.insertCell(0);
  155. let cell2 = row.insertCell(1);
  156.  
  157. cell1.innerText = 'Auto next';
  158. cell1.style.width = '40%';
  159.  
  160. let autoNext = document.createElement('INPUT');
  161. autoNext.setAttribute("type", "checkbox");
  162. autoNext.id = 'custom-autonext';
  163.  
  164. cell2.appendChild(autoNext);
  165.  
  166. box.appendChild(table);
  167.  
  168. let buttonDiv = document.createElement('div');
  169. buttonDiv.className = 'right'
  170.  
  171. let SaveButton = document.createElement('button');
  172. SaveButton.className = 'btn';
  173. SaveButton.innerText = 'Gem';
  174. SaveButton.onclick = function () { saveValuesToLocalStoarage(); window.location.reload(); };
  175. buttonDiv.appendChild(SaveButton);
  176.  
  177. box.appendChild(buttonDiv);
  178.  
  179. let attachBox = document.getElementsByClassName('employees_search')[0];
  180. attachBox.appendChild(box);
  181. }
  182.  
  183. function addRowWithTextbox(table, text, id) {
  184. let row = table.insertRow(-1);
  185. let cell1 = row.insertCell(0);
  186. let cell2 = row.insertCell(1);
  187.  
  188. cell1.innerText = text;
  189. cell1.style.width = '40%';
  190.  
  191. let inputElement = document.createElement('INPUT');
  192. inputElement.setAttribute("type", "text");
  193. inputElement.setAttribute("size", "1");
  194. inputElement.setAttribute("maxlength", "2");
  195. inputElement.id = id;
  196.  
  197. inputElement.className = 'center';
  198. inputElement.style.width = '20px';
  199.  
  200. cell2.appendChild(inputElement);
  201. }
  202.  
  203. function saveValuesToLocalStoarage() {
  204. localStorage.setItem('custom-search-youth', document.getElementById('custom-youth').value);
  205. localStorage.setItem('custom-search-goalkeeper', document.getElementById('custom-goalkeeper').value);
  206. localStorage.setItem('custom-search-field', document.getElementById('custom-field').value);
  207. localStorage.setItem('custom-search-disiplin', document.getElementById('custom-disiplin').value);
  208. localStorage.setItem('custom-search-motivation', document.getElementById('custom-motivation').value);
  209. localStorage.setItem('custom-search-scouting', document.getElementById('custom-scouting').value);
  210. }
  211.  
  212. function getValuesFromLocalStorage() {
  213. document.getElementById('custom-youth').value = localStorage.getItem('custom-search-youth');
  214. document.getElementById('custom-goalkeeper').value = localStorage.getItem('custom-search-goalkeeper');
  215. document.getElementById('custom-field').value = localStorage.getItem('custom-search-field');
  216. document.getElementById('custom-disiplin').value = localStorage.getItem('custom-search-disiplin');
  217. document.getElementById('custom-motivation').value = localStorage.getItem('custom-search-motivation');
  218. document.getElementById('custom-scouting').value = localStorage.getItem('custom-search-scouting');
  219. }
  220. })();