// ==UserScript== // @name Bitbucket Enhanced +3 // @namespace https://greasyfork.org/en/scripts/458896 // @homepageURL https://gist.github.com/raveren/3bd55656272143f667e9cfd7e7171c52 // @license MIT // @version 2.0 // @author raveren // @description Changes page titles to be informative, makes branch name click to copy, and links PHPStorm from diff line (requires IDE Remote Control plugin https://plugins.jetbrains.com/plugin/19991) // @match https://bitbucket.org/* // @run-at document-start // @connect localhost // @grant GM_xmlhttpRequest // @downloadURL none // ==/UserScript== (function () { 'use strict'; window.addEventListener('load', function () { let fixTitle = function () { if (location.href.match(/\/pull-requests\/$/)) { document.title = 'All Pull Requests'; } else { document.title = document.title.replace(/[\w-]+ \/ [\w-]+ \/ Pull Request #/, '#'); document.title = document.title.replace(/Feature\/\w+ \d* /, ''); } }; fixTitle(); setInterval(fixTitle, 5000) const ideLink = 'http://localhost:63342/api/file/'; const icon = ''; // small monitor icon when hovering on line number to go to IDE $(document).on('mouseover', 'a.line-number-permalink', function (e) { if ($(this).data('ravLoaded')) { return } $(this).data('ravLoaded', 1) let link = $(this).prop('href').replace(/.*#chg_/, '') let href = ideLink + link.replace(/_newline/, ':').replace(/_oldline/, ':') let span = document.createElement('span'); span.innerHTML = `${icon} `; span.title = 'Open in PHPStorm' $(this).before(span); }); // in overview tab $(document).on('mouseover', '[data-qa="pull-request-overview-activity-content"] .line-number', function (e) { let el = $(this); if (el.data('ravLoaded')) { return } el.data('ravLoaded', 1) //
let src = el.closest('.lines-wrapper').find('[data-qa="code-line-permalink"]').prop('id'); let path = src.replace(/^L/, '').replace(/[FT]\d+$/, '') let line = src.match(/\d+$/, '') let href = ideLink + path + ':' + line; let span = document.createElement('span'); span.innerHTML = ` ${icon}`; span.title = 'Open in PHPStorm' el.append(span); }); $(document).on('click', 'a.rav-js-ide-link', function (e) { e.preventDefault() GM_xmlhttpRequest({ method: 'GET', url: this.href, }) return false }) let addTopBranch = function () { if ($('.rav-js-top-branch').length) { return; } // 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') .eq(0) .text() .replace(/^Branch: /, ''); const css = '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%)' if (branchName) { $(`