Add partial YouTube compatibility shim

This commit is contained in:
hensm
2019-01-23 15:27:57 +00:00
parent 5c1c78016b
commit 2373880214
4 changed files with 55 additions and 18 deletions

10
ext/src/compat/youtube.js Normal file
View File

@@ -0,0 +1,10 @@
"use strict";
// Insert script before first script is run
document.addEventListener("beforescriptexecute", function onBeforeScriptExecute () {
document.removeEventListener("beforescriptexecute", onBeforeScriptExecute);
const scriptElement = document.createElement("script");
scriptElement.src = browser.runtime.getURL("vendor/webcomponents-lite.min.js");
document.head.prepend(scriptElement);
});

View File

@@ -17,6 +17,13 @@
, "background": {
"scripts": [ "main.js" ]
}
, "content_scripts": [
{
"matches": [ "https://www.youtube.com/*" ]
, "js": [ "compat/youtube.js" ]
, "run_at": "document_start"
}
]
, "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
, "default_locale": "en"
@@ -38,6 +45,6 @@
, "web_accessible_resources": [
"shim/bundle.js"
, "dm.js"
, "vendor/webcomponents-lite.min.js"
]
}

File diff suppressed because one or more lines are too long

View File

@@ -18,6 +18,7 @@ module.exports = (env) => ({
, "mediaCast" : `${includePath}/mediaCast.js`
, "mirroringCast" : `${includePath}/mirroringCast.js`
, "messageRouter" : `${includePath}/messageRouter.js`
, "compat/youtube" : `${includePath}/compat/youtube.js`
}
, output: {
filename: "[name].js"
@@ -34,25 +35,32 @@ module.exports = (env) => ({
})
// Copy static assets
, new CopyWebpackPlugin([{
from: includePath
, to: env.outputPath
, ignore: [ "*.js", "*.jsx" ]
, transform (content, path) {
// Access to variables in static files
if (path.endsWith(".json")) {
return Buffer.from(content.toString()
.replace("EXTENSION_NAME", env.extensionName)
.replace("EXTENSION_ID", env.extensionId)
.replace("EXTENSION_VERSION", env.extensionVersion)
.replace("MIRRORING_APP_ID", env.mirroringAppId)
.replace("APPLICATION_NAME", env.applicationName)
.replace("APPLICATION_VERSION", env.applicationVersion));
}
, new CopyWebpackPlugin([
{
from: includePath
, to: env.outputPath
, ignore: [ "*.js", "*.jsx" ]
, transform (content, path) {
// Access to variables in static files
if (path.endsWith(".json")) {
return Buffer.from(content.toString()
.replace("EXTENSION_NAME", env.extensionName)
.replace("EXTENSION_ID", env.extensionId)
.replace("EXTENSION_VERSION", env.extensionVersion)
.replace("MIRRORING_APP_ID", env.mirroringAppId)
.replace("APPLICATION_NAME", env.applicationName)
.replace("APPLICATION_VERSION", env.applicationVersion));
}
return content;
return content;
}
}
}])
, {
// Copy vendor dir
from: path.join(includePath, "vendor")
, to: path.join(env.outputPath, "vendor")
}
])
]
, mode: "development"
, module: {