Skip to content

Commit

Permalink
Clean up background.js code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotwaite committed Jan 29, 2024
1 parent 94c860e commit 0b2d23b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 40 deletions.
41 changes: 21 additions & 20 deletions extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

let cache = {}
let cacheTimes = []
let cacheDuration = 600000 // Default is 10 mins.
let cacheDuration = 600000 // Default is 10 mins.

chrome.runtime.onInstalled.addListener(() => {
chrome.storage.sync.get({cacheDuration: 600000}, function(settings) {
chrome.storage.sync.get({ cacheDuration: 600000 }, function (settings) {
if (settings && settings.cacheDuration !== undefined) {
cacheDuration = settings.cacheDuration
}
Expand Down Expand Up @@ -38,24 +38,25 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
}

// Otherwise, fetch new data and cache it.
fetch('https://returnyoutubedislikeapi.com/Votes?videoId=' + message.videoId)
.then(response => {
if (!response.ok) {
sendResponse(null)
} else {
response.json().then(data => {
const likesData = {
'likes': data.likes,
'dislikes': data.dislikes,
}
if (!(message.videoId in cache)) {
cache[message.videoId] = likesData
cacheTimes.push([Date.now(), message.videoId])
}
sendResponse(likesData)
})
}
})
fetch(
'https://returnyoutubedislikeapi.com/Votes?videoId=' + message.videoId,
).then((response) => {
if (!response.ok) {
sendResponse(null)
} else {
response.json().then((data) => {
const likesData = {
likes: data.likes,
dislikes: data.dislikes,
}
if (!(message.videoId in cache)) {
cache[message.videoId] = likesData
cacheTimes.push([Date.now(), message.videoId])
}
sendResponse(likesData)
})
}
})

// Returning `true` signals to the browser that we will send our
// response asynchronously using `sendResponse()`.
Expand Down
41 changes: 21 additions & 20 deletions manifest-v2/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

let cache = {}
let cacheTimes = []
let cacheDuration = 600000 // Default is 10 mins.
let cacheDuration = 600000 // Default is 10 mins.

chrome.storage.local.get({cacheDuration: 600000}, function(settings) {
chrome.storage.local.get({ cacheDuration: 600000 }, function (settings) {
if (settings && settings.cacheDuration !== undefined) {
cacheDuration = settings.cacheDuration
}
Expand Down Expand Up @@ -36,24 +36,25 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
}

// Otherwise, fetch new data and cache it.
fetch('https://returnyoutubedislikeapi.com/Votes?videoId=' + message.videoId)
.then(response => {
if (!response.ok) {
sendResponse(null)
} else {
response.json().then(data => {
const likesData = {
'likes': data.likes,
'dislikes': data.dislikes,
}
if (!(message.videoId in cache)) {
cache[message.videoId] = likesData
cacheTimes.push([Date.now(), message.videoId])
}
sendResponse(likesData)
})
}
})
fetch(
'https://returnyoutubedislikeapi.com/Votes?videoId=' + message.videoId,
).then((response) => {
if (!response.ok) {
sendResponse(null)
} else {
response.json().then((data) => {
const likesData = {
likes: data.likes,
dislikes: data.dislikes,
}
if (!(message.videoId in cache)) {
cache[message.videoId] = likesData
cacheTimes.push([Date.now(), message.videoId])
}
sendResponse(likesData)
})
}
})

// Returning `true` signals to the browser that we will send our
// response asynchronously using `sendResponse()`.
Expand Down

0 comments on commit 0b2d23b

Please sign in to comment.