SUAI hide tasks

Добавляет чекбокс для скрытия заданий в лк гуапа

目前为 2021-12-12 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name SUAI hide tasks
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.2
  5. // @description Добавляет чекбокс для скрытия заданий в лк гуапа
  6. // @author goodhumored
  7. // @license MIT
  8. // @match https://pro.guap.ru/inside_s
  9. // @icon https://www.google.com/s2/favicons?domain=guap.ru
  10. // @grant GM.setValue
  11. // @grant GM.getValue
  12. // @run-at document-end
  13. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18. var hidden_tasks = [];
  19. var hiding = true;
  20. var interval = setInterval(async function() {
  21. if ($('.panel-body').length > 1) {
  22. hidden_tasks = await GM.getValue('hidden_tasks', []);
  23. hiding = await GM.getValue('hiding', true);
  24. let row = $('.panel-body')[0].appendChild(document.createElement('div'));
  25. row.className = 'row';
  26. let cm3 = row.appendChild(document.createElement('div'));
  27. cm3.className = 'col-md-3';
  28. let fg = cm3.appendChild(document.createElement('div'));
  29. fg.className = 'form-group';
  30. let label = fg.appendChild(document.createElement('label'));
  31. label.innerText = 'Скрывать помеченные задания ';
  32. let hideC = label.appendChild(document.createElement('input'));
  33. hideC.type = 'checkbox';
  34. hideC.onchange = (event) => hide(event.target.checked);
  35. hideC.checked = hiding;
  36. add_checkboxes();
  37. let c = $('[name=tableTasks_length]')[0];
  38. $('[name=tableTasks_length]').change((event) => {GM.setValue('show_count', event.target.value); add_checkboxes();})
  39. c.value = await GM.getValue('show_count', 15);
  40. c.dispatchEvent(new Event('change'));
  41. clearInterval(interval);
  42. }
  43. }, 3000);
  44. function add_checkboxes() {
  45. $('#tableTasks tbody tr').each(function(i, e) {
  46. let id = e.lastElementChild.firstElementChild.href.split('/').at(-1)
  47. let l = e.lastElementChild.appendChild(document.createElement('label'));
  48. l.innerText = 'Скрыть ';
  49. let inp = l.appendChild(document.createElement('input'));
  50. inp.type = 'checkbox';
  51. inp.setAttribute('task-id', id);
  52. if (hidden_tasks.indexOf(id) != '-1') {
  53. if (hiding)
  54. e.hidden = true;
  55. inp.checked = true;
  56. }
  57. inp.onchange = function(event) {
  58. if (event.target.checked) {
  59. hidden_tasks.push(id);
  60. if (hiding)
  61. event.target.parentElement.parentElement.parentElement.hidden = true;
  62. } else {
  63. hidden_tasks.splice(hidden_tasks.indexOf(id), 1);
  64. }
  65. GM.setValue('hidden_tasks', hidden_tasks);
  66. }
  67. });
  68. }
  69. function hide(checked) {
  70. if (checked) {
  71. $('#tableTasks tbody tr').each(function(i, e) {
  72. let id = e.lastElementChild.firstElementChild.href.split('/').at(-1);
  73. let ind = hidden_tasks.indexOf(id);
  74. if (ind != -1)
  75. e.hidden = true;
  76. });
  77. hiding = true;
  78. } else {
  79. $('tr[hidden]').each((i, e)=>{e.hidden = false});
  80. hiding = false;
  81. }
  82. GM.setValue('hiding', hiding);
  83. }
  84. })();