WorkTile交互优化

优化愚蠢的交互方式和样式,让操作更便捷更人性!

目前為 2021-11-30 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         WorkTile交互优化
// @namespace    http://fulicat.com
// @version      1.0.9
// @description  优化愚蠢的交互方式和样式,让操作更便捷更人性!
// @author       Jack.Chan
// @license MIT
// @url          https://greasyfork.org/zh-CN/scripts/436038-worktile%E4%BA%A4%E4%BA%92%E4%BC%98%E5%8C%96
// @match        https://*.worktile.com/*
// @icon         https://cdn.pingcode.com/static/portal/favicon.ico
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var $style = document.createElement('style');
    $style.type = 'text/css';
    $style.innerHTML = `
.app-nav-new-area-x,
.thy-header-self-adaption-x,
.shortcut-tray-content{
    z-index: 3000 !important;
}
.dialog-max-lg{
    width: 90% !important;
}
.task-table-next{
    padding: 16px 16px 46px 16px !important;
}

.shortcut-main{
    position: relative;
}
.shortcut-main shortcut-tray-list{
    box-shadow: 5px 0 10px 0 rgb(0 0 0 / 20%);
    background: #fafafa;
    position: fixed;
    right: 0;
    left: 108px;
    bottom: 0;
}
.shortcut-main .shortcut-list-content{
    justify-content: center;
}

.toc-section.thy-menu{
    padding-bottom: 80px;
}
mission-work-addon-group.thy-layout{
    padding-bottom: 50px;
}
mission-work-addon-group .addon-task-table-body.addon-task-table-scroll{
    bottom: 50px;
}

/* 右侧抽屉 */
.view-filter .view-filter-body{
    height: auto !important;
}
.view-filter .view-filter-footer{
    position: static !important;
}

/* 需求、任务描述 */
.textarea-show-wrapper .textarea-show-footer{
    text-align: center;
    background: #eee;
    padding: 10px;
}
.textarea-show-wrapper .textarea-show-footer a{
    padding: 10px 20px;
}
.textarea-show-body{
    position: relative;
}
.markdown-body{
    visibility: hidden;
}
.markdown-body-new{
    visibility: visible;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1;
    background: rgba(255 ,255, 255, 1);
}
.x-link{
    width: auto !important;
}

.app-nav-new-area{
    padding-top: 35px;
}
.link-open-new-window{
    position: absolute;
    top: 0;
    color: #fff;
    z-index: 99996;
    font-weight: bold;
    padding: 13px 0;
    display: block;
    width: 60px;
    text-align: center;
    background: #358fe4;
}
.link-open-new-window:hover{
    color: #fff;
    background: #ff9f73;
    background: #4caf50;
    background: #ff894e;
}
`;

    //window.localStorage.setItem('latestMissionPath', '/mission/my/following');

    function init() {
        document.createElement('shortcut-tray-list');
        document.head.appendChild($style);
    }

    function addLink(delay) {
        delay = delay || 0;
        setTimeout(function() {

            // 增加新开窗口
            var $linkOpenNewWindow = document.querySelector('.link-open-new-window');
            if (!$linkOpenNewWindow) {
                $linkOpenNewWindow = document.createElement('a');
                $linkOpenNewWindow.className = 'link-open-new-window';
                $linkOpenNewWindow.title = '打开新窗口';
                $linkOpenNewWindow.innerText = '新窗口';
                $linkOpenNewWindow.target='_blank';
                $linkOpenNewWindow.rel='opener';
                $linkOpenNewWindow.href = window.location.href;
                $linkOpenNewWindow.addEventListener('click', function(event) {
                    $linkOpenNewWindow.href = window.location.href;
                }, false);
                document.body.appendChild($linkOpenNewWindow);
            }

/*
            // 左边二级导航 增加 我参与的
            if (!document.querySelector('.body-list-new')) {
                var $bodyList = document.querySelector('.body-list');
                var $menu = $bodyList.querySelector('.thy-menu.thy-menu');
                if ($bodyList && $menu) {
                    var $node = document.createElement('div');
                    $node.style.cssText = 'border-top: 1px #e5ecfc solid;border-bottom: 1px #e5ecfc solid;';
                    $node.innerHTML = `
<a href="/mission/my/following" routerlinkactive="active" class="section-item thy-menu-item active">
	<div class="thy-menu-item-content" style="padding: 0 20px;">
		<span thymenuitemicon="" class="pl-0 thy-menu-item-icon">
			<thy-icon thyiconname="user-square-fill" class="font-size-md text-primary thy-icon-user-square-fill thy-icon">
				<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fit="" height="1em" width="1em" preserveAspectRatio="xMidYMid meet" focusable="false"><g id="uhnormal/user-square-fill" stroke-width="1" fill-rule="evenodd"><path d="M12.8 0C14.56 0 16 1.36 16 3.2v9.6c0 1.76-1.44 3.2-3.2 3.2H3.2A3.21 3.21 0 0 1 0 12.8V3.2C0 1.44 1.44 0 3.2 0zM8.053 3h-.092c-1.7 0-2.153 1.58-2.187 2.465C5.774 7.293 7 7.96 7 7.96s.152.18.152.498c0 .073-.12.22-.2.287-.699.577-3.212 1.159-3.375 2.402-.126.528-.344 1.577 1.609 1.701.687.044 1.612.177 2.865.148 4.484-.104 4.572-.62 4.403-1.83-.163-1.243-2.696-1.844-3.395-2.421-.08-.066-.126-.284-.126-.357 0-.318.077-.428.077-.428-.001.001 1.23-.667 1.23-2.495C10.205 4.58 9.678 3 8.052 3z" id="uh形状结合"></path></g></svg>
			</thy-icon>
		</span>
		<span thymenuitemname="" translate="mission.MY_TASK" class="thy-menu-item-name thy-menu-item-name-ellipsis">我参与的</span>
	</div>
</a>
`;
                    $node.addEventListener('click', function(event) {
                        event.preventDefault();
                        event.stopPropagation();
                        window.history.pushState(null, null, '/mission/my/following');
                        window.dispatchEvent(new HashChangeEvent('hashchange'));
                        return false;
                    }, false);
                    $bodyList.insertBefore($node, $menu);
                    $bodyList.classList.add('body-list-new');
                }
            }
*/

            // 弹框
            var $dialogs = document.querySelectorAll('.thy-dialog-container');
            if ($dialogs && $dialogs.length) {
                $dialogs.forEach(function($dialog) {
                    var $dialogNavSecondary = $dialog.querySelector('.thy-icon-nav-secondary');
                    if ($dialogNavSecondary) {
                        // 弹框: 在新窗口打开、复制链接
                        var $linkOpen = $dialogNavSecondary.querySelector('.x-link-open-new');
                        var $linkCopy = $dialogNavSecondary.querySelector('.x-link-copy');
                        if (!$linkOpen) {
                            $linkOpen = document.createElement('a');
                            $linkOpen.className = 'thy-icon-nav-link x-link x-link-open-new';
                            $linkOpen.target = '_blank';
                            $linkOpen.innerText = '新窗口打开';
                            $linkOpen.title = '在新窗口中打开';
                            $dialogNavSecondary.appendChild($linkOpen);

                            $linkCopy = document.createElement('a');
                            $linkCopy.className = 'thy-icon-nav-link x-link x-link-copy';
                            $linkCopy.innerText = '复制链接';
                            $linkCopy.title = '复制链接';
                            $linkCopy.addEventListener('click', function(event) {
                                event.preventDefault();
                                event.stopPropagation();
                                var $textarea = document.createElement('textarea');
                                $textarea.style.cssText = 'position:fixed;top:0;left:-500px;z-index:9999;';
                                document.body.appendChild($textarea);
                                var $projectName = $dialog.querySelector('.project-name');
                                var projectName = $projectName ? $projectName.innerText : ''
                                var $taskTitle = $dialog.querySelector('.task-title');
                                var taskTitle = $taskTitle ? $taskTitle.innerText : '';
                                var value = `【${projectName}】 - ${taskTitle}\r\n${window.location.href}`;
                                $textarea.value = value;
                                $textarea.select();
                                document.execCommand('Copy');
                                $linkCopy.innerText = '复制成功';
                                setTimeout(function() {
                                    $linkCopy.innerText = '复制链接';
                                    document.body.removeChild($textarea);
                                }, 1500);
                                return false;
                            }, false);
                            $dialogNavSecondary.appendChild($linkCopy);

                        }
                        $linkOpen.href = window.location.href;
                        $linkCopy.href = window.location.href;

                        // 弹框:需求/任务 描述 编辑、复制
                        if (!$dialog.querySelector('.markdown-body-new')) {
                            var $markdownBody = $dialog.querySelector('.markdown-body');
                            if ($markdownBody && $markdownBody.parentNode) {
                                var $markdownBodyParent = $markdownBody.parentNode;
                                var $newMarkdownBody = $markdownBody.cloneNode(true);
                                $newMarkdownBody.classList.add('markdown-body-new');
                                $markdownBodyParent.appendChild($newMarkdownBody, $markdownBody);

                                var syncDescHandler = function(event) {
                                    setTimeout(function() {
                                        $newMarkdownBody.innerHTML = $markdownBody.innerHTML;
                                    }, 300);
                                }

                                $dialog.addEventListener('mousedown', function(event) {
                                    var $btns = $dialog.querySelectorAll('field-item-textarea-show-edit .thy-btn')
                                    $btns.forEach(function($btn) {
                                        $btn.removeEventListener('mouseup', syncDescHandler, false);
                                        $btn.addEventListener('mouseup', syncDescHandler, false);
                                    });
                                }, false);

                                $newMarkdownBody.addEventListener('dblclick', function(event) {
                                    $markdownBodyParent.classList.toggle('textarea-show-body-collapse');
                                    return false
                                }, false);

                             }
                        }

                    }
                })
            }
        }, delay);
    }

    init();

    document.body.addEventListener('mousedown', function(e) {
        addLink(500);
    }, false);

    addLink(1500);
})();