Skip to content

Commit

Permalink
Merge branch 'hotfix-0.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
ToranSharma committed May 19, 2020
2 parents f5d4829 + b586010 commit 76fb44d
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 37 deletions.
30 changes: 29 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@ Changelog
------------
-

[v0.0.2] - 2020-05-19
---------------------
[GitHub Release Page](https://github.com/ToranSharma/Xporcle-Extension/releases/tag/v0.0.2)
### Added
- Gecko browser specific settings extension ID for future Firefox storage API
support.
- Sending of a connection closed message from the background script to the
content script.
- Corresponding connection close message handing in the content script.
- Handling of quiz finished message to update internal state of the background
script.

### Fixed
- Handling of changing page while a quiz is being played.
- Resetting of internal state variables in background script.
- Missing declaration of interfaceContainer.
- Width of interfaceBox to account for differing scroll bar size in Firefox.
- Handling of start quiz messages when quiz is already running. This only really
affects the host of a room.
- Clipboard writing to support Firefox.

### Changed
- Content script renamed from script.js to xporcle.js.

### Removed
- Debugging console messages from content and background scripts.

[v0.0.1] - 2020-05-18
---------------------
[GitHub Release Page](https://github.com/ToranSharma/Xporcle-Extension/releases/tag/v0.0.1)
Expand All @@ -20,4 +47,5 @@ Changelog
- Options page popup placeholder.

[Unreleased]: https://github.com/ToranSharma/Xporcle-Extension/compare/master...develop
[v0.0.1]: https://github.com/ToranSharma/Xporcle-Extension/releases/tag/v1.0.0
[v0.0.2]: https://github.com/ToranSharma/Xporcle-Extension/compare/v0.0.1...v0.0.2
[v0.0.1]: https://github.com/ToranSharma/Xporcle-Extension/releases/tag/v0.0.1
24 changes: 12 additions & 12 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,14 @@ let playing = null;
chrome.runtime.onConnect.addListener(
(port) =>
{
console.log("Page connecting");
if (port.name === "messageRelay")
{
messagePort = port;
port.onMessage.addListener(
(message) =>
{
console.log("Page sent a message");
console.log(message);
if (message.type === "connectionStatus")
{
console.log("Page is asking about the connection status");
// Request to see if we are still connected to a room
if (ws !== null)
{
Expand Down Expand Up @@ -84,7 +80,7 @@ chrome.runtime.onConnect.addListener(

if (message.type === "live_scores_update")
{
playing = message["playing"]
playing = !message["finished"]
}
}
}
Expand All @@ -94,7 +90,6 @@ chrome.runtime.onConnect.addListener(
port.onDisconnect.addListener(
() =>
{
console.log("page disconnected");
messagePort = null;

if (playing)
Expand All @@ -112,8 +107,6 @@ chrome.runtime.onConnect.addListener(

function startConnection(initialMessage)
{
console.log("Connecting to server");

username = initialMessage.username;

if (initialMessage["code"] !== undefined)
Expand All @@ -129,7 +122,8 @@ function startConnection(initialMessage)
};
ws.onclose = (event) =>
{
console.log("connection closed");
if (messagePort != null)
messagePort.postMessage({type: "connection_closed"});
reset();
};
ws.onopen = (event) =>
Expand All @@ -143,7 +137,6 @@ function startConnection(initialMessage)
function forwardMessage(event)
{
const message = JSON.parse(event.data);
console.log(message);

messageType = message["type"];

Expand All @@ -159,13 +152,16 @@ function forwardMessage(event)
}
else if (messageType === "scores_update")
{
playing = false;
Object.assign(scores, message["scores"]);
scores = message["scores"];
}
else if (messageType === "start_quiz")
{
playing = true;
}
else if (messageType === "quiz_finished")
{
playing = false;
}
else if (messageType === "url_update")
{
urls[message["username"]] = message["url"];
Expand Down Expand Up @@ -195,4 +191,8 @@ function reset()
ws = null;
username = null;
roomCode = null;
host = null;
scores = {};
urls = {};
playing = null;
}
12 changes: 10 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name" : "Xporcle",
"description" : "Adds real-time multiplayer abilities to Sporcle.com",
"version" : "0.0.1",
"version" : "0.0.2",
"manifest_version" : 2,

"icons" : {
Expand Down Expand Up @@ -32,7 +32,7 @@
"content_scripts" : [
{
"matches" : ["https://www.sporcle.com/*"],
"js" : ["script.js"]
"js" : ["xporcle.js"]
}
],

Expand All @@ -42,4 +42,12 @@
"page" : "options.html",
"open_in_tab" : false
}
,
"browser_specific_settings":
{
"gecko":
{
"id": "[email protected]"
}
}
}
2 changes: 1 addition & 1 deletion options.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>Xporcle Options</title>
</head>
<body>
<h1>Xporcle <span id="version">v0.0.1</span></h1>
<h1>Xporcle <span id="version">v0.0.2</span></h1>
<h2>Enable or Disable Features Here</h2>
</body>
</html>
49 changes: 28 additions & 21 deletions script.js → xporcle.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ function addInterfaceBox()
const gameHeader = document.querySelector(`.game-header`);
const staffPicks = document.querySelector(`#staff-picks-wrapper`);

if (document.querySelector(`#interfaceContainer`) === null)
let interfaceContainer = document.querySelector(`#interfaceContainer`);
if (interfaceContainer === null)
{
const interfaceContainer = document.createElement("div");
interfaceContainer = document.createElement("div");
interfaceContainer.id = "interfaceContainer";
interfaceContainer.style =
`
Expand Down Expand Up @@ -152,7 +153,7 @@ function addInterfaceBox()
interfaceBox.id = "interfaceBox";
interfaceBox.style =
`
width: calc(((100vw - 960px) / 2 - 4px));
width: calc(((100vw - 960px) / 2 - 10px));
padding: 0.5em;
box-sizing: border-box;
max-width: 400px;
Expand Down Expand Up @@ -193,8 +194,6 @@ function resetInterface()

function processMessage(message)
{
console.log(message);

messageType = message["type"];

switch (messageType)
Expand All @@ -203,18 +202,16 @@ function processMessage(message)
updateLeaderboard(message["scores"]);
break;
case "room_closed":
console.log("room closed");
resetInterface();
break;
case "rooms_list":
console.log(message["rooms"]);
case "connection_closed":
resetInterface();
break;
case "error":
console.error(message["error"]);
break;
case "removed_from_room":
const removedUser = message["username"];
console.log(`${removedUser} removed from room`);
if (removedUser === username)
{
resetInterface();
Expand All @@ -227,9 +224,12 @@ function processMessage(message)
case "start_quiz":
// Start the quiz!

// First remove the quiz start provention
toggleQuizStartProvention(false);
document.querySelector(`#button-play`).click();
if (!quizRunning)
{
// First remove the quiz start provention
toggleQuizStartProvention(false);
document.querySelector(`#button-play`).click();
}
break;
case "live_scores_update":
updateLiveScores(message["live_scores"]);
Expand Down Expand Up @@ -293,8 +293,16 @@ async function createRoom(event, form)
return;
}

console.log("connection established.");
try
{
await navigator.clipboard.writeText(roomCode);
}
catch (error)
{
console.error("Clipboard write failure: ", error);
}

/* clipboard-write permissions query is only available in chrome
await navigator.permissions.query({name: "clipboard-write"}).then(
(result) =>
{
Expand All @@ -305,6 +313,7 @@ async function createRoom(event, form)
}
}
);
*/

interfaceBox.querySelectorAll(`form`).forEach(
(form) => form.remove()
Expand All @@ -326,8 +335,6 @@ async function joinRoom(event, form)
button.disabled = true;
button.value = "...";

console.log(`Trying to join room ${roomCode}`);

const message = {
type: "join_room",
username: username,
Expand Down Expand Up @@ -372,7 +379,6 @@ async function joinRoom(event, form)
return;
}

console.log("connection established");
onRoomConnect();
}

Expand Down Expand Up @@ -547,9 +553,6 @@ function updateLeaderboardUrls()

if (onQuizPage)
{
const playButton = document.querySelector("#button-play");
const playButtonContainer = playButton.parentNode.parentNode;

const allPlayersOnSamePage = ! Object.entries(urls).some(entry => entry[1] !== window.location.href);

toggleQuizStartProvention(allPlayersOnSamePage === false)
Expand All @@ -559,6 +562,12 @@ function updateLeaderboardUrls()
function toggleQuizStartProvention(prevent)
{
const playPadding = document.querySelector(`#playPadding`);
if (document.querySelector(`#button-play`) === null)
{
// No play button so no need to stop it being clicked, we have probably finished a quiz now.
return false;
}

if (prevent)
{
playPadding.addEventListener("click", stopQuizStart, true);
Expand Down Expand Up @@ -798,7 +807,6 @@ function quizStarted(mutationList)
{
// Quiz started
quizStartObserver.disconnect();
console.log("Quiz started");

quizRunning = true;
quizStartTime = new Date();
Expand Down Expand Up @@ -830,7 +838,6 @@ function quizFinished(mutationList)
if (mutation.target.getAttribute("style") !== null)
{
// Quiz finished
console.log("Quiz finished");

quizFinishObserver.disconnect();
scoreObserver.disconnect();
Expand Down

0 comments on commit 76fb44d

Please sign in to comment.