Skip to content

GKCS-5022 handle github portals #13

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

Merged
merged 1 commit into from
Dec 21, 2023
Merged
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
55 changes: 54 additions & 1 deletion src/hosts/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export function injectionScope(url: string) {
class GitHubInjectionProvider implements InjectionProvider {
private _timer: ReturnType<typeof setTimeout> | undefined;
private _observer: MutationObserver | undefined;
private _domTimer: ReturnType<typeof setTimeout> | undefined;
private _domObserver: MutationObserver | undefined;

constructor(private uri: URL) {}

Expand All @@ -18,6 +20,22 @@ export function injectionScope(url: string) {
this.uri = new URL(window.location.href);
this.render();
});

this._domObserver = new MutationObserver((e: MutationRecord[]) => {
const portalchange = e.find(e => e.target && (e.target as HTMLElement).id === '__primerPortalRoot__');
if (portalchange) {
if (this._domTimer != null) {
return;
}

this._domTimer = setTimeout(() => {
this._domTimer = undefined;
this.render();
}, 100);
}
});
this._domObserver.observe(document.body, { childList: true, subtree: true });

this.render();
}

Expand Down Expand Up @@ -96,6 +114,22 @@ export function injectionScope(url: string) {
position: 'afterend',
});

insertions.set('#__primerPortalRoot__ > div > div > div > ul > div > ul > li:first-child', {
html: /*html*/ `<li data-gk class="Box-row Box-row--hover-gray p-3 mt-0 rounded-0">
<a class="d-flex flex-items-center color-fg-default text-bold no-underline" href="${url}" target="_blank" title="${label}" aria-label="${label}">
${this.getGitKrakenSvg(16, 'mr-2')}
${label}
</a>
</li>
<li data-gk class="Box-row Box-row--hover-gray p-3 mt-0 rounded-0">
<a class="d-flex flex-items-center color-fg-default text-bold no-underline" href="${compareUrl}" target="_blank" title="Open Comparison with GitKraken" aria-label="Open Comparison with GitKraken">
${this.getGitKrakenSvg(16, 'mr-2')}
Open Comparison with GitKraken
</a>
</li>`,
position: 'afterend',
});

break;
}
case 'tree':
Expand All @@ -110,6 +144,16 @@ export function injectionScope(url: string) {
position: 'afterend',
});

insertions.set('#__primerPortalRoot__ > div > div > div > ul > div > ul > li:first-child', {
html: /*html*/ `<li data-gk class="Box-row Box-row--hover-gray p-3 mt-0 rounded-0">
<a class="d-flex flex-items-center color-fg-default text-bold no-underline" href="${url}" target="_blank" title="${label}" aria-label="${label}">
${this.getGitKrakenSvg(16, 'mr-2')}
${label}
</a>
</li>`,
position: 'afterend',
});

break;
default: {
insertions.set('.file-navigation get-repo', {
Expand All @@ -120,7 +164,6 @@ export function injectionScope(url: string) {
)}</a>`,
position: 'beforebegin',
});

insertions.set('[data-target="get-repo.modal"] #local-panel ul li:first-child', {
html: /*html*/ `<li data-gk class="Box-row Box-row--hover-gray p-3 mt-0 rounded-0">
<a class="d-flex flex-items-center color-fg-default text-bold no-underline" href="${url}" target="_blank" title="${label}" aria-label="${label}">
Expand All @@ -131,6 +174,16 @@ export function injectionScope(url: string) {
position: 'afterend',
});

insertions.set('#__primerPortalRoot__ > div > div > div > ul > div > ul > li:first-child', {
html: /*html*/ `<li data-gk class="Box-row Box-row--hover-gray p-3 mt-0 rounded-0">
<a class="d-flex flex-items-center color-fg-default text-bold no-underline" href="${url}" target="_blank" title="${label}" aria-label="${label}">
${this.getGitKrakenSvg(16, 'mr-2')}
${label}
</a>
</li>`,
position: 'afterend',
});

break;
}
}
Expand Down