SUAI hide tasks

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

当前为 2021-12-12 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         SUAI hide tasks
// @namespace    http://tampermonkey.net/
// @version      0.1.2
// @description  Добавляет чекбокс для скрытия заданий в лк гуапа
// @author       goodhumored
// @license      MIT
// @match        https://pro.guap.ru/inside_s
// @icon         https://www.google.com/s2/favicons?domain=guap.ru
// @grant        GM.setValue
// @grant        GM.getValue
// @run-at       document-end
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
// ==/UserScript==

(function() {
    'use strict';
    var hidden_tasks = [];
    var hiding = true;
    var interval = setInterval(async function() {
        if ($('.panel-body').length > 1) {
            hidden_tasks = await GM.getValue('hidden_tasks', []);
            hiding = await GM.getValue('hiding', true);
            let row = $('.panel-body')[0].appendChild(document.createElement('div'));
            row.className = 'row';
            let cm3 = row.appendChild(document.createElement('div'));
            cm3.className = 'col-md-3';
            let fg = cm3.appendChild(document.createElement('div'));
            fg.className = 'form-group';
            let label = fg.appendChild(document.createElement('label'));
            label.innerText = 'Скрывать помеченные задания ';
            let hideC = label.appendChild(document.createElement('input'));
            hideC.type = 'checkbox';
            hideC.onchange = (event) => hide(event.target.checked);
            hideC.checked = hiding;
            add_checkboxes();
            let c = $('[name=tableTasks_length]')[0];
            $('[name=tableTasks_length]').change((event) => {GM.setValue('show_count', event.target.value); add_checkboxes();})
            c.value = await GM.getValue('show_count', 15);
            c.dispatchEvent(new Event('change'));
            clearInterval(interval);
        }
    }, 3000);
    function add_checkboxes() {
        $('#tableTasks tbody tr').each(function(i, e) {
            let id = e.lastElementChild.firstElementChild.href.split('/').at(-1)
            let l = e.lastElementChild.appendChild(document.createElement('label'));
            l.innerText = 'Скрыть ';
            let inp = l.appendChild(document.createElement('input'));
            inp.type = 'checkbox';
            inp.setAttribute('task-id', id);
            if (hidden_tasks.indexOf(id) != '-1') {
                if (hiding)
                    e.hidden = true;
                inp.checked = true;
            }
            inp.onchange = function(event) {
                if (event.target.checked) {
                    hidden_tasks.push(id);
                    if (hiding)
                        event.target.parentElement.parentElement.parentElement.hidden = true;
                } else {
                    hidden_tasks.splice(hidden_tasks.indexOf(id), 1);
                }
                GM.setValue('hidden_tasks', hidden_tasks);
            }
        });
    }
    function hide(checked) {
        if (checked) {
            $('#tableTasks tbody tr').each(function(i, e) {
                let id = e.lastElementChild.firstElementChild.href.split('/').at(-1);
                let ind = hidden_tasks.indexOf(id);
                if (ind != -1)
                    e.hidden = true;
            });
            hiding = true;
        } else {
            $('tr[hidden]').each((i, e)=>{e.hidden = false});
            hiding = false;
        }
        GM.setValue('hiding', hiding);
    }
})();