diff --git a/README.md b/README.md index f1032e25c3cbd7925b2ccae57095b8acd36bc7ac..d3024fd4ffe01b8963ef5982ea7d8dbab929c53a 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,8 @@ Once Greasemonkey is installed, you can either add user scripts from GitHub or t ### How to install from GitLab +IMPORTANT: The links to raw files are currently not working due to a bug in GitLab. Please move on to the next chapter and use the links from **Greasy Fork** ! + Just open one of the PLATFORM.user.js files and then click on "Raw". Your Firefox browser should tell you that you're opening a Greasemonkey user script and provides an option "Install" which you should then click. The direct links are: @@ -103,9 +105,7 @@ However, you can adjust their scope by individually defining the list of domains ## Useful links * [Greasy Fork][17] -* [User Scripts][14] * [Toggl Button Greasy Fork][3] -* [Toggl Button User Scripts][1] * [Greasemonkey Homepage][15] * [Greasemonkey AddOn][11] * [Other browser support][12] @@ -136,14 +136,12 @@ As the author of this set of scripts I do disclose that I am **in no way** assoc This also means, that the scripts here are in no way *official products* of Toggl and therefore not supported by Toggl or their associates. -[1]: http://userscripts.org:8080/tags/toggl [2]: https://gitlab.paragon-es.de/toggl-button/core/merge_requests [3]: https://greasyfork.org/scripts/search?q=toggl -[10]: https://new.toggl.com +[10]: https://www.toggl.com [11]: https://addons.mozilla.org/en-US/firefox/addon/greasemonkey [12]: http://wiki.greasespot.net/Cross-browser_userscripting [13]: https://github.com/toggl/toggl-button -[14]: http://userscripts.org:8080 [15]: http://www.greasespot.net [16]: https://github.com/toggl/toggl_api_docs [17]: https://greasyfork.org diff --git a/TogglLibrary.css b/TogglLibrary.css index 8d372d3b08e73ab11253d777bb013d4d044a5904..246b1cc8e73d297fab220a43d9505f0a06f75d31 100644 --- a/TogglLibrary.css +++ b/TogglLibrary.css @@ -61,7 +61,7 @@ position: fixed; bottom: 10px; left: 10px; - z-index: 999; + z-index: 1001; padding: 0; border: 1px solid #999999; -moz-box-shadow: 0 0 5px 5px #888; @@ -141,7 +141,10 @@ text-decoration: underline; } -/* Special positioning on TeamWork */ -body#tasks #toggl-button-wrapper { - bottom: 40px; +/* Special: TeamWork */ +body#tasks .startTimer { + display: none; +} +body#tasks .btn.harvest-timer { + display: none; } diff --git a/TogglLibrary.js b/TogglLibrary.js index a6c699da6205c491f4bc78253174628dd4a8152f..780fd05e274043ba2926946501a8479605c37d5b 100644 --- a/TogglLibrary.js +++ b/TogglLibrary.js @@ -16,6 +16,7 @@ function TogglButtonGM(selector, renderer) { $newApiUrl = "https://www.toggl.com/api/v8", $legacyApiUrl = "https://new.toggl.com/api/v8", $triedAlternative = false, + $addedDynamicListener = false, $api_token = null, $default_wid = null, $clientMap = {}, @@ -119,34 +120,48 @@ function TogglButtonGM(selector, renderer) { if (selector == null) { return; } - var i, len, elems = document.querySelectorAll(selector); + var i, len, elems = document.querySelectorAll(selector + ':not(.toggl)'); for (i = 0, len = elems.length; i < len; i += 1) { elems[i].classList.add('toggl'); $instances[i] = new TogglButtonGMInstance(renderer(elems[i])); } - document.addEventListener('TogglButtonGMUpdateStatus', function() { - GM_xmlhttpRequest({ - method: "GET", - url: $activeApiUrl + "/time_entries/current", - headers: { - "Authorization": "Basic " + btoa($api_token + ':api_token') - }, - onload: function (result) { - if (result.status === 200) { - var resp = JSON.parse(result.responseText), - data = resp.data || false; - if (data) { - for (i in $instances) { - $instances[i].checkCurrentLinkStatus(data); + + if (!$addedDynamicListener) { + $addedDynamicListener = true; + + document.addEventListener('TogglButtonGMUpdateStatus', function() { + GM_xmlhttpRequest({ + method: "GET", + url: $activeApiUrl + "/time_entries/current", + headers: { + "Authorization": "Basic " + btoa($api_token + ':api_token') + }, + onload: function (result) { + if (result.status === 200) { + var resp = JSON.parse(result.responseText), + data = resp.data || false; + if (data) { + for (i in $instances) { + $instances[i].checkCurrentLinkStatus(data); + } } } } - } + }); }); - }); - window.addEventListener('focus', function() { - document.dispatchEvent(new CustomEvent('TogglButtonGMUpdateStatus')); - }); + + window.addEventListener('focus', function() { + document.dispatchEvent(new CustomEvent('TogglButtonGMUpdateStatus')); + }); + + if (selector !== 'body') { + document.body.addEventListener('DOMSubtreeModified', function () { + setTimeout(function () { + render(selector, renderer); + }, 1000); + }); + } + } } this.clickLinks = function() { @@ -341,13 +356,24 @@ function TogglButtonGM(selector, renderer) { document.querySelector('body').classList.add('toggl-button-available'); if (params.targetSelectors == undefined) { - var wrapper = document.createElement('div'), + var wrapper, + existingWrapper = document.querySelectorAll('#toggl-button-wrapper'), content = createTag('div', 'content'); - wrapper.id = 'toggl-button-wrapper'; content.appendChild($link); content.appendChild(createProjectSelect()); - wrapper.appendChild(content); - document.querySelector('body').appendChild(wrapper); + if (existingWrapper.length > 0) { + wrapper = existingWrapper[0]; + while (wrapper.firstChild) { + wrapper.removeChild(wrapper.firstChild); + } + wrapper.appendChild(content); + } + else { + wrapper = document.createElement('div'); + wrapper.id = 'toggl-button-wrapper'; + wrapper.appendChild(content); + document.querySelector('body').appendChild(wrapper); + } } else { var elem = params.targetSelectors.context || document; if (params.targetSelectors.link != undefined) {