🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Toggl-Button TeamWork

Toggle button for TeamWork

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name        Toggl-Button TeamWork
// @namespace   https://gitlab.paragon-es.de/toggl-button
// @version     1.2
// @include     http*://*.teamwork.com/*
// @grant       GM_xmlhttpRequest
// @grant       GM_addStyle
// @grant       GM_getResourceText
// @grant       GM_getValue
// @grant       GM_setValue
// @grant       GM_info
// @grant       GM_registerMenuCommand
// @require     https://greasyfork.org/scripts/2670-toggllibrary/code/TogglLibrary.js
// @resource    togglStyle https://gitlab.paragon-es.de/toggl-button/core/raw/master/TogglLibrary.css
// @description Toggle button for TeamWork
// ==/UserScript==

var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver,
  target = document.querySelector('#mainContent'),
  bodyTarget = document.querySelector('body'),
  stopTB, stopProcessed,
  config = { attributes: true, childList: true, characterData: true },
  observer = new MutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
      if (mutation.type === 'childList') {
        // TODO: if none of the mutations is a task, then remove the toggle element if visible.
        var task = document.querySelector('#Task');
        if (task !== null) {
          var tb = new TogglButtonGM('#Task', function (elem) {
            var taskDetail = document.querySelector('.taskDetailHolder');
            if (taskDetail !== null) {
              var taskID = taskDetail.id.substr(13),
                taskDetailTarget = taskDetail.querySelector('div'),
                taskDetailProcessed = false,
                innerObserver = new MutationObserver(function (mutations) {
                  mutations.forEach(function (mutation) {
                    if (mutation.type === 'childList' && !taskDetailProcessed) {
                      var titleElem = document.querySelector('.taskDetailsName span');
                      if (titleElem !== null) {
                        innerObserver.disconnect();
                        taskDetailProcessed = true;
                        var tb = new TogglButtonGM('#Task', function (elem) {
                          var description, projectIds = [],
                            projectElem = document.querySelector('#projectName'),
                            linkElem = document.querySelector('#ViewTaskSidebar .blue2.ql');

                          description = taskID + " " + titleElem.textContent.trim();

                          if (projectElem !== null) {
                            projectIds.push(projectElem.textContent.trim());
                          }
                          if (linkElem !== null) {
                            projectIds.push(linkElem.textContent.trim());
                          }

                          return {
                            className: 'teamwork',
                            description: description,
                            projectIds: projectIds
                          };
                        });

                        document.querySelector('.startTimer button').addEventListener('click', function () {
                          tb.clickLinks();
                        });
                      }
                    }
                  });
                });
              innerObserver.observe(taskDetailTarget, config);
            }
          });
        }
      }
    });
  }),
  bodyObserver = new MutationObserver(function (mutations) {
    if (stopTB == null) {
      stopTB = new TogglButtonGM();
      stopProcessed = false;
    }
    mutations.forEach(function (mutation) {
      if (mutation.type === 'childList') {
        var stopElem = document.querySelector('#timerBar');
        if (stopElem !== null && !stopProcessed) {
          stopProcessed = true;
          stopElem.querySelector('.timer-log-time, .timer-body .btn-success').addEventListener('click', function () {
            stopTB.stopTimeEntry();
          });
        }
      }
    });
  });

observer.observe(target, config);
bodyObserver.observe(bodyTarget, config);