-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add fork-source-link-same-view feature
#3230
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 fork-source-link-same-view feature
#3230
Conversation
Yes, as small as possible around the repo name and fork link, but include the browser’s status bar to show its different. I did something similar for the “fix view link” feature.
Yeah it happens when the fork has a new file. It’s expected but at the same time it means we’re breaking that link. What if we send a HEAD request to the link to ensure it works before changing the pathname? |
I am not sure which feature your talking about.
Ok I had this idea. At first I awaited the check but that was causing issues with the fork dropdown (When there is more than one fork we make it a drop down). So I decided not to await it and update the link when api finishes. Its a very simple request and did not take even a second. The worst thing that can happen if someone clicks it before and the file does not exists they will get a 404. Maybe we should only do this on your own forks? WDYT? |
|
Looks like I missed the boat (Ouch) I thought you wanted to check the fork links too if they point to a 404. Correcting. |
I didn't think of that, but in that case we're not breaking an native link, it's our own feature. |
💯 |
|
I timed it to test which one is faster, Api wins. refined-github.js:8953 fetch: 356.760009765625ms |
source/github-helpers/index.ts
Outdated
|
|
||
| export function getForkedRepo(): string | undefined { | ||
| return select<HTMLAnchorElement>('.fork-flag a')?.pathname.slice(1); | ||
| return select<HTMLAnchorElement>('.fork-flag a')?.pathname.slice(1).split('/', 2).join('/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return select<HTMLAnchorElement>('.fork-flag a')?.pathname.slice(1).split('/', 2).join('/'); | |
| return select<HTMLAnchorElement>('.fork-flag .text a')?.textContent!.trim(); |
I think this would work here too, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess. Double-check by blaming the line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks at the blame and finds a magic comment
Also you could use the same meta tags I used in the isForkedRepo since they're available earlier on the page:
<meta name="octolytics-dimension-repository_parent_nwo" content="sindresorhus/refined-github" />
| return select<HTMLAnchorElement>('.fork-flag a')?.pathname.slice(1).split('/', 2).join('/'); | |
| return select<HTMLMetaElement>('[name="octolytics-dimension-repository_parent_nwo"]')?.content; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, good job. That's what happens when I review after a merge PR, it gets lost
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be put back?
Co-authored-by: Fregante <opensource@bfred.it>
I think all I am missing is a screenshot Can you point me to it? I am not sure which feature your talking about |
|
@fregante what program do you use? I have a very hard time doing those kind of pictures. |
|
The screenshot misses the context entirely. I have no idea what that is. At least include the repo name and don’t zoom too much |
I can test it in about an hour |
Yes For example on this PR it send me to https://github.com/yakov116/refined-github/pull/HEAD |
Co-authored-by: Fregante <opensource@bfred.it>
fregante
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Felt like those changes weren't needed at all. createLink was fine in that feature
|
Doesn't work again 😅 it points to itself, not the fork source https://github.com/fregante/refined-github/blob/master/.editorconfig |
I love how clean it is now. @fregante I learn from your coding each day. Thanks! |
|
Not sure it will get lost here please take a look at https://github.com/sindresorhus/refined-github/pull/3230/files/4003fa22b477050b3db99b86ea84e80cb2fb7741#diff-cecb0456449444f8df0aa134a3ba6540 |
It's already here: https://github.com/sindresorhus/refined-github/blob/75422077fa0dc554a2a0b50c9e5701e4a336684f/source/github-helpers/index.ts#L50-L52 |
|
I think this should also support Test link: https://github.com/yakov116/refined-github/edit/upstream/package.json |
|
@fregante I'm on it Send it just to blob? |
|
Why would you send it to blob instead of leaving it as edit? |
|
Less code :). I am working on it will have a pr in a few |



LINKED ISSUES:
Closes
default-branch-buttonon forks: add secondary button to see folder on source repo #2985TEST URLS:
Any forked repo
SCREENSHOT:

Notes: I "hosted" the function in this feature since I felt that
forked-towas getting crowded.