-
Notifications
You must be signed in to change notification settings - Fork 10
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 support for Rewards Github publishers #20
Conversation
e00e787
to
34fc02e
Compare
c0b0725
to
dcfb025
Compare
tipButton.appendChild(tipIconContainer) | ||
|
||
// Create the tip icon | ||
const tipIcon = document.createElement('span') |
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.
Is it possible (and if so, worth it) to generalize this DOM creation operation across the sites (so that it would live in the "common" folder)?
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.
Good point, I'll enter a new issue for that. This function is particularly funny because it was originally copied from the Twitter content script. I guess the container layout also happens to work for Github, but it gives the false impression that Github is using this same layout/naming when it actually isn't.
return tipAction | ||
} | ||
|
||
const getCommentMetaData = (elem: Element) => { |
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.
This could probably be an async function, with the return Project.reject(...
replaced with throw ...
.
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.
Fixed.
parent.insertBefore(tipAction, end) | ||
} | ||
|
||
const getCommitLinksMetaData = (elem: Element) => { |
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.
Could probably be an async function as well.
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.
Fixed.
parent.appendChild(tipAction) | ||
} | ||
|
||
const getStarringContainerMetaData = (elem: Element) => { |
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.
Could probably be an async function.
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.
Fixed.
parent.insertBefore(tipAction, elements[0]) | ||
} | ||
|
||
const getPageHeadMetaData = (elem: Element) => { |
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.
Could probably be an async function.
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.
Fixed.
const configureTipActions = () => { | ||
clearTimeout(configureTipActionsTimeout) | ||
|
||
const tippingFunctions = [ |
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.
Nit: I think it would be more clear to not use this data structure and simply call configureTipAction
however many times is required.
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.
Good point, fixed.
} | ||
|
||
const handleOnUpdatedTab = (changeInfo: any) => { | ||
if (!changeInfo || (!changeInfo.url && changeInfo.status !== 'complete')) { |
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'm a little unclear on the filtering here - when do want the action below to run?
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.
Yes, this was a little odd. I was receiving multiple update notifications, I'm assuming it's related to Github using the history API as this bug seems to suggest: https://bugs.chromium.org/p/chromium/issues/detail?id=465709.
In order to work around that, I look for a changInfo
with a URL or a status of complete
and then store the location if it doesn't match what we already have stored.
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.
Sounds good - mind adding a short 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.
Good idea, added.
}) | ||
} | ||
|
||
const getMediaMetaData = (screenName: string) => { |
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.
Could probably be an async function.
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.
Fixed.
return Promise.reject(new Error('Invalid profile api url')) | ||
} | ||
|
||
return fetch(profileApiUrl) |
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.
If you use an async function, you can await fetch(....)
here.
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.
Fixed.
}) | ||
}) | ||
.catch((error: any) => { | ||
throw new Error(`Fetch request failed: ${error}`) |
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.
Throwing from a catch
handler will just result in a new rejected promise. You probably don't need the catch handler here (unless you want to add extra error context).
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.
Ahh yep, fixed.
dcfb025
to
468e909
Compare
Greaselion.json
Outdated
@@ -1,4 +1,16 @@ | |||
[ | |||
{ | |||
"urls": [ | |||
"https://*.github.com/*" |
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.
any reason to support sub domains?
I would guess we can do something like this
"https://github.com/*",
"https://www.github.com/*"
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 know that we need to support at least gist.github.com
, but I could just manually list that.
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 made that change.
d0e5b5f
to
716e73f
Compare
throw new Error('Invalid profile api url') | ||
} | ||
|
||
return await fetch(profileApiUrl) |
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.
You can use await to get rid of all of the then
callbacks, if you like:
const response = await fetch(profileApiUrl)
if (!response.ok) {
throw new Error(`Profile API request failed: ${response.statusText} (${response.status})`)
}
const data = await response.json()
return ...
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.
Ah yes, I definitely do want to get rid of that - thanks! Fixed.
716e73f
to
8bd5c50
Compare
8bd5c50
to
920ca65
Compare
920ca65
to
6042b5e
Compare
Associated brave-core PR: brave/brave-core#6789
Adds support for Github-based publisher tips via a Greaselion script. The script reacts to URL navigations and state changes by sending the associated publisher info to the Rewards extension, allowing tips to be supported via the Rewards panel and an injected inline tip button in the user's Github pages.