Jira: Project icon as tab icon

Changes browser tab icon to Jira project icon

Installa questo script?
Script suggerito dall'autore

Potresti essere interessato/a anche a Bitbucket: PR author avatar as favicon

Installa questo script
  1. // ==UserScript==
  2. // @name Jira: Project icon as tab icon
  3. // @namespace https://github.com/rybak/atlassian-tweaks
  4. // @version 6
  5. // @license MIT
  6. // @description Changes browser tab icon to Jira project icon
  7. // @author Sergey Lukashevich
  8. // @include https://*jira*/*
  9. // @match https://jira.example.com/*
  10. // @icon https://jira.atlassian.com/favicon.ico
  11. // @homepageURL https://github.com/rybak/atlassian-tweaks
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. /*
  16. * Copyright (c) 2022-2023 Sergey Lukashevich
  17. *
  18. * Permission is hereby granted, free of charge, to any person obtaining a copy
  19. * of this software and associated documentation files (the "Software"), to deal
  20. * in the Software without restriction, including without limitation the rights
  21. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  22. * copies of the Software, and to permit persons to whom the Software is
  23. * furnished to do so, subject to the following conditions:
  24. *
  25. * The above copyright notice and this permission notice shall be included in all
  26. * copies or substantial portions of the Software.
  27. *
  28. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  29. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  30. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  31. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  32. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  33. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  34. * SOFTWARE.
  35. */
  36.  
  37. (function() {
  38. 'use strict';
  39.  
  40. let projectAvatar = document.getElementById('project-avatar');
  41. let url = null;
  42. if (!projectAvatar) {
  43. let elements = document.getElementsByClassName('aui-avatar-project');
  44. if (elements.length === 1) {
  45. let byTagName = elements[0].getElementsByTagName('img');
  46. if (byTagName.length === 1) {
  47. projectAvatar = byTagName[0];
  48. }
  49. }
  50. }
  51. if (projectAvatar) {
  52. url = projectAvatar.src;
  53. } else {
  54. // try layout as in the cloud version of Jira Software
  55. projectAvatar = document.querySelector('div[data-navheader="true"] span[style*=background]');
  56. if (projectAvatar) {
  57. const bgImage = projectAvatar.style.getPropertyValue("background-image");
  58. url = bgImage.slice(5, bgImage.length - 7); // cut out the URL from CSS code `url('...');`
  59. }
  60. }
  61.  
  62. let shortcutIco = document.querySelector('link[rel="shortcut icon"]');
  63.  
  64. if (url && shortcutIco) {
  65. shortcutIco.href = url;
  66. }
  67. })();