feat: new "time played" feature (a bit buggy right now)
This commit is contained in:
parent
80d223e4d1
commit
9f49fc848d
4 changed files with 82 additions and 3 deletions
|
|
@ -95,7 +95,8 @@ const DefaultSettings = {
|
|||
ProgressBarOn: true,
|
||||
PercentageOn: true,
|
||||
OpacityOn: true
|
||||
}
|
||||
},
|
||||
TimePlayedOn: true
|
||||
}
|
||||
|
||||
// ON EXTENSION INSTALL / RELOAD
|
||||
|
|
@ -108,9 +109,47 @@ chrome.runtime.onInstalled.addListener(() => {
|
|||
})
|
||||
});
|
||||
|
||||
let RecordingTimePlayed = false
|
||||
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
|
||||
if (request.action === 'reload') {
|
||||
chrome.runtime.reload();
|
||||
} else if (request.action === 'start_time_played') {
|
||||
if (RecordingTimePlayed === true) {
|
||||
console.log('Time Played: Already Started Interval')
|
||||
return
|
||||
}
|
||||
RecordingTimePlayed = true
|
||||
|
||||
chrome.storage.sync.get(['PolyPlus_TimePlayed'], function(result){
|
||||
console.log('Time Played: Start Interval')
|
||||
|
||||
const Playtime = result.PolyPlus_TimePlayed || {
|
||||
[request.placeID]: 0
|
||||
};
|
||||
let LoadedIn = false
|
||||
const TimePlayedInterval = setInterval(async () => {
|
||||
console.log('Time Played: Run Check')
|
||||
const PlaceStatus = (await (await fetch('https://api.polytoria.com/v1/users/' + request.userID)).json()).playing
|
||||
|
||||
if (PlaceStatus === null) {
|
||||
console.log('Time Played: Not Playing Anything')
|
||||
if (LoadedIn === true) {
|
||||
console.log('Time Played: End Interval')
|
||||
clearInterval(TimePlayedInterval)
|
||||
}
|
||||
} else {
|
||||
LoadedIn = true
|
||||
if (!Playtime[PlaceStatus.placeID]) {
|
||||
Playtime[PlaceStatus.placeID] = 0
|
||||
}
|
||||
Playtime[PlaceStatus.placeID] += 5
|
||||
console.log('Time Played: Time Increase: ', new Date(Playtime[PlaceStatus.placeID] * 1000).toISOString().slice(11, 19), PlaceStatus)
|
||||
chrome.storage.sync.set({'PolyPlus_TimePlayed': Playtime}, function(){
|
||||
console.log('Time Played: Saved Playtime')
|
||||
})
|
||||
}
|
||||
}, 5000);
|
||||
})
|
||||
} else if (request.action === 'greatdivide_stats') {
|
||||
chrome.storage.local.get(['PolyPlus_GreatDivideStats_' + request.userID], async function(result){
|
||||
let Statistics = result['PolyPlus_GreatDivideStats_' + request.userID]
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ let Utilities;
|
|||
let PlaceDetails = null;
|
||||
|
||||
var Settings;
|
||||
let TimePlayed;
|
||||
var PinnedGamesData = [];
|
||||
let GamePinned;
|
||||
|
||||
|
|
@ -45,8 +46,9 @@ const Gamepasses = Array.from(GamepassesTab.getElementsByClassName('card')) || [
|
|||
|
||||
RatingsContainer.children[0].appendChild(PercentageLabel);
|
||||
|
||||
chrome.storage.sync.get(['PolyPlus_Settings'], async function (result) {
|
||||
chrome.storage.sync.get(['PolyPlus_Settings', 'PolyPlus_TimePlayed'], async function (result) {
|
||||
Settings = result.PolyPlus_Settings || {};
|
||||
TimePlayed = result.PolyPlus_TimePlayed || {};
|
||||
|
||||
Utilities = await import(chrome.runtime.getURL('resources/utils.js'));
|
||||
Utilities = Utilities.default;
|
||||
|
|
@ -72,6 +74,25 @@ const Gamepasses = Array.from(GamepassesTab.getElementsByClassName('card')) || [
|
|||
IRLPrice();
|
||||
}
|
||||
|
||||
if (Settings.TimePlayedOn === true) {
|
||||
const TimePlayedNameRow = document.createElement('li');
|
||||
TimePlayedNameRow.innerText = 'Time Played:';
|
||||
|
||||
const TimePlayedValueRow = document.createElement('li')
|
||||
if (TimePlayed[PlaceID]) {
|
||||
TimePlayedValueRow.innerText = new Date(TimePlayed[PlaceID] * 1000).toISOString().slice(11, 19)
|
||||
} else {
|
||||
TimePlayedValueRow.innerText = '-'
|
||||
}
|
||||
|
||||
InfoColumns[0].appendChild(TimePlayedNameRow);
|
||||
InfoColumns[1].appendChild(TimePlayedValueRow);
|
||||
|
||||
document.getElementById('btn-play').addEventListener('click', function(){
|
||||
chrome.runtime.sendMessage({ action: "start_time_played", placeID: PlaceID, userID: UserID })
|
||||
})
|
||||
}
|
||||
|
||||
if (Settings.ShowPlaceRevenueOn === true) {
|
||||
const NameRow = document.createElement('li');
|
||||
NameRow.innerText = 'Revenue:';
|
||||
|
|
|
|||
|
|
@ -115,7 +115,8 @@ export default {
|
|||
ProgressBarOn: true,
|
||||
PercentageOn: true,
|
||||
OpacityOn: true
|
||||
}
|
||||
},
|
||||
TimePlayedOn: true
|
||||
},
|
||||
Limits: {
|
||||
PinnedGames: 10,
|
||||
|
|
|
|||
|
|
@ -777,6 +777,24 @@
|
|||
* This feature does not make it possible to set your place(s) as "copyable"
|
||||
</span>
|
||||
</div>
|
||||
<div class="setting-container" id="time-played">
|
||||
<span class="badge bg-primary mb-1">New in v1.3!</span>
|
||||
<br>
|
||||
<span class="indicator"> </span>
|
||||
<span class="title">
|
||||
Time Played
|
||||
</span>
|
||||
<div class="setting-buttons">
|
||||
<button class="btn btn-sm toggle-btn" data-setting="TimePlayedOn">Toggle</button>
|
||||
</div>
|
||||
<br />
|
||||
<span class="desc">
|
||||
Track your playtime in places around Polytoria!
|
||||
</span>
|
||||
<span class="warning">
|
||||
* Past playtime data (prior to extension install/prior to setting enable) is, understandably, not able to be tracked
|
||||
</span>
|
||||
</div>
|
||||
<!---
|
||||
<div class="setting-container" id="auto-ad-bidding">
|
||||
<span class="indicator"> </span>
|
||||
|
|
|
|||
Reference in a new issue