useful-forks.github.io icon indicating copy to clipboard operation
useful-forks.github.io copied to clipboard

userscript version of the Chrome extension

Open odnar-dev opened this issue 3 years ago • 16 comments

closes #20

odnar-dev avatar Mar 12 '21 16:03 odnar-dev

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

odnar-dev avatar Mar 12 '21 16:03 odnar-dev

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 avatar Mar 13 '21 17:03 payne911

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

payne911 avatar Mar 14 '21 04:03 payne911

3

odnar-dev avatar Mar 16 '21 01:03 odnar-dev

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

Is that what fixes #9 ?

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

payne911 avatar Mar 17 '21 00:03 payne911

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

odnar-dev avatar Mar 17 '21 05:03 odnar-dev

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 avatar Mar 18 '21 13:03 payne911

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 avatar Mar 19 '21 03:03 payne911

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 ?

payne911 avatar Mar 20 '21 00:03 payne911

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..)

odnar-dev avatar Mar 21 '21 01:03 odnar-dev

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.

payne911 avatar May 27 '21 04:05 payne911

hey any news about this ?

odnar-dev avatar Oct 06 '21 17:10 odnar-dev

Any update? This would be a great addition!

Metacinnabar avatar Oct 08 '21 04:10 Metacinnabar

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.

payne911 avatar Nov 11 '21 16:11 payne911

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

odnar-dev avatar Nov 12 '21 12:11 odnar-dev

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 avatar Nov 14 '21 17:11 payne911

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.

payne911 avatar Jan 19 '23 01:01 payne911