1
- function getTabs ( )
2
- {
3
- chrome . tabs . query ( { currentWindow : true , active : true } , doThingWithTabs ) ;
4
- }
1
+ window . onload = ( event ) => {
2
+ // Gets the current tabs
3
+ chrome . tabs . query ( { currentWindow : true , active : true } , getAdoLink ) ;
4
+ } ;
5
5
6
- function doThingWithTabs ( tabs )
6
+ function getAdoLink ( tabs )
7
7
{
8
+ // Check the URL of the current tab to see if it's a MUX GitHub URL
8
9
let fullUrl = tabs [ 0 ] . url ;
9
10
if ( isValidUrl ( fullUrl ) )
10
11
{
@@ -14,40 +15,35 @@ function doThingWithTabs(tabs)
14
15
// Create link with search URL
15
16
document . getElementById ( "content" ) . innerHTML =
16
17
"<a href='" + searchUrl + "' "
17
- + "target='_blank' rel='noopener' " // Opens link in new tab
18
- + "title='Open ADO link in new tab'>Link</a>" ;
18
+ + "target='_blank' rel='noopener' " // Opens link in new tab
19
+ + "title='Open ADO link in new tab' " // Hover text
20
+ + ">ADO Link</a>" ; // Display text
19
21
}
20
22
else
21
23
{
22
- //document.write("Not a WinUI GitHub page");
23
24
document . getElementById ( "content" ) . innerHTML = "Not a WinUI GitHub page" ;
24
25
}
25
26
}
26
27
27
28
function isValidUrl ( fullUrl )
28
29
{
29
- let firstPart = "https://github.com/microsoft/microsoft-ui-xaml/ issues/" ;
30
- let isValid = ( fullUrl . startsWith ( firstPart ) ) ? true : false ;
31
- return isValid ;
30
+ // Leave out ending slash so the full list of issues (no number) is considered valid
31
+ let firstPart = "https://github.com/microsoft/microsoft-ui-xaml/issues" ;
32
+ return fullUrl . startsWith ( firstPart ) ;
32
33
}
33
34
34
35
function getGithubNumberFromUrl ( fullUrl )
35
36
{
36
- let number ;
37
37
let firstPart = "https://github.com/microsoft/microsoft-ui-xaml/issues/" ;
38
- let len = firstPart . length ;
39
- number = fullUrl . substring ( len ) ;
40
- return number ;
38
+ return fullUrl . substring ( firstPart . length ) ;
41
39
}
42
40
43
41
function createAdoSearchUrl ( githubNumber )
44
42
{
45
43
let urlStart = "https://microsoft.visualstudio.com/OS/_search?" ;
46
- let searchTest = "text=https%3A//github.com/microsoft/microsoft-ui-xaml/issues/" ;
47
- // github item number goes here
44
+ let searchText = "text=https%3A//github.com/microsoft/microsoft-ui-xaml/issues/" ;
45
+ // github item number goes here (if there is one, otherwise we return a query for all the MUX GitHub issues)
48
46
let itemType = "&type=workitem&lp=workitems-Project" ;
49
- let searchUrl = urlStart + searchTest + githubNumber + itemType ;
47
+ let searchUrl = urlStart + searchText + githubNumber + itemType ;
50
48
return searchUrl ;
51
49
}
52
-
53
- document . getElementById ( "linkButton" ) . addEventListener ( "click" , getTabs ) ;
0 commit comments