Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional redirect from *.visualstudio.com to dev.azure.com/* #226

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/azdo-pr-dashboard.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==

// @name More Awesome Azure DevOps (userscript)
// @version 3.6.0
// @version 3.6.1
// @author Alejandro Barreto (NI)
// @description Makes general improvements to the Azure DevOps experience, particularly around pull requests. Also contains workflow improvements for NI engineers.
// @license MIT
Expand All @@ -16,6 +16,7 @@
// @include https://*.visualstudio.com/*

// @run-at document-body
// @run-at document-start
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you specify two run-at statements? Does the 2nd one take priority?

// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js#sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery-once/2.2.3/jquery.once.min.js#sha256-HaeXVMzafCQfVtWoLtN3wzhLWNs8cY2cH9OIQ8R9jfM=
// @require https://cdnjs.cloudflare.com/ajax/libs/date-fns/1.30.1/date_fns.min.js#sha256-wCBClaCr6pJ7sGU5kfb3gQMOOcIZNzaWpWcj/lD9Vfk=
Expand Down Expand Up @@ -90,14 +91,30 @@
`);
}

eus.registerCssClassConfig(document.body, 'Redirect visualstudio.com to dev.azure.com', 'visualstudio-redirect', 'visualstudio-redirect-off', {
'visualstudio-redirect-on': 'On',
'visualstudio-redirect-off': 'Off',
});

// Start modifying the page once the DOM is ready.
if (document.readyState !== 'loading') {
onReady();
} else {
onStart();
document.addEventListener('DOMContentLoaded', onReady);
}
}

function onStart() {
const host = window.location.host;
if (document.body.classList.contains('visualstudio-redirect-on') && host.endsWith('.visualstudio.com')) {
// Redirect to dev.azure.com if the user has enabled that option
window.stop();
const subDomain = host.split('.')[0];
window.location.href = window.location.href.replace(host, `dev.azure.com/${subDomain}`);
}
}

function onReady() {
// Find out who is our current user. In general, we should avoid using pageData because it doesn't always get updated when moving between page-to-page in AzDO's single-page application flow. Instead, rely on the AzDO REST APIs to get information from stuff you find on the page or the URL. Some things are OK to get from pageData; e.g. stuff like the user which is available on all pages.
const pageData = JSON.parse(document.getElementById('dataProviders').innerHTML).data;
Expand Down