Skip to content

Commit 7f42784

Browse files
Merge pull request #222 from DavidCurtiss/master
Fix PR image URLs to match the window URL
2 parents 7efb1ab + cd5f07c commit 7f42784

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

src/azdo-pr-dashboard.user.js

+30-3
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
@@ -24,8 +24,8 @@
2424
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/sweetalert2.all.min.js#sha384-8oDwN6wixJL8kVeuALUvK2VlyyQlpEEN5lg6bG26x2lvYQ1HWAV0k8e2OwiWIX8X
2525
// @require https://gist.githubusercontent.com/alejandro5042/af2ee5b0ad92b271cd2c71615a05da2c/raw/45da85567e48c814610f1627148feb063b873905/easy-userscripts.js#sha384-t7v/Pk2+HNbUjKwXkvcRQIMtDEHSH9w0xYtq5YdHnbYKIV7Jts9fSZpZq+ESYE4v
2626

27-
// @require https://unpkg.com/@popperjs/core@2#sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB
28-
// @require https://unpkg.com/tippy.js@6#sha384-AiTRpehQ7zqeua0Ypfa6Q4ki/ddhczZxrKtiQbTQUlJIhBkTeyoZP9/W/5ulFt29
27+
// @require https://unpkg.com/@popperjs/core@2.11.7#sha384-zYPOMqeu1DAVkHiLqWBUTcbYfZ8osu1Nd6Z89ify25QV9guujx43ITvfi12/QExE
28+
// @require https://unpkg.com/tippy.js@6.3.7#sha384-AiTRpehQ7zqeua0Ypfa6Q4ki/ddhczZxrKtiQbTQUlJIhBkTeyoZP9/W/5ulFt29
2929

3030
// @require https://highlightjs.org/static/highlight.min.js
3131
// @require https://cdnjs.cloudflare.com/ajax/libs/js-yaml/3.14.0/js-yaml.min.js#sha512-ia9gcZkLHA+lkNST5XlseHz/No5++YBneMsDp1IZRJSbi1YqQvBeskJuG1kR+PH1w7E0bFgEZegcj0EwpXQnww==
@@ -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)