Skip to content
Permalink
Browse files

Fix for Chrome

  • Loading branch information...
rafaelgssa committed Sep 28, 2019
1 parent 7f58e6a commit f20afd78d0f60db94e9dcec22c60266df7569e40
@@ -10,10 +10,10 @@ class ItemParser {
return location.href;
}

isReady() {
async isReady() {
let isReady = false;

const session = NetflixApiUtils.getSession();
const session = await NetflixApiUtils.getSession();

if (session) {
this.id = session.videoId.toString();
@@ -33,7 +33,7 @@ class ItemParser {
}

async checkIsReady(resolve) {
if (this.isReady()) {
if (await this.isReady()) {
const data = await NetflixApiUtils.getMetadata(this.id);
resolve(data);
} else {
@@ -255,25 +255,45 @@ const netflixApiUtils = {
}
},

_getSession(resolve, event) {
window.removeEventListener('traktflix-getSession-fromPage', this.sessionListener);

const session = JSON.parse(event.detail.session);

resolve(session);
},

getSession() {
const netflix = window.netflix || (window.wrappedJSObject && window.wrappedJSObject.netflix);
return new Promise(resolve => {
if (window.wrappedJSObject) {
const netflix = window.wrappedJSObject.netflix;

if (netflix) {
const sessions = netflix.appContext.state.playerApp.getState().videoPlayer.playbackStateBySessionId;
const key = Object.keys(sessions).filter(key => key.match(/^watch/))[0];
if (netflix) {
const sessions = netflix.appContext.state.playerApp.getState().videoPlayer.playbackStateBySessionId;
const key = Object.keys(sessions).filter(key => key.match(/^watch/))[0];

let session = null;
let session = null;

if (key) {
session = Object.assign({}, sessions[key]);
}
if (key) {
session = Object.assign({}, sessions[key]);
}

if (window.wrappedJSObject) {
XPCNativeWrapper(window.wrappedJSObject.netflix);
}
XPCNativeWrapper(window.wrappedJSObject.netflix);

return session;
}
resolve(session);
} else {
resolve();
}
} else {
this.sessionListener = this._getSession.bind(this, resolve);

window.addEventListener('traktflix-getSession-fromPage', this.sessionListener, false);

const event = new CustomEvent('traktflix-getSession-toPage');

window.dispatchEvent(event);
}
});
},
};

@@ -30,7 +30,7 @@ export default class EventWatcher {
}

async checkForChanges() {
const session = NetflixApiUtils.getSession();
const session = await NetflixApiUtils.getSession();

if (typeof session !== 'undefined') {
if (session) {
@@ -81,8 +81,8 @@ export default class Scrobble {
});
}

checkForChanges() {
const session = NetflixApiUtils.getSession();
async checkForChanges() {
const session = await NetflixApiUtils.getSession();

if (session) {
this.progress = Math.round((session.currentTime / session.duration) * 10000) / 100;
@@ -12,11 +12,18 @@ class Header extends React.Component {
const tabs = await browser.tabs.query({url: `*://*.netflix.com/*`, active: true});

if (tabs.length > 0) {
browser.tabs.create({
cookieStoreId: tabs[0].cookieStoreId,
index: tabs[0].index + 1,
url: browser.runtime.getURL('html/history-sync.html'),
});
if (browser.cookies) {
browser.tabs.create({
cookieStoreId: tabs[0].cookieStoreId,
index: tabs[0].index + 1,
url: browser.runtime.getURL('html/history-sync.html'),
});
} else {
browser.tabs.create({
index: tabs[0].index + 1,
url: browser.runtime.getURL('html/history-sync.html'),
});
}
}
}

@@ -36,17 +36,76 @@ async function init() {
}
}

function _getApiDefs(event) {
window.removeEventListener('traktflix-getApiDefs-fromPage', getApiDefs);

const { authUrl, buildIdentifier } = event.detail;

if (authUrl && buildIdentifier) {
browser.runtime.sendMessage({ type: 'setApiDefs', authUrl, buildIdentifier });
}
}

function getApiDefs() {
const netflix = window.netflix || (window.wrappedJSObject && window.wrappedJSObject.netflix);
if (window.wrappedJSObject) {
const netflix = window.wrappedJSObject.netflix;

if (netflix) {
const authUrl = netflix.reactContext.models.userInfo.data.authURL;
const buildIdentifier = netflix.reactContext.models.serverDefs.data.BUILD_IDENTIFIER;
if (netflix) {
const authUrl = netflix.reactContext.models.userInfo.data.authURL;
const buildIdentifier = netflix.reactContext.models.serverDefs.data.BUILD_IDENTIFIER;

browser.runtime.sendMessage({type: `setApiDefs`, authUrl, buildIdentifier});
browser.runtime.sendMessage({ type: 'setApiDefs', authUrl, buildIdentifier });

if (window.wrappedJSObject) {
XPCNativeWrapper(window.wrappedJSObject.netflix);
}
} else {
const script = document.createElement('script');

script.textContent = `
window.addEventListener('traktflix-getApiDefs-toPage', () => {
let authUrl = '';
let buildIdentifier = '';
if (netflix) {
authUrl = netflix.reactContext.models.userInfo.data.authURL;
buildIdentifier = netflix.reactContext.models.serverDefs.data.BUILD_IDENTIFIER;
}
const event = new CustomEvent('traktflix-getApiDefs-fromPage', {
detail: { authUrl, buildIdentifier },
});
window.dispatchEvent(event);
});
window.addEventListener('traktflix-getSession-toPage', () => {
let session;
if (netflix) {
const sessions = netflix.appContext.state.playerApp.getState().videoPlayer.playbackStateBySessionId;
const key = Object.keys(sessions).filter(key => key.match(/^watch/))[0];
session = null;
if (key) {
session = sessions[key];
}
}
const event = new CustomEvent('traktflix-getSession-fromPage', {
detail: { session: JSON.stringify(session) },
});
window.dispatchEvent(event);
});
`;

document.body.appendChild(script);

window.addEventListener('traktflix-getApiDefs-fromPage', _getApiDefs, false);

const event = new CustomEvent('traktflix-getApiDefs-toPage');

window.dispatchEvent(event);
}
}

0 comments on commit f20afd7

Please sign in to comment.
You can’t perform that action at this time.