ultrawidify/src/popup/js/ExecAction.js

65 lines
1.9 KiB
JavaScript
Raw Normal View History

import Comms from '../../ext/lib/comms/Comms';
class ExecAction {
2019-02-13 23:58:19 +01:00
constructor(settings, site) {
this.settings = settings;
2019-02-13 23:58:19 +01:00
this.site = site;
}
setSettings(settings) {
this.settings = settings;
}
2019-02-13 23:58:19 +01:00
setSite(site) {
this.site = site;
}
exec(action, scope, frame) {
for (var cmd of action.cmd) {
if (scope === 'page') {
const message = {
forwardToContentScript: true,
targetFrame: frame,
frame: frame,
cmd: cmd.action,
arg: cmd.arg
}
Comms.sendMessage(message);
} else if (scope === 'site') {
2019-02-13 23:58:19 +01:00
let site = this.site;
if (!this.site) {
site = window.location.host;
}
if (!this.settings.active.sites[site]) {
this.settings.active.sites[site] = this.settings.getDefaultOption();
}
if (cmd.action === "set-stretch") {
2019-02-13 23:58:19 +01:00
this.settings.active.sites[site].stretch = cmd.arg;
} else if (cmd.action === "set-alignment") {
2019-02-13 23:58:19 +01:00
this.settings.active.sites[site].videoAlignment = cmd.arg;
} else if (cmd.action === "set-extension-mode") {
2019-02-13 23:58:19 +01:00
this.settings.active.sites[site].mode = cmd.arg;
} else if (cmd.action === "set-autoar-mode") {
2019-02-13 23:58:19 +01:00
this.settings.active.sites[site].autoar = cmd.arg;
}
this.settings.save();
} else if (scope === 'global') {
if (cmd.action === "set-stretch") {
2019-01-20 23:05:04 +01:00
this.settings.active.sites['@global'].stretch = cmd.arg;
} else if (cmd.action === "set-alignment") {
2019-01-20 23:05:04 +01:00
this.settings.active.sites['@global'].videoAlignment = cmd.arg;
} else if (cmd.action === "set-extension-mode") {
2019-02-13 23:58:19 +01:00
this.settings.active.sites['@global'].mode = cmd.arg;
} else if (cmd.action === "set-autoar-mode") {
2019-02-13 23:58:19 +01:00
this.settings.active.sites['@global'].autoar = cmd.arg;
}
this.settings.save();
}
}
}
}
export default ExecAction;