Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions css/wrapper.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
}

#top-layer {
position: inherit;
z-index: inherit;
height: inherit;
position: absolute;
height: 80%;
width: inherit;
z-index: auto;
}

#app {
Expand Down
2 changes: 1 addition & 1 deletion html/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<p id="start-stream"></p>
</div>
<div>
<i>Tips: You can hide the player with Alt+Maj+T</i>
<i>Tips: You can hide the player with Ctrl+Shift+Space</i>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From https://developer.chrome.com/apps/commands : Please note that on Mac 'Ctrl' is automatically converted to 'Command'. If you want 'Ctrl' instead, please specify 'MacCtrl' under "mac". Specifying 'MacCtrl' under "default" will cause the extension to be uninstallable.

We can't use this as CMD + Space triggers the spotlight search on macOs :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine, what do we use, then?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Please note that on Mac 'Ctrl' is automatically converted to 'Command'. If you want 'Ctrl' instead, please specify 'MacCtrl' under "mac". Specifying 'MacCtrl' under "default" will cause the extension to be uninstallable.

We could use ctrl + Shift + space for default and MaCtrl + Shift + Space for mac ?
What bothers me is that there is no easy way to remember this shortcut :(

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ImFlog you're right, let's discuss about it

</div>
<script src="../js/popup.js"></script>
</body>
Expand Down
8 changes: 5 additions & 3 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const pauseType = 'PAUSE_CHANNEL';
const hideType = 'HIDE_CHANNEL';
const changeHostType = 'CHANGE_HOST_CHANNEL';
const updatePlayerInfosType = 'UPDATE_PLAYER_INFOS';
const toggleCommand = 'toggle-display';

let currentChannel = '';
let isHidden = false;
Expand Down Expand Up @@ -113,15 +114,16 @@ function notifyContainerDeletion() {

// Player hidding feature
chrome.commands.onCommand.addListener(function (command) {
if (command === "toggle-display") {
console.info('Received command', command);
if (command === toggleCommand) {
isHidden = !isHidden
// Send a message to every content-script asking to pause and hide.
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
for (let i = 0; i < tabs.length; i++) {
chrome.tabs.sendMessage(
tabs[i].id,
{ type: hideType },
() => { }
() => {}
)
}
});
Expand All @@ -130,7 +132,7 @@ chrome.commands.onCommand.addListener(function (command) {
chrome.tabs.sendMessage(
tabs[i].id,
{ type: hideType },
() => { }
() => {}
)
}
})
Expand Down
26 changes: 17 additions & 9 deletions js/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const defaultHeight = '300';

function PlayerInfos () {
return {
x: 0,
y: 0,
x: 10,
y: 10,
width: defaultWidth,
height: defaultHeight
};
Expand All @@ -36,12 +36,12 @@ let startWidthResize, startHeightResize;
chrome.runtime.onMessage.addListener(function (message) {
if (message.type) {
if (message.type === createType) {
playerInfos = message.playerInfos || player;
playerInfos = message.playerInfos || playerInfos;
startVideo(message.text, message.isHidden);
} else if (message.type === removeType) {
clearPage();
} else if (message.type === pauseType) {
player.pause();
pausePlayer();
} else if (message.type === hideType) {
togglePlayer();
} else if (message.type === updatePlayerInfosType) {
Expand All @@ -51,6 +51,12 @@ chrome.runtime.onMessage.addListener(function (message) {
}
});

function pausePlayer(){
if (player) {
player.pause();
}
}

function startVideo(channelId, isHidden) {
let elem = document.getElementById(containerId);
if (elem === null) {
Expand All @@ -65,7 +71,7 @@ function startVideo(channelId, isHidden) {

function clearPage() {
let elem = document.getElementById(containerId);
if (elem != null) {
if (elem !== null) {
elem.parentNode.removeChild(elem);
}
player = null;
Expand All @@ -74,14 +80,14 @@ function clearPage() {

function togglePlayer() {
let elem = document.getElementById(containerId);
if (elem) {
if (!!elem) {
if (elem.style.display === 'none') {
// Show player
player.play();
elem.style.display = 'block'
} else {
// Hide player
player.pause();
pausePlayer();
elem.style.display = 'none'
}
}
Expand All @@ -103,7 +109,6 @@ function updatePlayerInfos() {
playerInfos.x = clientRect.left;
playerInfos.y = clientRect.top;

console.info('sending player infos', playerInfos);
chrome.runtime.sendMessage({ type: updatePlayerInfosType, playerInfos });
}
}
Expand Down Expand Up @@ -220,12 +225,15 @@ function createContainer(channelId, isHidden) {
player = embed.getPlayer();
player.play();
});
embed.addEventListener(Twitch.Embed.VIDEO_PLAY, () => {

embed.addEventListener(Twitch.Embed.VIDEO_PLAY, (e) => {
if (channelId !== player.getChannel()) {
chrome.runtime.sendMessage({ type: changeHostType, channelId: player.getChannel() });
}
});
}


/*
* Code from https://medium.com/the-z/making-a-resizable-div-in-js-is-not-easy-as-you-think-bda19a1bc53d
*/
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"commands": {
"toggle-display": {
"suggested_key": {
"default": "Alt+Shift+T"
"default": "Ctrl+Shift+Space"
},
"description": "Toggle Twitch Iframe display"
}
Expand Down