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

Improved C2P Script Injection #528

Merged
merged 11 commits into from Apr 28, 2020

set c2p queue as hashmap to prevent duplicates

  • Loading branch information
christophertino committed Apr 22, 2020
commit 0103ab2a381b95b92eb115c060f68377ef56ba95
@@ -161,15 +161,11 @@ const Click2PlayContentScript = (function(win, doc) {
if (name === 'c2p') {
if (message) {
// Dequeue C2P data stored while the script injection was taking place
if (Array.isArray(message)) {
let m = message.shift();
while (m !== undefined) {
applyC2P(m.app_id, m.data, m.html);
m = message.shift();
for (const app_id in message) {
if (message.hasOwnProperty(app_id)) {
applyC2P(app_id, message[app_id].data, message[app_id].html);
delete message[app_id];
}
} else {
// Single C2P message
applyC2P(message.app_id, message.data, message.html);
}
}
}
@@ -3,7 +3,7 @@
*
* this._tabInfo[tab_id]: {
* c2pStatus {string} current status of the click_to_play.js script injection on the tab (none|loading|done)
* c2pQueue {array} queue of c2p messages collected when c2pStatus is none or loading
* c2pQueue {Object} queue of c2p messages collected when c2pStatus is none or loading, organized as a HashSet by app_id
* domain: {string} the general domain name plus suffix (no sub-domains)
* hash: {string} hash values appended to the url
* host: {string} the domain name plus suffix and sub-domains
@@ -71,7 +71,7 @@ class TabInfo {
},
insecureRedirects: [],
c2pStatus: 'none',
c2pQueue: [],
c2pQueue: {},
};

this._tabInfo[tab_id] = info;
@@ -108,23 +108,26 @@ export function buildC2P(details, app_id) {
// Send the entire queue to the content script to reduce message passing
sendMessage(tab_id, 'c2p', tab.c2pQueue);
tab.c2pStatus = 'done';
tab.c2pQueue = {};
}).catch((err) => {
log('buildC2P error', err);
});
break;
case 'loading':
// Push C2P data to a holding queue until click_to_play.js has finished loading on the page
tab.c2pQueue.push({
app_id,
data: c2pApp,
html: c2pHtml
});
if (!tab.c2pQueue.hasOwnProperty(app_id)) {
tab.c2pQueue[app_id] = {
data: c2pApp,
html: c2pHtml
};
}
break;
case 'done':
sendMessage(tab_id, 'c2p', {
app_id,
data: c2pApp,
html: c2pHtml
app_id: {
data: c2pApp,
html: c2pHtml
}
});
break;
default:
ProTip! Use n and p to navigate between commits in a pull request.