ECU Bitbucket Improvements

Changes page titles to be informative, makes branch name click to copy, and links PHPStorm from diff line

As of 28.01.2025. See апошняя версія.

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 or Violentmonkey 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.

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        ECU Bitbucket Improvements
// @namespace   https://greatest.deepsurf.us/en/scripts/458896
// @homepageURL https://gist.github.com/raveren/3bd55656272143f667e9cfd7e7171c52
// @license     MIT
// @version     1.4.0
// @author      raveren
// @description Changes page titles to be informative, makes branch name click to copy, and links PHPStorm from diff line
// @match       https://bitbucket.org/ecu1/internal-www/pull-requests*
// @match       https://bitbucket.org/ecu1/backend-api/pull-requests*
// @run-at      document-start
// @connect     localhost
// @grant       GM_xmlhttpRequest
// ==/UserScript==

(function () {
    'use strict';

    window.addEventListener('load', function () {
        if (location.href === 'https://bitbucket.org/ecu1/internal-www/pull-requests/') {
            document.title = 'All Pull Requests';
        } else {
            document.title = document.title.replace('ecu1 / internal-www / Pull Request #', '');
            document.title = document.title.replace(/Feature\/\w+ \d* /, '');
        }


        // small monitor icon when hovering on line number to go to IDE
        $(document).on('mouseover', 'a.line-number-permalink', function (e) {
            if ($(this).data('ecu-loaded')) {
                return
            }
            $(this).data('ecu-loaded', 1)

            // https://bitbucket.org/ecu1/internal-www/pull-requests/1373#chg_app/Modules/blablabla.php_newline81
            let link = $(this).prop('href').replace(/.*#chg_/, '')
            let path = link.replace(/_newline/, ':')


            let a = document.createElement('span');
            a.innerHTML = '<a class="asd" href="http://localhost:63342/api/file/' + path + '"><svg width="8px" height="8px" version="1.1" viewBox="0 0 2.1024 2.1186" xmlns="http://www.w3.org/2000/svg"><g transform="translate(-1.1725 -.99595)"><path d="m1.1743 1.2677 1.8282-7.437e-4 0.00146 1.8455m-1.6398-0.18919 1.6423-1.6446" stroke="#000" stroke-width=".54173"/></g></svg></a>';
            a.onclick = 'return false'
            a.title = 'Open in PHPStorm'
            $(this).before(a);
        });

        $(document).on('click', 'a.asd', function (e) {
            e.preventDefault()

            GM_xmlhttpRequest({
                method: 'GET',
                url: this.href,
            })

            return false
        })

        // make branch name stand out a little and click to copy
        const branchName = $('div[data-qa="pr-branches-and-state-styles"] > div:first-child > div:first-child > span:first-child > span:first-child')
            .text()
            .replace(/^Branch: /, '');

        if (branchName) {
            $('<div style="position: fixed;top: 0;z-index: 9999;margin: 0 auto;width: 100%;text-align: center;cursor: pointer;font-weight: bold;color: darkred;background:linear-gradient(90deg,rgba(255, 0, 0, 1) 0%,rgba(255, 154, 0, 1) 10%,rgba(208, 222, 33, 1) 20%,rgba(79, 220, 74, 1) 30%,rgba(63, 218, 216, 1) 40%,rgba(47, 201, 226, 1) 50%,rgba(28, 127, 238, 1) 60%,rgba(95, 21, 242, 1) 70%,rgba(186, 12, 248, 1) 80%,rgba(251, 7, 217, 1) 90%,rgba(255, 0, 0, 1) 100%)">' + branchName + '</div>')
                .appendTo(document.body)
                .prop('title', 'click to copy')
                .on('click', function () {
                    navigator.clipboard.writeText($(this).text())
                    $(this).append('<span><svg width="16" height="16" viewBox="0 0 24 24" role="presentation"><g fill-rule="evenodd"><circle fill="green" cx="12" cy="12" r="10"></circle><path d="M9.707 11.293a1 1 0 10-1.414 1.414l2 2a1 1 0 001.414 0l4-4a1 1 0 10-1.414-1.414L11 12.586l-1.293-1.293z" fill="inherit"></path></g></svg> Copied</span>');
                    $(this).find('span').fadeOut(1000, function () {
                        $(this).remove()
                    })
                })
        }
    });
})();