From f94eecee3111a23dd51b36b2754cc6a5f070b71c Mon Sep 17 00:00:00 2001 From: Andrei Rybak Date: Thu, 25 Jul 2024 21:03:25 +0200 Subject: [PATCH] bitbucket-copy-commit-reference: make selectors more robust Fix functions getFullHash and wrapButton, which broke due to a change in HTML layout of Bitbucket Cloud. Make the selectors more robust by removing dependencies on mangled CSS class names. --- bitbucket-copy-commit-reference.user.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bitbucket-copy-commit-reference.user.js b/bitbucket-copy-commit-reference.user.js index 7275ca1..587a12b 100644 --- a/bitbucket-copy-commit-reference.user.js +++ b/bitbucket-copy-commit-reference.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Bitbucket: copy commit reference // @namespace https://github.com/rybak/atlassian-tweaks -// @version 8 +// @version 9 // @description Adds a "Copy commit reference" link to every commit page on Bitbucket Cloud and Bitbucket Server. // @license AGPL-3.0-only // @author Andrei Rybak @@ -99,7 +99,7 @@ /* * "View source" button on the right. */ - const a = document.querySelector('div.css-1oy5iav a.css-1luyhz2'); + const a = document.querySelector('#root [data-testid="settingsButton"]')?.parentNode.querySelector('a'); const href = a.getAttribute('href'); debug("BitbucketCloud:", href); return href.slice(-41, -1); @@ -136,10 +136,11 @@ wrapButton(button) { try { const icon = document.querySelector('[aria-label="copy commit hash"] svg').cloneNode(true); - icon.classList.add('css-bwxjrz', 'css-snhnyn'); + icon.classList.add('css-bwxjrz', 'css-snhnyn'); // same classes as s inside "Approve" button const buttonText = this.getButtonText(); button.replaceChildren(icon, document.createTextNode(` ${buttonText}`)); - button.classList.add('css-1luyhz2'); + const settingsButton = document.querySelector('#root [data-testid="settingsButton"]'); + button.classList.add(settingsButton.classList); } catch (e) { warn('BitbucketCloud: cannot find icon of "copy commit hash"'); }