55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
|
import { isNull } from "lodash";
|
||
|
|
||
|
async function addView() {
|
||
|
var regex = /^\/([a-z-]+)\/([0-9]+)\//;
|
||
|
|
||
|
if (regex.test(document.location.pathname)) {
|
||
|
var params = document.location.pathname.match(regex);
|
||
|
fetch(
|
||
|
`https://qa.softcad.pw/${params[1]}/view/${document.location.hostname}/${params[2]}`
|
||
|
).catch((err) => {});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async function playStart(title, poster_path) {
|
||
|
fetch('/api/modal', {
|
||
|
method: 'POST',
|
||
|
headers: {
|
||
|
'Accept': 'application/json, text/plain, */*',
|
||
|
'Content-Type': 'application/json'
|
||
|
},
|
||
|
body: JSON.stringify({poster_path: poster_path, title: title})
|
||
|
}).then(res => {
|
||
|
return res.text();
|
||
|
}).then( html => {
|
||
|
|
||
|
const modal = document.getElementById('player-modal');
|
||
|
modal.innerHTML = html;
|
||
|
let event = new CustomEvent("show-player-modal", {});
|
||
|
window.dispatchEvent(event);
|
||
|
})
|
||
|
.catch(err => {console.log(err)});
|
||
|
}
|
||
|
|
||
|
export function initializePlayer() {
|
||
|
const player = document.getElementById('player');
|
||
|
if (!isNull(player)) {
|
||
|
const config = JSON.parse(player.getAttribute('data-plyr-config'));
|
||
|
addView();
|
||
|
new Plyr("#player", {
|
||
|
listeners: {
|
||
|
play: function (e) {
|
||
|
if (this.fullscreen.active) {
|
||
|
this.fullscreen.exit();
|
||
|
}
|
||
|
playStart(config.title, config.poster_path);
|
||
|
return false;
|
||
|
},
|
||
|
},
|
||
|
});
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
return false;
|
||
|
}
|