1C distributives grouper

Groups distributive links into OS-specific containers

目前为 2023-10-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name 1C distributives grouper
  3. // @description Groups distributive links into OS-specific containers
  4. // @version 0.4
  5. // @author Akpaev E.A.
  6. // @grant none
  7. // @namespace https://github.com/akpaevj
  8. // @license MIT
  9. // @match https://releases.1c.ru/version_files?nick=Platform83*
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. const container = document.createElement('div');
  15. container.className = 'container tabbale';
  16.  
  17. const ul = document.createElement('ul');
  18. ul.className = 'nav nav-tabs';
  19. container.append(ul);
  20.  
  21. const filesContainer = document.querySelector('.files-container');
  22. filesContainer.append(container);
  23.  
  24. const tabContent = document.createElement('div');
  25. tabContent.className = 'tab-content';
  26. container.append(tabContent);
  27.  
  28. function addTab(id, title, active = false) {
  29. const li = document.createElement('li');
  30. if (active) {
  31. li.className = 'active';
  32. }
  33. ul.append(li);
  34.  
  35. const a = document.createElement('a');
  36. a.setAttribute('href', `#${id}`);
  37. a.dataset.toggle = 'tab';
  38. a.textContent = title;
  39. li.append(a);
  40. }
  41.  
  42. function addPane(id, active = false, addSelectorRow = false) {
  43. const div = document.createElement('div');
  44. if (active) {
  45. div.className = 'tab-pane active';
  46. } else {
  47. div.className = 'tab-pane';
  48. }
  49. div.setAttribute('id', id);
  50. tabContent.append(div);
  51.  
  52. if (addSelectorRow) {
  53. const row = document.createElement('div');
  54. row.className = 'row-fluid';
  55. div.append(row);
  56. }
  57.  
  58. return div;
  59. }
  60.  
  61. function addTabAndPane(id, title, active = false, addSelectorRow = false) {
  62. addTab(id, title, active);
  63. return addPane(id, active, addSelectorRow);
  64. }
  65.  
  66. function addOption(select, value, title) {
  67. const option = document.createElement('option');
  68. option.setAttribute('value', value);
  69. option.textContent = title;
  70. select.append(option);
  71. }
  72.  
  73. function addArchSelector(pane) {
  74. const row = pane.querySelector('.row-fluid');
  75.  
  76. const span = document.createElement('div');
  77. span.className = 'span3';
  78. if (row === null) {
  79. pane.append(span);
  80. } else {
  81. row.append(span);
  82. }
  83.  
  84. const label = document.createElement('label');
  85. label.setAttribute('for', 'arch-select');
  86. label.textContent = 'Arch:';
  87. span.append(label);
  88.  
  89. const select = document.createElement('select');
  90. select.setAttribute('id', 'arch-select');
  91. span.append(select);
  92.  
  93. addOption(select, 'all', 'all');
  94. addOption(select, '86', 'x86');
  95. addOption(select, '64', 'x64');
  96.  
  97. select.onchange = (event) => {
  98. const value = select.selectedOptions[0].value;
  99.  
  100. if (value === 'all') {
  101. pane.querySelectorAll('.formLine').forEach((e) => {
  102. e.style.display = "block";
  103. });
  104. } else if (value === '86') {
  105. pane.querySelectorAll('.formLine').forEach((e) => {
  106. if (/.*64-bit.*/i.test(e.querySelector('a').innerText)) {
  107. e.style.display = "none";
  108. } else {
  109. e.style.display = "block";
  110. }
  111. });
  112. } else {
  113. pane.querySelectorAll('.formLine').forEach((e) => {
  114. if (/.*64-bit.*/i.test(e.querySelector('a').innerText)) {
  115. e.style.display = "block";
  116. } else {
  117. e.style.display = "none";
  118. }
  119. });
  120. }
  121. };
  122. }
  123.  
  124. const cCont = addTabAndPane('common', 'Common', true, true);
  125. addArchSelector(cCont);
  126.  
  127. const wCont = addTabAndPane('windows', 'Windows', false, true);
  128. addArchSelector(wCont);
  129.  
  130. const lCont = addTabAndPane('linux', 'Linux', false, true);
  131. addArchSelector(lCont);
  132.  
  133. const mCont = addTabAndPane('mac', 'Mac');
  134. const oCont = addTabAndPane('other', 'Other');
  135.  
  136. document.querySelectorAll(".formLine").forEach((e) => {
  137. const a = e.querySelector('a');
  138.  
  139. if (/.*Windows.*/i.test(a.innerText) && (/.*Linux.*/i.test(a.innerText) || /.*MacOS.*/i.test(a.innerText))) {
  140. cCont.append(e)
  141. } else if (/.*Windows.*/i.test(a.innerText)) {
  142. wCont.append(e)
  143. } else if (/.*Linux.*/i.test(a.innerText)) {
  144. lCont.append(e)
  145. } else if (/.*MacOS.*/i.test(a.innerText)) {
  146. mCont.append(e)
  147. } else {
  148. oCont.append(e)
  149. }
  150. });
  151. })();