2024-11-07 08:21:37 -05:00
|
|
|
import { isValidURL } from "../utils/misc.js";
|
|
|
|
|
import { findPath } from "../utils/paths.js";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import fs from 'fs';
|
2024-12-30 14:16:40 +02:00
|
|
|
const youtube = fs.readFileSync(await findPath('youtubeutils.js')),
|
|
|
|
|
contextmenu = fs.readFileSync(await findPath('contextmenu.js'));
|
2024-11-07 08:21:37 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {Electron.WebContents} contents
|
|
|
|
|
*/
|
|
|
|
|
const youtubeinject = (contents) => {
|
|
|
|
|
const f = () => contents.executeJavaScript(youtube).then(() => contents.executeJavaScript('injectDislike()'));
|
|
|
|
|
contents.addListener('did-finish-load', f);
|
|
|
|
|
contents.addListener('did-navigate', async (_) => {
|
|
|
|
|
const hostname = await contents.executeJavaScript('window.location.hostname');
|
|
|
|
|
if (hostname !== 'www.youtube.com') return contents.removeListener('did-navigate', f);
|
|
|
|
|
else f();
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-12-30 14:16:40 +02:00
|
|
|
/**
|
|
|
|
|
* @param {Electron.WebContents} contents
|
|
|
|
|
*/
|
|
|
|
|
const contextMenuInject = (contents) => contents.executeJavaScript(contextmenu).catch(console.error);
|
|
|
|
|
|
|
|
|
|
|
2024-11-07 08:21:37 -05:00
|
|
|
/**
|
|
|
|
|
* @param {Electron.WebContents} contents
|
|
|
|
|
*/
|
|
|
|
|
export default async function addonManager(contents) {
|
|
|
|
|
try {
|
2024-12-30 14:16:40 +02:00
|
|
|
contextMenuInject(contents);
|
2024-11-07 08:21:37 -05:00
|
|
|
|
2024-12-30 14:16:40 +02:00
|
|
|
const hostname = await contents.executeJavaScript('window.location.hostname');
|
2024-11-07 08:21:37 -05:00
|
|
|
if (hostname === 'www.youtube.com') return youtubeinject(contents);
|
2024-12-30 14:16:40 +02:00
|
|
|
|
2024-11-07 08:21:37 -05:00
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
catch (err) {
|
|
|
|
|
console.error(err);
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
}
|