ultrawidify/src/popup/App.vue

386 lines
9.8 KiB
Vue
Raw Normal View History

<template>
2020-12-06 21:57:16 +01:00
<!--
NOTE the code that makes ultrawidify popup work in firefox regardless of whether the
extension is being displayed in a normal or a small/overflow popup breaks the popup
behaviour on Chrome (where the popup would never reach the full width of 800px)
Since I'm tired and the hour is getting late, we'll just add an extra CSS class for
non-firefox builds of this extension and be done with it. No need to complicate things
further than that.
-->
2021-07-05 00:49:35 +02:00
<div v-if="settingsInitialized"
class="popup flex flex-column no-overflow"
2020-12-06 21:57:16 +01:00
:class="{'popup-chrome': ! BrowserDetect.firefox}"
>
<div class="flex-row flex-nogrow flex-noshrink relative"
:class="{'header': !narrowPopup, 'header-small': narrowPopup}"
>
<span class="smallcaps">Ultrawidify</span>: <small>Quick settings</small>
<div class="absolute channel-info" v-if="BrowserDetect.processEnvChannel !== 'stable'">
Build channel: {{BrowserDetect.processEnvChannel}}
</div>
</div>
<div class="flex flex-row body no-overflow flex-grow">
</div>
</div>
2022-07-26 23:54:25 +02:00
<pre>
---- site:
{{site}}
2022-07-26 23:54:25 +02:00
----
</pre>
</template>
<script>
import WhatsNewPanel from './panels/WhatsNewPanel.vue';
import SiteDetailsPanel from './panels/SiteDetailsPanel.vue';
import Donate from '../common/misc/Donate.vue';
import Debug from '../ext/conf/Debug';
import BrowserDetect from '../ext/conf/BrowserDetect';
import Comms from '../ext/lib/comms/Comms';
import VideoPanel from './panels/VideoPanel';
import PerformancePanel from './panels/PerformancePanel';
import Settings from '../ext/lib/Settings';
2021-03-14 02:34:35 +01:00
import ExecAction from './js/ExecAction';
import DefaultSettingsPanel from './panels/DefaultSettingsPanel';
import AboutPanel from './panels/AboutPanel';
import ExtensionMode from '../common/enums/ExtensionMode.enum';
import Logger from '../ext/lib/Logger';
import {ChromeShittinessMitigations as CSM} from '../common/js/ChromeShittinessMitigations';
2021-03-29 21:15:01 +02:00
import { browser } from 'webextension-polyfill-ts';
export default {
data () {
return {
comms: new Comms(),
settings: {},
settingsInitialized: false,
narrowPopup: null,
sideMenuVisible: null,
2022-07-26 23:54:25 +02:00
logger: undefined,
site: undefined
}
},
async created() {
2020-01-28 01:26:40 +01:00
this.logger = new Logger();
await this.logger.init({
2020-01-16 01:00:12 +01:00
allowLogging: true,
2019-09-17 22:18:02 +02:00
});
this.settings = new Settings({afterSettingsSaved: () => this.updateConfig(), logger: this.logger});
2019-02-13 23:58:19 +01:00
await this.settings.init();
this.settingsInitialized = true;
2021-03-29 21:15:01 +02:00
const port = browser.runtime.connect({name: 'popup-port'});
port.onMessage.addListener( (m,p) => this.processReceivedMessage(m,p));
CSM.setProperty('port', port);
2020-12-21 19:29:52 +01:00
2019-01-18 00:26:15 +01:00
// ensure we'll clean player markings on popup close
window.addEventListener("unload", () => {
2020-12-21 19:29:52 +01:00
CSM.port.postMessage({
2019-01-18 00:26:15 +01:00
cmd: 'unmark-player',
2019-04-13 03:09:29 +02:00
forwardToAll: true,
2019-01-18 00:26:15 +01:00
});
if (BrowserDetect.anyChromium) {
chrome.extension.getBackgroundPage().sendUnmarkPlayer({
cmd: 'unmark-player',
forwardToAll: true,
});
}
2019-01-18 00:26:15 +01:00
});
2019-04-13 03:09:29 +02:00
// get info about current site from background script
while (true) {
try {
console.log('trying to get site ...');
2019-04-13 03:09:29 +02:00
this.getSite();
console.log('site gottne');
2019-04-13 03:09:29 +02:00
} catch (e) {
console.warn('failed to load site:', e);
2019-04-13 03:09:29 +02:00
}
await this.sleep(5000);
2021-07-05 00:49:35 +02:00
}
},
async updated() {
const body = document.getElementsByTagName('body')[0];
// ensure that narrowPopup only gets set the first time the popup renders
// if popup was rendered before, we don't do anything because otherwise
// we'll be causing an unwanted re-render
2021-07-05 00:49:35 +02:00
//
2020-12-04 00:53:51 +01:00
// another thing worth noting — the popup gets first initialized with
// offsetWidth set to 0. This means proper popup will be displayed as a
// mini popup if we don't check for that.
if (this.narrowPopup === null && body.offsetWidth > 0) {
this.narrowPopup = body.offsetWidth < 600;
}
},
components: {
2019-02-16 01:19:29 +01:00
Debug,
BrowserDetect,
2019-01-03 02:07:16 +01:00
},
methods: {
2019-01-18 00:26:15 +01:00
async sleep(t) {
return new Promise( (resolve,reject) => {
2019-01-18 00:26:15 +01:00
setTimeout(() => resolve(), t);
});
},
toObject(obj) {
return JSON.parse(JSON.stringify(obj));
},
getSite() {
try {
this.logger.log('info','popup', '[popup::getSite] Requesting current site ...')
2020-12-21 19:29:52 +01:00
CSM.port.postMessage({cmd: 'get-current-site'});
2019-01-18 00:26:15 +01:00
} catch (e) {
this.logger.log('error','popup','[popup::getSite] sending get-current-site failed for some reason. Reason:', e);
2019-01-18 00:26:15 +01:00
}
},
getRandomColor() {
return `rgb(${Math.floor(Math.random() * 128)}, ${Math.floor(Math.random() * 128)}, ${Math.floor(Math.random() * 128)})`;
},
2019-01-03 02:07:16 +01:00
processReceivedMessage(message, port) {
this.logger.log('info', 'popup', '[popup::processReceivedMessage] received message:', message)
2019-01-03 02:07:16 +01:00
if (message.cmd === 'set-current-site'){
2019-01-03 02:07:16 +01:00
if (this.site) {
if (!this.site.host) {
2019-01-03 02:07:16 +01:00
// dunno why this fix is needed, but sometimes it is
this.site.host = site.tabHostname;
2019-01-03 02:07:16 +01:00
}
}
this.site = message.site;
// update activeSites
// this.activeSites = this.activeSites.filter(x => x.host !== message.site);
// add current site
// this.activeSites = unshift({
// host: message.site.host,
// isIFrame: false, // currently unused
// });
this.selectedSite = this.selectedSite || message.site.host;
2019-01-18 00:26:15 +01:00
this.loadFrames(this.site);
}
2019-05-09 21:10:26 +02:00
2019-08-25 01:52:04 +02:00
return true;
},
isDefaultFrame(frameId) {
return frameId === '__playing' || frameId === '__all';
2019-01-18 00:26:15 +01:00
},
2022-07-26 23:54:25 +02:00
loadFrames() {
this.activeSites = [{
host: this.site.host,
isIFrame: false, // not used tho. Maybe one day
}];
this.selectedSite = this.selectedSite || this.site.host;
2022-07-26 23:54:25 +02:00
// for (const frame in videoTab.frames) {
// this.activeFrames.push({
// id: `${this.site.id}-${frame}`,
// label: videoTab.frames[frame].host,
// ...this.frameStore[frame],
// })
// // only add each host once at most
// if (!this.activeSites.find(x => x.host === videoTab.frames[frame].host)) {
// this.activeSites.push({
// host: videoTab.frames[frame].host,
// isIFrame: undefined // maybe one day
// });
// }
// }
// update whether video tab can be shown
this.updateCanShowVideoTab();
2019-01-03 02:07:16 +01:00
},
getRandomColor() {
2019-01-03 02:07:16 +01:00
return `rgb(${Math.floor(Math.random() * 128)}, ${Math.floor(Math.random() * 128)}, ${Math.floor(Math.random() * 128)})`;
}
}
}
</script>
2019-01-03 02:07:16 +01:00
<style src="../res/css/font/overpass.css"></style>
<style src="../res/css/font/overpass-mono.css"></style>
2020-03-01 20:24:08 +01:00
<style src="../res/css/flex.scss"></style>
2019-01-03 02:07:16 +01:00
<style src="../res/css/common.scss"></style>
<style lang="scss" scoped>
html {
// width: 800px !important;
// max-width: 800px !important;
2019-01-03 02:07:16 +01:00
padding: 0px;
margin: 0px;
}
.zero-width {
width: 0px !important;
overflow: hidden;
}
.header .header-small, .narrow-content {
padding: 8px;
}
2019-01-17 22:16:55 +01:00
#tablist {
min-width: 275px;
2020-03-15 20:19:48 +01:00
max-width: 300px;
2019-01-17 22:16:55 +01:00
}
2019-01-03 02:07:16 +01:00
.header {
2019-01-17 22:16:55 +01:00
overflow: hidden;
2019-01-03 02:07:16 +01:00
background-color: #7f1416;
color: #fff;
margin: 0px;
margin-top: 0px;
padding-top: 8px;
padding-left: 15px;
padding-bottom: 1px;
font-size: 2.7em;
}
.header-small {
overflow: hidden;
background-color: #7f1416;
color: #fff;
margin: 0px;
margin-top: 0px;
padding-top: 8px;
padding-left: 15px;
padding-bottom: 1px;
font-size: 1.27em;
}
2019-01-03 02:07:16 +01:00
2019-01-03 02:07:16 +01:00
.menu-item-inline-desc{
font-size: 0.60em;
font-weight: 300;
font-variant: normal;
}
.menu-item {
flex-grow: 0;
2019-01-03 02:07:16 +01:00
padding-left: 15px;
padding-top: 5px;
padding-bottom: 5px;
font-variant: small-caps;
border-left: transparent 5px solid;
cursor: pointer;
user-select: none;
}
.menu-item-darker {
color: #999;
2019-01-03 02:07:16 +01:00
}
.suboption {
display: block;
padding-left: 15px;
padding-right: 15px;
padding-top: 5px;
padding-bottom: 20px;
min-height: 250px;
}
#no-videos-display {
height: 100%;
padding-top: 50px;
/* text-align: center; */
}
.tabitem-container {
padding-top: 0.5em;
}
.selected-tab {
background-color: initial;
border-left: #f18810 5px solid;
}
.tabitem {
font-variant: normal;
2019-01-20 21:12:26 +01:00
// font-size: 0.69em;
// margin-left: 16px;
2019-01-03 02:07:16 +01:00
border-left: transparent 3px solid;
padding-left: 12px;
margin-left: -10px;
}
.site-list {
max-height: 200px;
}
2019-01-03 02:07:16 +01:00
.tabitem-selected {
color: #fff !important;
background-color: initial;
border-left: #f0c089 3px solid !important;
}
2020-12-04 00:26:39 +01:00
2019-01-03 02:07:16 +01:00
.tabitem-selected::before {
padding-right: 8px;
2019-01-03 02:07:16 +01:00
}
.tabitem-disabled {
color: #cc3b0f !important;
}
2019-01-03 02:07:16 +01:00
.tabitem-iframe::after {
content: "</>";
padding-left: 0.33em;
}
2019-01-17 22:16:55 +01:00
2020-12-04 00:26:39 +01:00
.menu-button {
margin-bottom: 4px;
padding: 4px;
border-bottom: #f18810 1px solid !important;
font-size: 1.5rem !important;
2020-12-04 00:53:51 +01:00
cursor: pointer;
user-select: none;;
2020-12-04 00:26:39 +01:00
}
2019-01-17 22:16:55 +01:00
.popup {
height: 600px;
}
2020-12-06 21:57:16 +01:00
/**
This was written at the top, but it's worth repeating.
NOTE the code that makes ultrawidify popup work in firefox regardless of whether the
extension is being displayed in a normal or a small/overflow popup breaks the popup
behaviour on Chrome (where the popup would never reach the full width of 800px)
Since I'm tired and the hour is getting late, we'll just add an extra CSS class for
non-firefox builds of this extension and be done with it. No need to complicate things
further than that.
2021-07-05 00:49:35 +02:00
It also seems that Chrome doesn't like if we set the width of the popup all the way to
2020-12-06 21:57:16 +01:00
800px (probably something something scrollbar), so let's just take away a few px.
*/
.popup-chrome {
width: 780px !important;
}
.relative {
position: relative;
}
.absolute {
position: absolute;
}
.channel-info {
height: 0px;
right: 1.5rem;
bottom: 0.85rem;
font-size: 0.75rem;
}
.show-more {
padding-top: 12px;
font-size: 0.9rem;
}
</style>