Skip to content

Commit c15eb87

Browse files
committed
Fix PR image URLs to match the window URL
When an image is embedded in a PR description, the image URL needs to match the window URL (whether dev.azure.com/org/ or org.visualstudio.com/), or the image won't show up. This change watches for all new img tags and fixes the URL if needed.
1 parent 7efb1ab commit c15eb87

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/azdo-pr-dashboard.user.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22

33
// @name More Awesome Azure DevOps (userscript)
4-
// @version 3.5.3
4+
// @version 3.6.0
55
// @author Alejandro Barreto (NI)
66
// @description Makes general improvements to the Azure DevOps experience, particularly around pull requests. Also contains workflow improvements for NI engineers.
77
// @license MIT
@@ -132,6 +132,7 @@
132132
watchForStatusCardAndMoveToRightSideBar(session);
133133
addEditButtons(session);
134134
addTrophiesToPullRequest(session, pageData);
135+
fixImageUrls(session);
135136
});
136137

137138
eus.onUrl(/\/(agentqueues|agentpools)(\?|\/)/gi, (session, urlMatch) => {
@@ -2185,6 +2186,32 @@
21852186
}
21862187
}
21872188

2189+
// Fix PR image URLs to match the window URL (whether dev.azure.com/account/ or account.visualstudio.com/)
2190+
function fixImageUrls(session) {
2191+
let account;
2192+
let badPrefix;
2193+
let goodPrefix;
2194+
if (window.location.host === 'dev.azure.com') {
2195+
account = window.location.pathname.match(/^\/(\w+)/)[1];
2196+
badPrefix = new RegExp(`^${window.location.protocol}//${account}.visualstudio.com/`);
2197+
goodPrefix = `${window.location.protocol}//dev.azure.com/${account}/`;
2198+
} else {
2199+
const match = window.location.host.match(/^(\w+)\.visualstudio.com/);
2200+
if (!match) return;
2201+
account = match[1];
2202+
badPrefix = new RegExp(`^${window.location.protocol}//dev.azure.com/${account}/`);
2203+
goodPrefix = `${window.location.protocol}//${account}.visualstudio.com/`;
2204+
}
2205+
2206+
session.onEveryNew(document, 'img', img => {
2207+
const src = img.getAttribute('src');
2208+
if (src && src.match(badPrefix)) {
2209+
// For debugging: debug("Fixing img src", src);
2210+
img.setAttribute('src', src.replace(badPrefix, goodPrefix));
2211+
}
2212+
});
2213+
}
2214+
21882215
// Helper function to get the file extension out of a file path; e.g. `cs` from `blah.cs`.
21892216
function getFileExt(path) {
21902217
return /(?:\.([^.]+))?$/.exec(path)[1];

0 commit comments

Comments
 (0)