mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-11 15:59:03 +00:00
fix: disable guardAgainstIFrameRequests to enable menu embed
This commit is contained in:
parent
705ba509cb
commit
a65fb79878
@ -4,6 +4,9 @@
|
|||||||
* (https://notion-enhancer.github.io/) under the MIT license
|
* (https://notion-enhancer.github.io/) under the MIT license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const replaceIfNotFound = (string, search, replacement) =>
|
||||||
|
string.includes(replacement) ? string : string.replace(search, replacement);
|
||||||
|
|
||||||
const patches = {
|
const patches = {
|
||||||
"*": async (scriptId, scriptContent) => {
|
"*": async (scriptId, scriptContent) => {
|
||||||
const prevTriggerPattern = /require\(['|"]notion-enhancer['|"]\)/,
|
const prevTriggerPattern = /require\(['|"]notion-enhancer['|"]\)/,
|
||||||
@ -18,20 +21,19 @@ const patches = {
|
|||||||
"main/main": async (scriptContent) => {
|
"main/main": async (scriptContent) => {
|
||||||
// https://github.com/notion-enhancer/desktop/issues/160
|
// https://github.com/notion-enhancer/desktop/issues/160
|
||||||
// enable the notion:// url scheme/protocol on linux
|
// enable the notion:// url scheme/protocol on linux
|
||||||
const searchValue = /process.platform === "win32"/g,
|
const search = /process.platform === "win32"/g,
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
replaceValue = 'process.platform === "win32" || process.platform === "linux"';
|
replacement = 'process.platform === "win32" || process.platform === "linux"';
|
||||||
if (scriptContent.includes(replaceValue)) return scriptContent;
|
return replaceIfNotFound(scriptContent, search, replacement);
|
||||||
return scriptContent.replace(searchValue, replaceValue);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"main/schemeHandler": async (scriptContent) => {
|
"main/schemeHandler": async (scriptContent) => {
|
||||||
// https://github.com/notion-enhancer/desktop/issues/291
|
// https://github.com/notion-enhancer/desktop/issues/291
|
||||||
// bypass csp issues by intercepting notion:// protocol
|
// bypass csp issues by intercepting notion:// protocol
|
||||||
const searchValue =
|
// prettier-ignore
|
||||||
"protocol.registerStreamProtocol(config_1.default.protocol, async (req, callback) => {",
|
const protocolSearch = "protocol.registerStreamProtocol(config_1.default.protocol, async (req, callback) => {",
|
||||||
replaceValue = `${searchValue}
|
protocolReplacement = `${protocolSearch}
|
||||||
{ /* notion-enhancer */
|
{/*notion-enhancer*/
|
||||||
const schemePrefix = "notion://www.notion.so/__notion-enhancer/";
|
const schemePrefix = "notion://www.notion.so/__notion-enhancer/";
|
||||||
if (req.url.startsWith(schemePrefix)) {
|
if (req.url.startsWith(schemePrefix)) {
|
||||||
const { search, hash, pathname } = new URL(req.url),
|
const { search, hash, pathname } = new URL(req.url),
|
||||||
@ -44,18 +46,21 @@ const patches = {
|
|||||||
data: require("fs").createReadStream(require("path").resolve(\`\${__dirname}/\${filePath}\`)),
|
data: require("fs").createReadStream(require("path").resolve(\`\${__dirname}/\${filePath}\`)),
|
||||||
headers: { "content-type": require("notion-enhancer/vendor/content-types.min.js").get(fileExt) },
|
headers: { "content-type": require("notion-enhancer/vendor/content-types.min.js").get(fileExt) },
|
||||||
});
|
});
|
||||||
}
|
}}`,
|
||||||
}`;
|
filterSearch = "function guardAgainstIFrameRequests(webRequest) {",
|
||||||
if (scriptContent.includes(replaceValue)) return scriptContent;
|
filterReplacement = `${filterSearch}/*notion-enhancer*/return;`;
|
||||||
return scriptContent.replace(searchValue, replaceValue);
|
return replaceIfNotFound(
|
||||||
|
replaceIfNotFound(scriptContent, filterSearch, filterReplacement),
|
||||||
|
protocolSearch,
|
||||||
|
protocolReplacement
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
"main/systemMenu": async (scriptContent) => {
|
"main/systemMenu": async (scriptContent) => {
|
||||||
// exposes template for modification
|
// exposes template for modification
|
||||||
const searchValue = "}\nexports.setupSystemMenu = setupSystemMenu;",
|
const search = "}\nexports.setupSystemMenu = setupSystemMenu;",
|
||||||
replaceValue = ` return template;\n${searchValue}`;
|
replacement = ` return template;\n${search}`;
|
||||||
if (scriptContent.includes(replaceValue)) return scriptContent;
|
return replaceIfNotFound(scriptContent, search, replacement);
|
||||||
return scriptContent.replace(searchValue, replaceValue);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user