|
| 1 | +export default { |
| 2 | + icon: "https://lh3.googleusercontent.com/cvfpnTKw3B67DtM1ZpJG2PNAIjP6hVMOyYy403X4FMkOuStgG1y4cjCn21vmTnnsip1dTZSVsWBA9IxutGuA3dVDWhg=w128-h128-e365-rj-sc0x00ffffff", |
| 3 | + name: { |
| 4 | + en: "PIP full website", |
| 5 | + vi: "PIP toàn website", |
| 6 | + }, |
| 7 | + description: { |
| 8 | + en: "Picture in picture mode for full website", |
| 9 | + vi: "Picture in picture: Xem toàn bộ website (thay vì chỉ video) trong của sổ nhỏ", |
| 10 | + img: "", |
| 11 | + }, |
| 12 | + |
| 13 | + changeLogs: [ |
| 14 | + { |
| 15 | + version: "1.66", |
| 16 | + date: "25/04/2024", |
| 17 | + description: { |
| 18 | + en: "init", |
| 19 | + vi: "init", |
| 20 | + }, |
| 21 | + }, |
| 22 | + ], |
| 23 | + |
| 24 | + onClickContentScript: async () => { |
| 25 | + if (!window.ufs_pip_fullWebsite) { |
| 26 | + window.ufs_pip_fullWebsite = { |
| 27 | + isPIP: false, |
| 28 | + video: null, |
| 29 | + stream: null, |
| 30 | + }; |
| 31 | + } |
| 32 | + |
| 33 | + function enterPIP(stream, video) { |
| 34 | + window.ufs_pip_fullWebsite.isPIP = true; |
| 35 | + window.ufs_pip_fullWebsite.video = video; |
| 36 | + window.ufs_pip_fullWebsite.stream = stream; |
| 37 | + video.requestPictureInPicture(); |
| 38 | + } |
| 39 | + |
| 40 | + function leavePIP() { |
| 41 | + document.exitPictureInPicture(); |
| 42 | + window.ufs_pip_fullWebsite.isPIP = false; |
| 43 | + window.ufs_pip_fullWebsite.video?.remove?.(); |
| 44 | + window.ufs_pip_fullWebsite.stream?.getVideoTracks?.().forEach((track) => { |
| 45 | + track.stop(); |
| 46 | + }); |
| 47 | + window.ufs_pip_fullWebsite.stream = null; |
| 48 | + } |
| 49 | + |
| 50 | + try { |
| 51 | + if (window.ufs_pip_fullWebsite.isPIP) { |
| 52 | + leavePIP(); |
| 53 | + return; |
| 54 | + } |
| 55 | + |
| 56 | + const tab = await UfsGlobal.Extension.runInBackground( |
| 57 | + "utils.getCurrentTab" |
| 58 | + ); |
| 59 | + |
| 60 | + const streamId = await UfsGlobal.Extension.runInBackground( |
| 61 | + "chrome.tabCapture.getMediaStreamId", |
| 62 | + [ |
| 63 | + { |
| 64 | + targetTabId: tab.id, |
| 65 | + consumerTabId: tab.id, |
| 66 | + }, |
| 67 | + ] |
| 68 | + ); |
| 69 | + |
| 70 | + navigator.webkitGetUserMedia( |
| 71 | + { |
| 72 | + audio: false, |
| 73 | + video: { |
| 74 | + mandatory: { |
| 75 | + chromeMediaSource: "tab", // The media source must be 'tab' here. |
| 76 | + chromeMediaSourceId: streamId, |
| 77 | + minWidth: 50, |
| 78 | + minHeight: 50, |
| 79 | + // maxWidth: 1920, |
| 80 | + // maxHeight: 1080, |
| 81 | + minFrameRate: 10, |
| 82 | + maxFrameRate: 60, |
| 83 | + }, |
| 84 | + }, |
| 85 | + }, |
| 86 | + function (stream) { |
| 87 | + const video = document.createElement("video"); |
| 88 | + video.srcObject = stream; |
| 89 | + video.autoplay = true; |
| 90 | + video.style.display = "none"; |
| 91 | + video.addEventListener("enterpictureinpicture", () => {}); |
| 92 | + video.addEventListener("leavepictureinpicture", () => { |
| 93 | + leavePIP(); |
| 94 | + }); |
| 95 | + video.addEventListener( |
| 96 | + "canplay", |
| 97 | + function () { |
| 98 | + this.play(); |
| 99 | + enterPIP(stream, video); |
| 100 | + }, |
| 101 | + { once: true } |
| 102 | + ); |
| 103 | + document.body.appendChild(video); |
| 104 | + }, |
| 105 | + function (error) { |
| 106 | + alert("ERROR: " + error); |
| 107 | + console.log(error); |
| 108 | + } |
| 109 | + ); |
| 110 | + } catch (e) { |
| 111 | + alert(e); |
| 112 | + } |
| 113 | + }, |
| 114 | +}; |
0 commit comments