Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for Google Chrome Extension (#512)
Support for Google Chrome Extension
- Loading branch information
Showing
5 changed files
with
97 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const EXTENSION_ID = "amknoiejhlmhancpahfcfcfhllgkpbld"; | ||
|
||
// Check if the Chrome Extension is present | ||
// The Chrome extension injects an empty span to help detection. | ||
// Also check for the presence of window.chrome object to confirm smooth operations | ||
export const hasChromeExtensionInstalled = () => { | ||
return document.getElementById("chromePWExtensionDetect") !== null; | ||
} | ||
|
||
const chromeWithoutProxy = (req, _store) => new Promise((resolve, reject) => { | ||
chrome.runtime.sendMessage( | ||
EXTENSION_ID, { | ||
messageType: "send-req", | ||
data: { | ||
config: req | ||
} | ||
}, (message) => { | ||
if (message.data.error) { | ||
reject(message.data.error); | ||
} else { | ||
resolve(message.data.response); | ||
} | ||
} | ||
); | ||
}); | ||
|
||
const chromeWithProxy = (req, { state }) => new Promise((resolve, reject) => { | ||
chrome.runtime.sendMessage( | ||
EXTENSION_ID, { | ||
messageType: "send-req", | ||
data: { | ||
config: { | ||
method: "post", | ||
url: state.postwoman.settings.PROXY_URL || "https://postwoman.apollotv.xyz/", | ||
data: req | ||
} | ||
} | ||
}, (message) => { | ||
if (message.data.error) { | ||
reject(error); | ||
} else { | ||
resolve(message.data.response.data); | ||
} | ||
} | ||
) | ||
}); | ||
|
||
const chromeStrategy = (req, store) => { | ||
if (store.state.postwoman.settings.PROXY_ENABLED) { | ||
return chromeWithProxy(req, store); | ||
} else { | ||
return chromeWithoutProxy(req, store); | ||
} | ||
} | ||
|
||
export default chromeStrategy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters