Skip to content

Commit 1267ca1

Browse files
Merge pull request #2 from mikesingleton/1.1.6
v1.1.6
2 parents 7ec7988 + b4a7633 commit 1267ca1

6 files changed

Lines changed: 184 additions & 10 deletions

File tree

app/extension/html/popup.html

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,43 @@
2222
</svg>
2323
</div>
2424
<div id="popupBox">
25-
<div class="if">
25+
<div id="if-title" class="if" style="cursor: pointer;">
2626
Internet Friends
2727
</div>
2828
<div id="website" class="website">
2929
website.com
3030
</div>
31-
<table class="table">
31+
<table id="pauseTable" class="table">
32+
<tr>
33+
<td>
34+
Internet Friends is paused...
35+
</td>
36+
</tr>
37+
<tr>
38+
<td>
39+
<span id="countdownTimer"></span>
40+
</td>
41+
</tr>
42+
<tr><td></td></tr>
43+
<tr>
44+
<td style="justify-content: space-between;">
45+
Add Time
46+
<div style="display: flex;">
47+
<button id="pause15m" class="pauseButton">15m</button>
48+
<button id="pause3h" class="pauseButton">3h</button>
49+
<button id="pause24h" class="pauseButton">24h</button>
50+
</div>
51+
</td>
52+
</tr>
53+
<tr>
54+
<td>
55+
<button id="unpauseButton" class="unpauseButton">
56+
Unpause Internet Friends
57+
</button>
58+
</td>
59+
</tr>
60+
</table>
61+
<table id="settingsTable" class="table" style="display: hidden">
3262
<tr>
3363
<td>
3464
Enable for this website
@@ -61,6 +91,16 @@
6191
</button>
6292
</td>
6393
</tr>
94+
<tr>
95+
<td>
96+
Pause extension
97+
<div style="display: flex;">
98+
<button id="pause15m" class="pauseButton">15m</button>
99+
<button id="pause3h" class="pauseButton">3h</button>
100+
<button id="pause24h" class="pauseButton">24h</button>
101+
</div>
102+
</td>
103+
</tr>
64104
</table>
65105
<div id="refresh" class="refresh">
66106
Refresh for changes to take effect

app/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "__MSG_appName__",
3-
"version": "1.1.5",
3+
"version": "1.1.6",
44
"manifest_version": 3,
55
"description": "__MSG_appDescription__",
66
"icons": {

app/scripts.babel/inject.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,17 @@ var Inject = (function() {
4747

4848
_this.init = function() {
4949
Logger.log(`Internet Friends Initializing Room "${window.location.host + window.location.pathname} : ${document.title}"`);
50+
51+
// if InternetFriends is paused, return
52+
if (IFSettings.pausedUntil > Date.now()) {
53+
Logger.log('Internet Friends is paused. Exiting.');
54+
return;
55+
}
5056

5157
// if websiteUrl is present in disabledSites, InternetFriends is disabled for this site, return
5258
let websiteUrl = window.location.host;
5359
if (IFSettings.disabledSites[websiteUrl]) {
54-
Logger.log('Website is disabled. Exiting.');
60+
Logger.log('Website is disabled in Internet Friends settings. Exiting.');
5561
return;
5662
}
5763

@@ -230,7 +236,7 @@ if (isWebRTCSupported) {
230236
// else, init now
231237
Inject.tryInit();
232238
}
233-
}, false);
239+
}, { once: true });
234240
} else {
235241
console.log("InternetFriends does not work without WebRTC support!"); // use console log here so it's logged regardless of whether general logging is enabled
236242
}

app/scripts.babel/popup.js

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33
var Popup = (function() {
44
// variables ----------------------------------------------------------------
55
var _this = {},
6+
_settingsTable = null,
7+
_title = null,
68
_website = null,
79
_websiteUrl = null,
810
_enableForSite = null,
911
_enableChat = null,
1012
_keyComboInput = null,
1113
_settingsTimeout = null,
12-
_userColor = null;
14+
_userColor = null,
15+
_pauseTable = null,
16+
_countdownTimeout = null,
17+
_pausedUntil = null,
18+
_pausedUntilTimeout = null;
1319

1420
// initialize ---------------------------------------------------------------
1521
_this.init = function() {
@@ -20,10 +26,19 @@ var Popup = (function() {
2026

2127
// Get document elements
2228

29+
_title = document.getElementById('if-title');
2330
_website = document.getElementById('website');
2431
_enableForSite = document.getElementById('enableForSite');
2532
_enableChat = document.getElementById('enableChat');
2633
_keyComboInput = document.getElementById('keyComboInput');
34+
_pauseTable = document.getElementById('pauseTable');
35+
_settingsTable = document.getElementById('settingsTable');
36+
37+
// Set website click event
38+
39+
_title.addEventListener('click', function () {
40+
window.open('https://internetfriends.social', '_blank');
41+
});
2742

2843
// Populate values
2944

@@ -102,6 +117,21 @@ var Popup = (function() {
102117

103118
_cursorColorButton.addEventListener("click", onCursorButtonClicked);
104119
_colorWheelContainerBackground.addEventListener("click", onPopupContainerClicked);
120+
121+
// Handle Pause Timer
122+
123+
_pausedUntil = IFSettings.pausedUntil
124+
setupPauseButtons();
125+
126+
// Handle Table Display
127+
128+
// if currently paused
129+
if (_pausedUntil > Date.now()) {
130+
_settingsTable.classList.add("hidden");
131+
updateCountdown();
132+
} else {
133+
_pauseTable.classList.add("hidden");
134+
}
105135
};
106136

107137
// private functions --------------------------------------------------------
@@ -208,6 +238,79 @@ var Popup = (function() {
208238
_refreshText.style.visibility = "visible";
209239
};
210240

241+
function updateCountdown() {
242+
var countdownTimer = document.getElementById('countdownTimer');
243+
const timeLeft = _pausedUntil - new Date().getTime();
244+
245+
if (timeLeft <= 0) {
246+
_pauseTable.classList.add("hidden");
247+
_settingsTable.classList.remove("hidden");
248+
clearTimeout(_countdownTimeout);
249+
} else {
250+
const days = Math.floor(timeLeft / (24 * 60 * 60 * 1000));
251+
const hours = Math.floor((timeLeft % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000));
252+
const minutes = Math.floor((timeLeft % (60 * 60 * 1000)) / (60 * 1000));
253+
const seconds = Math.floor((timeLeft % (60 * 1000)) / 1000);
254+
255+
countdownTimer.textContent = `${days}d ${hours}h ${minutes}m ${seconds}s`;
256+
_countdownTimeout = setTimeout(updateCountdown, 1000);
257+
}
258+
}
259+
260+
function setupPauseButtons() {
261+
var pauseButtons = document.querySelectorAll(".pauseButton");
262+
var unpauseButton = document.getElementById('unpauseButton');
263+
264+
pauseButtons.forEach(button => {
265+
button.addEventListener("click", function() {
266+
const duration = button.id === "pause15m" ? 15 * 60 * 1000 : // 15m
267+
button.id === "pause3h" ? 3 * 60 * 60 * 1000 : // 3h
268+
24 * 60 * 60 * 1000; // 24hr
269+
270+
// Clear any existing countdown
271+
if (_countdownTimeout) {
272+
clearTimeout(_countdownTimeout);
273+
}
274+
275+
// If extension is already paused
276+
if (_pausedUntil > new Date().getTime()) {
277+
// Add time
278+
_pausedUntil += duration
279+
} else {
280+
// Set time
281+
_pausedUntil = new Date().getTime() + duration
282+
283+
// Set refresh text
284+
var _refreshText = document.getElementById('refresh');
285+
_refreshText.style.visibility = "visible";
286+
}
287+
288+
// use timeout to prevent settings from being updated too quickly
289+
if (_pausedUntilTimeout)
290+
clearTimeout(_pausedUntilTimeout);
291+
_pausedUntilTimeout = setTimeout(updatePausedUntil, 100);
292+
_pauseTable.classList.remove("hidden");
293+
_settingsTable.classList.add("hidden");
294+
295+
updateCountdown();
296+
});
297+
});
298+
299+
unpauseButton.addEventListener("click", function() {
300+
_pausedUntil = -1
301+
updatePausedUntil();
302+
_pauseTable.classList.add("hidden");
303+
_settingsTable.classList.remove("hidden");
304+
305+
var _refreshText = document.getElementById('refresh');
306+
_refreshText.style.visibility = "visible";
307+
});
308+
}
309+
310+
function updatePausedUntil () {
311+
chrome.storage.sync.set({'pausedUntil': _pausedUntil});
312+
}
313+
211314
return _this;
212315
}());
213316

app/scripts.babel/settings.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ var IFEvents = new EventTarget();
3434
combo: storedSettings?.combo || _defaultCombo,
3535
disabledSites: storedSettings?.disabledSites || {},
3636
enableChat: storedSettings?.enableChat === true || storedSettings?.enableChat === undefined,
37-
userColor: storedSettings?.userColor || getRandomIroColor()
37+
userColor: storedSettings?.userColor || getRandomIroColor(),
38+
pausedUntil: storedSettings?.pausedUntil || -1
3839
}
3940

4041
// set new settings
@@ -66,7 +67,8 @@ var IFEvents = new EventTarget();
6667
combo: _defaultCombo,
6768
disabledSites: {},
6869
enableChat: true,
69-
userColor: getRandomIroColor()
70+
userColor: getRandomIroColor(),
71+
pausedUntil: -1
7072
}
7173

7274
IFEvents.dispatchEvent(initEvent);

app/styles/popup.css

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@
99
body {
1010
text-align: center;
1111
width: 314px;
12-
height: 282px;
12+
height: 318px;
1313
overflow: hidden;
1414
margin: auto;
1515
user-select: none;
1616
}
1717

18+
.hidden {
19+
display: none;
20+
}
21+
1822
.popupContainer {
1923
position: absolute;
2024
width: 314px;
21-
height: 282px;
25+
height: 318px;
2226
}
2327

2428
table {
@@ -34,9 +38,16 @@ td {
3438
height: 34px;
3539
align-items: center;
3640
display: flex;
41+
}
42+
43+
#settingsTable td {
3744
justify-content: space-between;
3845
}
3946

47+
#pauseTable td {
48+
justify-content: center;
49+
}
50+
4051
#keyComboInput {
4152
width: 146px;
4253
}
@@ -111,6 +122,18 @@ td {
111122
cursor: pointer;
112123
}
113124

125+
.pauseButton {
126+
font-size: 10px;
127+
font-weight: bold;
128+
width: 30px;
129+
height: 30px;
130+
justify-content: center;
131+
align-items: center;
132+
display: flex;
133+
font-family: "Open Sans",Verdana,Geneva,Tahoma,sans-serif;
134+
margin-left: 5px;
135+
}
136+
114137
.popup {
115138
position: relative;
116139
display: inline-block;

0 commit comments

Comments
 (0)