Refresh Button for Dashboard

Adds button that reloads all widgets on a dashboard.

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

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

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

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

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

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

// ==UserScript==
// @name         Refresh Button for Dashboard
// @author       Qteb
// @match        https://*.myjetbrains.com/youtrack/dashboard*
// @description  Adds button that reloads all widgets on a dashboard.
// @version 0.0.1.20170302134951
// @namespace https://greasyfork.org/users/106502
// ==/UserScript==

function refreshWidgets() {
    console.log('Updating...');
    $('div[react-value-glyph="#refresh"]').each( function() {
        $(this).click();
    });
}

(function() {
    'use strict';

    var vis = (function(){
        var stateKey, eventKey, keys = {
            hidden: "visibilitychange",
            webkitHidden: "webkitvisibilitychange",
            mozHidden: "mozvisibilitychange",
            msHidden: "msvisibilitychange"
        };
        for (stateKey in keys) {
            if (stateKey in document) {
                eventKey = keys[stateKey];
                break;
            }
        }
        return function(c) {
            if (c) document.addEventListener(eventKey, c);
            return !document[stateKey];
        };
    })();

    vis(function(){
        if(vis()) {
            refreshWidgets();
        }
    });

    // add refresh button
    setTimeout(function () {
        // while button does not exists
        while ($('.ring-button__content:contains("Reload All")').text().length === 0) {
            $('.dashboard-page__toolbar-buttons')
                .prepend($('<button>').addClass("ring-button ring-button_default reloadAll")
                         .prepend($('<span>').addClass("ring-button__content")
                                  .prepend($('<span>').text('Reload All'))));
        }
        // click refresh button action
        $('.ring-button__content:contains("Reload All")').click(function () {
            refreshWidgets();
        });
    }, 1000);
})();