Skip to content

Commit

Permalink
added RatingSwitch setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamlinerm committed Sep 15, 2023
1 parent 7e3d53d commit aebe5e9
Show file tree
Hide file tree
Showing 16 changed files with 263 additions and 468 deletions.
8 changes: 7 additions & 1 deletion chrome/_locales/de/messages.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extensionName": {
"message": "Streaming enhanced Netflix Disney Prime Video",
"message": "Streaming enhanced: Netflix Disney+ Prime Video",
"description": "Name der Erweiterung"
},
"extensionDescription": {
Expand Down Expand Up @@ -225,5 +225,11 @@
},
"conflictingTitle": {
"message": "Alle widersprüchlichen Funktionen"
},
"RatingSwitch": {
"message": "IMDB Bewertung:"
},
"RatingSwitchDescription": {
"message": "Zeigt die IMDB Bewertung für jeden film/serie an"
}
}
8 changes: 7 additions & 1 deletion chrome/_locales/en/messages.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extensionName": {
"message": "Streaming enhanced Netflix Disney Prime Video",
"message": "Streaming enhanced: Netflix Disney+ Prime Video",
"description": "Name of the extension"
},
"extensionDescription": {
Expand Down Expand Up @@ -225,5 +225,11 @@
},
"conflictingTitle": {
"message": "All conflicting Features"
},
"RatingSwitch": {
"message": "IMDB Rating:"
},
"RatingSwitchDescription": {
"message": "Adding the IMDB rating to every movie and series"
}
}
24 changes: 23 additions & 1 deletion chrome/_locales/mk/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
"message": "Прескокни го предупредувањето за дали сè уште гледате:"
},
"InactivitySwitchDescription": {
"message": "Го продолжува видеото ако се прикаже известувањето Дали сè уште гледате."
"message": "Го продолжува видеото ако се прикаже известувањето "Дали сè уште гледате"."
},
"ProfileSwitch": {
"message": "Автоматски избирање на последниот одберен профил на Netflix:"
Expand Down Expand Up @@ -209,5 +209,27 @@
},
"noWrap": {
"message": "unset"
},

"WatchCreditsSwitch": {
"message": "Прикажи кредити:"
},
"WatchCreditsSwitchDescription": {
"порака": "Секогаш гледај ги завршните наслови на секоја серија"
},
"gotoIndividual": {
"порака": "За индивидуалните поставки на услугата за стриминг, одете на "
},
"extendedSettings": {
"порака": "напредни поставки"
},
"conflictingTitle": {
"порака": "Сите конфликтни функции"
},
"RatingSwitch": {
"порака": "Оцена на ИМДБ:"
},
"RatingSwitchDescription": {
"порака": "Го прикажува рејтингот на IMDB за секој филм/серија"
}
}
9 changes: 8 additions & 1 deletion chrome/popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<img class="Logo" src="../icons/NetflixAmazon Auto-Skip.svg" />
<div class="flex-center flex-col">
<h2 class="title" i18n>pageTitle</h2>
<p style="color: grey; font-size: 1em">v.1.0.55</p>
<p style="color: grey; font-size: 1em">v.1.0.58</p>
</div>
</div>
<a
Expand Down Expand Up @@ -117,6 +117,13 @@ <h2 id="openVideoSettings" i18n>SharedPageTitle</h2>
<span class="slider round"></span>
</label>
</div>
<div class="line flex">
<p i18n>RatingSwitch</p>
<label class="switch" style="margin-left: 5px">
<input type="checkbox" id="VideoShowRating" />
<span class="slider round"></span>
</label>
</div>
<div class="line" style="width: 350px"><i18n>gotoIndividual</i18n><a href="settings.html" target="_blank" style="color: white" i18n>extendedSettings</a></div>
</div>
</div>
Expand Down
12 changes: 11 additions & 1 deletion chrome/popup/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,16 @@ <h2 i18n>SharedPageTitle</h2>
</label>
</div>
<p class="description" i18n>FullscreenSwitchDescription</p>
<hr />
<div class="line flex">
<p i18n>RatingSwitch</p>
<label class="switch" style="margin-left: 5px">
<input type="checkbox" id="VideoShowRating" />
<span class="slider round"></span>
</label>
</div>
<p class="description" i18n>RatingSwitchDescription</p>
<div style="margin-top: 5%"></div>
</div>
<div class="categoryPrime hidden" style="margin-top: 0; background-color: unset" id="AmazonSettings">
<div class="flex flex-between" style="padding: 5px 5px; color: #00aeef">
Expand Down Expand Up @@ -613,7 +623,7 @@ <h2 i18n>ImportSettings</h2>
<h2>Changelog</h2>
<div>
<div class="line flex">
<h2>1.0.58</h2>
<h2>1.0.56,57</h2>
<ul>
<li>Improved Freevee Ad skip</li>
</ul>
Expand Down
26 changes: 14 additions & 12 deletions chrome/popup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const defaultSettings = {
Amazon: { skipIntro: true, skipCredits: true, watchCredits: false, skipAd: true, blockFreevee: true, speedSlider: true, filterPaid: false },
Netflix: { skipIntro: true, skipRecap: true, skipCredits: true, watchCredits: false, skipBlocked: true, NetflixAds: true, speedSlider: true, profile: true },
Disney: { skipIntro: true, skipCredits: true, watchCredits: false, speedSlider: true },
Video: { playOnFullScreen: true },
Video: { playOnFullScreen: true, showRating: true },
Statistics: { AmazonAdTimeSkipped: 0, NetflixAdTimeSkipped: 0, IntroTimeSkipped: 0, RecapTimeSkipped: 0, SegmentsSkipped: 0 },
General: { profileName: null, profilePicture: null, sliderSteps: 1, sliderMin: 5, sliderMax: 20 },
},
Expand Down Expand Up @@ -146,7 +146,9 @@ function setCheckboxesToSettings() {
settings?.Netflix.speedSlider &&
settings?.Disney.speedSlider &&
// playOnFullScreen
settings?.Video.playOnFullScreen;
settings?.Video.playOnFullScreen &&
// showRating
settings?.Video.showRating;
button = document.querySelector("#VideoIntro");
if (button) button.checked = settings?.Amazon.skipIntro && settings?.Netflix.skipIntro && settings?.Disney.skipIntro;
button = document.querySelector("#VideoCredits");
Expand All @@ -161,6 +163,8 @@ function setCheckboxesToSettings() {
if (button) button.checked = settings?.Amazon.speedSlider && settings?.Netflix.speedSlider && settings?.Disney.speedSlider;
button = document.querySelector("#VideoFullScreen");
if (button) button.checked = settings?.Video.playOnFullScreen;
button = document.querySelector("#VideoShowRating");
if (button) button.checked = settings?.Video.showRating;

// ------------- Default ---------------------------------------
button = document.querySelector("#DefaultSkips");
Expand Down Expand Up @@ -226,10 +230,6 @@ function setCheckboxesToSettings() {
button = document.querySelector("#DisneySpeedSlider");
if (button) button.checked = settings?.Disney.speedSlider;

// general video settings
button = document.querySelector("#playOnFullScreen");
if (button) button.checked = settings?.Video.playOnFullScreen;

// ------------- Slider Options ---------------------------------------
button = document.querySelector("#SliderSteps");
if (button) button.value = settings?.General.sliderSteps;
Expand Down Expand Up @@ -345,7 +345,9 @@ function listenForClicks() {
settings?.Netflix.speedSlider &&
settings?.Disney.speedSlider &&
// playOnFullScreen
settings?.Video.playOnFullScreen
settings?.Video.playOnFullScreen &&
// showRating
settings?.Video.showRating
);
settings.Amazon.skipIntro =
settings.Netflix.skipIntro =
Expand All @@ -363,6 +365,8 @@ function listenForClicks() {
settings.Disney.speedSlider =
// playOnFullScreen
settings.Video.playOnFullScreen =
// showRating
settings.Video.showRating =
VideoSkips;
if (VideoSkips) settings.Amazon.watchCredits = settings.Netflix.watchCredits = settings.Disney.watchCredits = false;
setSettings("All VideoSkips");
Expand Down Expand Up @@ -395,6 +399,9 @@ function listenForClicks() {
} else if (e.target.id === "VideoFullScreen") {
settings.Video.playOnFullScreen = !settings.Video.playOnFullScreen;
setSettings("playOnFullScreen");
} else if (e.target.id === "VideoShowRating") {
settings.Video.showRating = !settings.Video.showRating;
setSettings("showRating");
}

// ------------- Default ---------------------------------------
Expand Down Expand Up @@ -497,11 +504,6 @@ function listenForClicks() {
settings.Disney.speedSlider = !settings.Disney.speedSlider;
setSettings("DisneySpeedSlider");
}
// ------------- Video ---------------------------------------
else if (e.target.id === "playOnFullScreen") {
settings.video.playOnFullScreen = !settings.video.playOnFullScreen;
setSettings("playOnFullScreen");
}
// ------------- Statistics ---------------------------------------
else if (e.target.id === "upload") {
// get the file from #file and console.log it
Expand Down
113 changes: 112 additions & 1 deletion chrome/skipper.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
Amazon: { skipIntro: true, skipCredits: true, watchCredits: false, skipAd: true, blockFreevee: true, speedSlider: true, filterPaid: false },
Netflix: { skipIntro: true, skipRecap: true, skipCredits: true, watchCredits: false, skipBlocked: true, NetflixAds: true, speedSlider: true, profile: true },
Disney: { skipIntro: true, skipCredits: true, watchCredits: false, speedSlider: true },
Video: { playOnFullScreen: true },
Video: { playOnFullScreen: true, showRating: true },
Statistics: { AmazonAdTimeSkipped: 0, NetflixAdTimeSkipped: 0, IntroTimeSkipped: 0, RecapTimeSkipped: 0, SegmentsSkipped: 0 },
General: { profileName: null, profilePicture: null, sliderSteps: 1, sliderMin: 5, sliderMax: 20 },
},
Expand Down Expand Up @@ -85,6 +85,7 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
if (settings.Disney?.speedSlider) startDisneySpeedSliderObserver();
}
if (settings.Video.playOnFullScreen) startPlayOnFullScreen(isNetflix);
if (settings.Video?.showRating) startShowRatingInterval();
// if there is an undefined setting, set it to the default
let changedSettings = false;
for (const key in defaultSettings.settings) {
Expand Down Expand Up @@ -139,12 +140,22 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
if (oldValue === undefined || newValue.Disney.speedSlider !== oldValue.Disney?.speedSlider) startDisneySpeedSliderObserver();
}
if (oldValue === undefined || newValue.Video.playOnFullScreen !== oldValue.Video?.playOnFullScreen) startPlayOnFullScreen(isNetflix);
if (oldValue === undefined || newValue.Video.showRating !== oldValue.Video?.showRating) startShowRatingInterval();
if (oldValue === undefined || settings.Statistics.SegmentsSkipped === 0) {
resetBadge();
}
}
}
});
let DBCache = {};
chrome.storage.local.get("DBCache", function (result) {
DBCache = result?.DBCache;
if (typeof DBCache !== "object") {
console.log("DBCache not found, creating new one", DBCache);
chrome.storage.local.set({ DBCache: {} });
DBCache = {};
}
});
function addIntroTimeSkipped(startTime, endTime) {
if (typeof startTime === "number" && typeof endTime === "number" && endTime > startTime) {
log("Intro Time skipped", endTime - startTime);
Expand All @@ -164,11 +175,94 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
const date = new Date();
console.log(date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(), ...args);
}
// set DB Cache if cache size under 2MB
function setDBCache() {
const size = new TextEncoder().encode(JSON.stringify(DBCache)).length;
const kiloBytes = size / 1024;
const megaBytes = kiloBytes / 1024;
if (megaBytes < 2) {
chrome.storage.local.set({ DBCache });
} else {
log("DBCache cleared", megaBytes);
DBCache = {};
chrome.storage.local.set({ DBCache });
}
// log(megaBytes);
// chrome.storage.local.get("DBCache", function (result) {
// console.log(JSON.stringify(result?.DBCache));
// });
// console.log(JSON.stringify(DBCache));
}
// justWatchAPI
async function getMovieInfo(movieTitle, locale = "en_US") {
// console.log("getMovieInfo", movieTitle);
const url = `https://apis.justwatch.com/content/titles/${locale}/popular?language=en&body={"page_size":1,"page":1,"query":"${movieTitle}","content_types":["show","movie"]}`;
const response = await fetch(encodeURI(url));
const data = await response.json();
if (data) {
// "https://www.justwatch.com" + data.items[0].full_path;
const justWatchURL = data?.items?.[0]?.full_path;
// flatrate = free with subscription (netflix, amazon prime, disney+)
let offers = data?.items?.[0].offers?.filter((x) => x.monetization_type == "flatrate" && (x.package_short_name == "amp" || x.package_short_name == "nfx" || x.package_short_name == "dnp"));
// get the first offer of each provider
offers = offers?.filter((x, i) => offers.findIndex((y) => y.provider_id == x.provider_id) == i);
// map offers to only package_short_name, country and standard_web url
offers = offers?.map((x) => ({ country: x.country, package_short_name: x.package_short_name, url: x.urls.standard_web }));
return {
jWURL: justWatchURL,
score: data?.items?.[0]?.scoring?.filter((x) => x.provider_type == "imdb:score")?.[0]?.value,
streamLinks: offers,
};
}
return null;
}

// Observers
// default Options for the observer (which mutations to observe)
const config = { attributes: true, childList: true, subtree: true };

// shared functions
async function JustWatch() {
let titleCards;
if (isNetflix) titleCards = document.querySelectorAll(".title-card .boxart-container:not(.imdb)");
else titleCards = document.querySelectorAll("li:not(.imdb) [data-card-title]");
titleCards.forEach((card) => {
// let card = document.querySelector(".title-card .boxart-container");
let title;
if (isNetflix) title = card.children?.[1]?.firstChild?.textContent;
// remove everything after - in the title
else title = card.getAttribute("data-card-title").split(" - ")[0].split(" – ")[0]; //Amazon
if (title && !title.includes("Netflix") && !title.includes("Prime Video")) {
if (!DBCache[title]) {
getMovieInfo(title).then((data) => {
if (data) DBCache[title] = data;
setRatingOnCard(card, data);
});
} else {
setRatingOnCard(card, DBCache[title]);
}
}
});
}
async function setRatingOnCard(card, data) {
if (isNetflix) card.classList.add("imdb");
else card.parentElement.classList.add("imdb");

let div = document.createElement("div");
// right: 1.5vw;
div.style = "position: absolute;bottom: 0;right:0;z-index: 9999;color: black;background: #f5c518;border-radius: 5px;font-size: 1vw;padding: 0 2px 0 2px;";
// div.id = "imdb";
if (data?.score) {
div.textContent = data.score?.toFixed(1);
// div.textContent = title;
} else {
div.textContent = "?";
console.log("no Score found", title);
}
if (isNetflix) card.appendChild(div);
else card.firstChild.firstChild.appendChild(div);
}

// Disney Observers
const DisneySkipIntroObserver = new MutationObserver(Disney_Intro);
function Disney_Intro(mutations, observer) {
Expand Down Expand Up @@ -740,6 +834,23 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
removeEventListener("fullscreenchange", OnFullScreenChange);
}
}
async function startShowRatingInterval() {
if (settings.Video?.showRating) {
log("started observing| ShowRating");
let JustWatchInterval = setInterval(function () {
if (!settings.Video?.showRating) {
clearInterval(JustWatchInterval);
log("stopped observing| ShowRating");
} else {
JustWatch();
}
}, 1000);
let DBCacheInterval = setInterval(function () {
if (!settings.Video?.showRating) clearInterval(DBCacheInterval);
else setDBCache();
}, 5000);
}
}
// Disney
async function startDisneySkipIntroObserver() {
if (settings.Disney?.skipIntro === undefined || settings.Disney.skipIntro) {
Expand Down
6 changes: 6 additions & 0 deletions firefox/_locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,11 @@
},
"conflictingTitle": {
"message": "Alle widersprüchlichen Funktionen"
},
"RatingSwitch": {
"message": "IMDB Bewertung:"
},
"RatingSwitchDescription": {
"message": "Zeigt die IMDB Bewertung für jeden film/serie an"
}
}
6 changes: 6 additions & 0 deletions firefox/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,11 @@
},
"conflictingTitle": {
"message": "All conflicting Features"
},
"RatingSwitch": {
"message": "IMDB Rating:"
},
"RatingSwitchDescription": {
"message": "Adding the IMDB rating to every movie and series"
}
}
Loading

0 comments on commit aebe5e9

Please sign in to comment.