useful-forks / useful-forks.github.io

Improving GitHub's Forks list discoverability through automatic filtering. The project offers an online tool and a Chrome extension.
https://useful-forks.github.io/
MIT License
1.18k stars 61 forks source link

userscript version of the Chrome extension #21

Closed odnar-dev closed 1 year ago

odnar-dev commented 3 years ago

closes #20

odnar-dev commented 3 years ago

menu to make it easy to add GITHUB_ACCESS_TOKEN or change it 1 show error if GITHUB_ACCESS_TOKEN has not been set up 2 hover color is adapted to GitHub's Night-Mode. (need better colors) 3

payne911 commented 3 years ago

That is looking like some really great work: I'll review the PR in the coming days. Thanks a lot for your contribution !

Are you aware of whether it would be possible not to duplicate the JavaScript code used for the Chrome plugin ? I know refined-github somehow manages to use the same code for all their supported browsers.

Maybe @fregante 's expertise could be helpful here.

payne911 commented 3 years ago

(Sorry, I thought changing the title would link the other issue, but I ended up having to edit your OP.)

odnar-dev commented 3 years ago

3

payne911 commented 3 years ago

document.addEventListener('pjax:end', init);

Is that what fixes #9 ?

Also, does Violentmonkey require the script to be within that (function() { /* code */ })(); wrapper ?

odnar-dev commented 3 years ago

document.addEventListener('pjax:end', init); Is that what fixes #9 ?

yes , github use for some pages Pjax to deliver a faster browsing experience without reloading the full page. check this

does Violentmonkey require the script to be within that (function() { / code / })(); wrapper ?

i don't think so , just a habit

payne911 commented 3 years ago

Would you mind creating 2 extra PRs for the fixes of #4 and #9 ? I'd do it myself, but I'll respect your "ownership" of the solutions, in case you wanted to be labeled as a contributor. I'd merge both those PRs into the Chrome script.

For this current PR, I don't have a lot of time to test it just yet. I'll eventually try to simply add your // ==UserScript== right at the top of the Chrome script.

payne911 commented 3 years ago

Alright, #25 was perfect, thanks for that!

I tried to incorporate your fix for #9 but couldn't get it to work properly. Have you tested if those cases work properly:

  1. landing directly on the Forks page (test with: https://github.com/useful-forks/useful-forks.github.io/network/members)
  2. refreshing the page when on the Forks page works (just press F5 when at the URL presented above)
payne911 commented 3 years ago

Alright, now that I've incorporated both of your side-fixes into the main branch, it could be interesting to look into what this actually has to offer.

Have you tried incorporating your code directly into the Chrome plugin's script and seeing how well it works for people with and without Violentmonkey ?

odnar-dev commented 3 years ago

Violentmonkey is an userscript manager this part of the script use a group of special apis provided only by an userscript manager.

// get token from local storage provided by the userscript manager.
let GITHUB_ACCESS_TOKEN = GM_getValue('GITHUB_ACCESS_TOKEN')
// add menu 
GM_registerMenuCommand("Set Github Access Token", setPersonalToken)
GM_registerMenuCommand("Generate New Access Token", newPersonalToken);
// store token in local storage provided by the userscript manager.
function setPersonalToken(){
    var mess = "Personal Access Token";
    var caseShow = GITHUB_ACCESS_TOKEN;
    var getpersonalToken = prompt(mess, caseShow);
    GITHUB_ACCESS_TOKEN = (getpersonalToken===null? GITHUB_ACCESS_TOKEN : getpersonalToken)
    GM_setValue("GITHUB_ACCESS_TOKEN", GITHUB_ACCESS_TOKEN)
}
// open url to generate a new personal token in new tab
function newPersonalToken(){
  let tabControl = GM_openInTab("https://github.com/settings/tokens/new?scopes=repo&description=UsefulFork")
  tabControl.onclose = () => setPersonalToken();
}

this should work in most other userscript managers (like Greasemonkey, Tampermonkey..)

payne911 commented 3 years ago

My main concern is the duplication of code. Is there a way to integrate it within the chrome script in a non-intrusive way?

I'm already bothered by a large portion of the code being duplicated, I wouldn't want to have to maintain a third duplicate.

odnar-dev commented 2 years ago

hey any news about this ?

Metacinnabar commented 2 years ago

Any update? This would be a great addition!

payne911 commented 2 years ago

As mentioned, I'm kind of bothered by the duplication of code. See https://github.com/useful-forks/useful-forks.github.io/pull/21#issuecomment-849303400.

odnar-dev commented 2 years ago

i'm kind of bothered by the duplication of code

what about creating a separate file that contain all shared functions and variables then simply include it to chrome script and userscript

payne911 commented 2 years ago

what about creating a separate file that contain all shared functions and variables

Maybe that could work.

As a Java dev, what comes to mind is abstracting with an interface that has a few default methods for the shared ones, and then some different implementations for the Chrome and Monkey plugins.

payne911 commented 1 year ago

The plugin has been heavily modified (see https://github.com/useful-forks/useful-forks.github.io/commit/63b9a3c49dd1bce9e1daf93dd4ea90bda002594e).

I'm closing the PR because it would basically need a rewrite anyways.