Skip to content
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

Move Twitch rewards processing to Greaselion #7019

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const handledByGreaselion = (url: URL) => {
url.hostname === 'github.com' ||
url.hostname.endsWith('.reddit.com') ||
url.hostname === 'reddit.com' ||
url.hostname.endsWith('.twitch.tv') ||
url.hostname === 'twitch.tv' ||
url.hostname.endsWith('.twitter.com') ||
url.hostname === 'twitter.com' ||
url.hostname.endsWith('.vimeo.com') ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,64 +150,8 @@ export class RewardsPanel extends React.Component<Props, State> {
if (!tabs || !tabs.length) {
return
}
const pollTwitchPage = (tab: chrome.tabs.Tab, tabId: number) => {
// use an interval here to monitor when the DOM has finished
// generating. clear after the data is present.
// Check every second no more than 'limit' times
// clear the interval if panel closes

const markupMatch = 'channel-header'
let itr = 0
const limit = 5
let interval = setInterval(poll, 1000)
function poll () {
chrome.tabs.executeScript(tabId, {
code: 'document.body.outerHTML'
}, function (result: string[]) {
if (result[0].includes(markupMatch)) {
clearInterval(interval)
const rewardsPanelActions = require('../background/actions/rewardsPanelActions').default
rewardsPanelActions.onTabRetrieved(tab, false, result[0])
} else {
chrome.storage.local.get(['rewards_panel_open'], function (result) {
if (result['rewards_panel_open'] === 'false') {
// panel was closed. give up
clearInterval(interval)
}
})
itr++
if (itr === limit) {
// give up
clearInterval(interval)

getTabData(tabId)
}
}
})
}
poll()
}

const pollData = (tab: chrome.tabs.Tab, tabId: number, url: URL) => {
if (url && url.href.startsWith('https://www.twitch.tv/')) {
chrome.storage.local.get(['rewards_panel_open'], function (result) {
if (result['rewards_panel_open'] === 'true') {
pollTwitchPage(tab, tabId)
}
})
} else {
getTabData(tabId)
}
}
let tab = tabs[0]
if (tab.url && tab.id) {
let url = new URL(tab.url)
if (url && url.host.endsWith('.twitch.tv')) {
pollData(tab, tab.id, url)
} else {
getTabData(tab.id)
}
} else if (tab.id) {
if (tab.id) {
getTabData(tab.id)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"permissions": [
"storage",
"tabs",
"chrome://favicon/*",
"https://www.twitch.tv/*"
"chrome://favicon/*"
],
"browser_action": {
"default_popup": "brave_rewards_panel.html",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ bool HandledByGreaselion(const std::string media_type) {
return false;
#else
return media_type == "github" || media_type == "reddit" ||
media_type == "twitter" || media_type == "vimeo" ||
media_type == "youtube";
media_type == "twitch" || media_type == "twitter" ||
media_type == "vimeo" || media_type == "youtube";
Comment on lines 24 to +26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can just return true for desktop, now that all of the supported publishers use Greaselion.

#endif
}

Expand Down