1C distributives grouper

Groups distributive links to OS-specific containers

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

  1. // ==UserScript==
  2. // @name 1C distributives grouper
  3. // @description Groups distributive links to OS-specific containers
  4. // @version 0.2
  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) {
  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. return div;
  53. }
  54.  
  55. function addTabAndPane(id, title, active = false) {
  56. addTab(id, title, active);
  57. return addPane(id, active);
  58. }
  59.  
  60. const cCont = addTabAndPane('common', 'Common', true);
  61. const wCont = addTabAndPane('windows', 'Windows');
  62. const lCont = addTabAndPane('linux', 'Linux');
  63. const mCont = addTabAndPane('mac', 'Mac');
  64. const oCont = addTabAndPane('other', 'Other');
  65.  
  66. document.querySelectorAll(".formLine").forEach((e) => {
  67. const a = e.querySelector('a');
  68.  
  69. if (/.*Windows.*/i.test(a.innerText) && (/.*Linux.*/i.test(a.innerText) || /.*MacOS.*/i.test(a.innerText))) {
  70. cCont.append(e)
  71. } else if (/.*Windows.*/i.test(a.innerText)) {
  72. wCont.append(e)
  73. } else if (/.*Linux.*/i.test(a.innerText)) {
  74. if (/.*RPM.*/i.test(a.innerText)) {
  75. lCont.append(e)
  76. } else {
  77. lCont.append(e)
  78. }
  79. } else if (/.*MacOS.*/i.test(a.innerText)) {
  80. mCont.append(e)
  81. } else {
  82. oCont.append(e)
  83. }
  84. });
  85. })();