Skip to content

Commit a78aba8

Browse files
committed
update to work with new github structure
1 parent f0a0609 commit a78aba8

File tree

2 files changed

+28
-42
lines changed

2 files changed

+28
-42
lines changed

CHANGES.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,11 @@
197197
</style>
198198
<div class="legend"><details><summary>Legend</summary><div><added></added>Added<br><changed></changed>Changed<br><fixed></fixed>Fixed<br><removed></removed>Removed</div></details></div>
199199
<h1 id="changeslog">Changes Log</h1>
200-
<p><strong><a href="https://github.com/vanowm/userscript_github-open_with_vscode/commit/2a06b17">23.10.28-125044</a></strong> <date>(2023-10-28 12:33:19)</date></p>
200+
<p><strong><a href="https://github.com/vanowm/userscript_github-open_with_vscode/commit/39a1877">24.5.9-085044</a></strong> <date>(2024-05-09 08:54:10)</date></p>
201+
<ul>
202+
<li><added title="Added">update to work with new github structure</added></li>
203+
</ul>
204+
<p><strong><a href="https://github.com/vanowm/userscript_github-open_with_vscode/commit/f0a0609">23.10.28-125044</a></strong> <date>(2023-10-28 12:50:44)</date></p>
201205
<ul>
202206
<li><changed title="Changed">moved icons to files</changed></li>
203207
</ul>

GitHub-Open_With_VSCode.user.js

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @namespace V@no
44
// @description Adds "Open with VSCode" button
55
// @match https://github.com/*
6-
// @version 23.10.28-125044
6+
// @version 24.5.9-085044
77
// @license MIT
88
// @run-at document-end
99
// @grant none
@@ -14,57 +14,39 @@
1414
"use strict";
1515
const fixLink = () =>
1616
{
17-
const elA_DownloadZip = document.querySelector(`[data-open-app="link"]`);
18-
if (!elA_DownloadZip)
17+
const elUL = document.querySelector(`#__primerPortalRoot__ > div > div > div > ul > div > ul`);
18+
if (!elUL)
1919
return true;
2020

21-
const elLi_DownloadZip = elA_DownloadZip.parentNode;
22-
const elA_VStudio = document.querySelector('[data-open-app="visual-studio"]');
23-
let elLi_VSCode;
24-
let elA_VSCode;
25-
if (elA_VStudio)
21+
const elLiVStudio = elUL.querySelector(`[id]:nth-child(2)`);
22+
if (elLiVStudio && !elLiVStudio.querySelector(".icon"))
2623
{
27-
const elLiVStudio = elA_VStudio.parentNode;
28-
elLi_VSCode = elLiVStudio.cloneNode(true);
29-
elA_VSCode = elLi_VSCode.querySelector("a");
3024
const elImg_Vstudio = document.createElement("img");
31-
elImg_Vstudio.classList.add("mr-2");
25+
elImg_Vstudio.classList.add("mr-2", "icon");
3226
elImg_Vstudio.src = "https://raw.githubusercontent.com/vanowm/userscript_github-open_with_vscode/master/media/vstudio.svg";
33-
elA_VStudio.prepend(elImg_Vstudio);
27+
elLiVStudio.prepend(elImg_Vstudio);
3428
}
35-
else
29+
const elLi_DownloadZip = elUL.querySelector(`li:last-child`);
30+
const elLi_VSCode = (elUL.querySelector(".vscode") || elLi_DownloadZip.cloneNode(true));
31+
if (!elLi_VSCode.parentNode)
3632
{
37-
elLi_VSCode = elLi_DownloadZip.cloneNode(true);
38-
elA_VSCode = elLi_VSCode.querySelector("a");
39-
elA_VSCode.dataset.action = "click:get-repo#showDownloadMessage";
40-
}
41-
try
42-
{
43-
const hydroClick = JSON.parse(elA_VSCode.dataset.hydroClick);
44-
hydroClick.payload.feature_clicked = "OPEN_WITH_VSCODE";
45-
elA_VSCode.dataset.hydroClick = JSON.stringify(hydroClick);
46-
}
47-
catch{}
48-
elA_VSCode.textContent = "Open with VSCode";
49-
const elImg_Vscode = document.createElement("img");
50-
elImg_Vscode.classList.add("mr-2");
51-
elImg_Vscode.src = "https://raw.githubusercontent.com/vanowm/userscript_github-open_with_vscode/master/media/vscode.svg";
52-
elA_VSCode.prepend(elImg_Vscode);
53-
// display "Launching Visual Studio Code..." message
54-
elA_VSCode.dataset.openApp = "vscode";
55-
const cloneURL = (document.querySelector(".input-group > .form-control") || {}).value;
33+
elLi_VSCode.classList.add("vscode");
34+
const elA_VSCode = elLi_VSCode.querySelector("a");
35+
elA_VSCode.textContent = "Open with VSCode";
36+
const elImg_Vscode = document.createElement("img");
37+
elImg_Vscode.classList.add("mr-2", "icon");
38+
elImg_Vscode.src = "https://raw.githubusercontent.com/vanowm/userscript_github-open_with_vscode/master/media/vscode.svg";
39+
elA_VSCode.prepend(elImg_Vscode);
5640

57-
if (cloneURL)
41+
const cloneURL = (elUL.parentNode.querySelector(`input`) || {}).value
42+
|| location.origin + location.pathname + ".git";
5843
elA_VSCode.href = "vscode://vscode.git/clone?url=" + encodeURI(cloneURL);
59-
else
60-
elA_VSCode.href = elA_VSCode.href.replace("git-client://", "vscode://vscode.git/");
6144

62-
elLi_DownloadZip.parentNode.insertBefore(elLi_VSCode, elLi_DownloadZip);
63-
//we don't need keep observing DOM changes anymore
64-
observer.disconnect();
45+
elLi_DownloadZip.parentNode.insertBefore(elLi_VSCode, elLi_DownloadZip);
46+
}
6547
};
6648

6749
const observer = new MutationObserver(fixLink);
68-
if (fixLink())
69-
observer.observe(document, {childList: true, subtree: true});
50+
fixLink();
51+
observer.observe(document, {childList: true, subtree: true});
7052
})();

0 commit comments

Comments
 (0)