Skip to content

Commit

Permalink
showrating shared setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamlinerm committed Oct 26, 2023
1 parent e8d89b1 commit ae5d4be
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 67 deletions.
14 changes: 7 additions & 7 deletions chrome/popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,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">
<input type="checkbox" id="VideoShowRating" />
<span class="slider round"></span>
</label>
</div>
<div class="line flex">
<p i18n>FullscreenSwitch</p>
<label class="switch">
Expand Down Expand Up @@ -200,13 +207,6 @@ <h2 id="openNetflixSettings" i18n>PageSpecificTitle;Netflix</h2>
<span class="slider round"></span>
</label>
</div>
<div class="line flex">
<p i18n>RatingSwitch</p>
<label class="switch">
<input type="checkbox" id="NetflixShowRating" />
<span class="slider round"></span>
</label>
</div>
<div class="line flex">
<p i18n>ProfileSwitch</p>
<label class="switch">
Expand Down
41 changes: 31 additions & 10 deletions chrome/popup/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,37 @@ <h2 i18n>SharedPageTitle</h2>
</tr>
</table>
<p class="description" i18n>AdsSwitchDescription</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>
<table style="border: 1px solid white">
<tr>
<th>Netflix</th>
<th>Disney</th>
</tr>
<tr>
<td>
<label class="switch">
<input type="checkbox" id="NetflixShowRating" />
<span class="slider round"></span>
</label>
</td>
<td>
<label class="switch">
<input type="checkbox" id="DisneyShowRating" />
<span class="slider round"></span>
</label>
</td>
</tr>
</table>
<p class="description" i18n>RatingSwitchDescription</p>

<hr />
<div class="line flex">
<p i18n>SliderSwitch</p>
Expand Down Expand Up @@ -479,16 +510,6 @@ <h2 i18n>PageSpecificTitle;Netflix</h2>
</div>
<p class="description" i18n>InactivitySwitchDescription</p>

<hr />
<div class="line flex">
<p i18n>RatingSwitch</p>
<label class="switch">
<input type="checkbox" id="NetflixShowRating" />
<span class="slider round"></span>
</label>
</div>
<p class="description" i18n>RatingSwitchDescription</p>

<hr />
<div class="line flex">
<p i18n>ProfileSwitch</p>
Expand Down
28 changes: 24 additions & 4 deletions chrome/popup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const defaultSettings = {
settings: {
Amazon: { skipIntro: true, skipCredits: true, watchCredits: false, skipAd: true, blockFreevee: true, speedSlider: true, filterPaid: false, showRating: true, streamLinks: true },
Netflix: { skipIntro: true, skipRecap: true, skipCredits: true, watchCredits: false, skipBlocked: true, NetflixAds: true, speedSlider: true, profile: true, showRating: true },
Disney: { skipIntro: true, skipCredits: true, watchCredits: false, speedSlider: true },
Disney: { skipIntro: true, skipCredits: true, watchCredits: false, speedSlider: true, showRating: true },
Video: { playOnFullScreen: 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 @@ -141,6 +141,9 @@ function setCheckboxesToSettings() {
// Ads
settings?.Amazon.blockFreevee &&
settings?.Netflix.NetflixAds &&
// showRating
settings?.Netflix.showRating &&
settings?.Disney.showRating &&
// SpeedSlider
settings?.Amazon.speedSlider &&
settings?.Netflix.speedSlider &&
Expand All @@ -157,6 +160,8 @@ function setCheckboxesToSettings() {
}
button = document.querySelector("#VideoAds");
if (button) button.checked = settings?.Amazon.blockFreevee && settings?.Netflix.NetflixAds;
button = document.querySelector("#VideoShowRating");
if (button) button.checked = settings?.Netflix.showRating && settings?.Disney.showRating;
button = document.querySelector("#VideoSpeedSlider");
if (button) button.checked = settings?.Amazon.speedSlider && settings?.Netflix.speedSlider && settings?.Disney.speedSlider;
button = document.querySelector("#VideoFullScreen");
Expand Down Expand Up @@ -190,7 +195,7 @@ function setCheckboxesToSettings() {

// ------------- Netflix ---------------------------------------
button = document.querySelector("#NetflixSkips");
if (button) button.checked = settings?.Netflix.skipRecap && settings?.Netflix.skipBlocked && settings?.Netflix.profile && settings?.Netflix.showRating;
if (button) button.checked = settings?.Netflix.skipRecap && settings?.Netflix.skipBlocked && settings?.Netflix.profile;
button = document.querySelector("#NetflixIntro");
if (button) button.checked = settings?.Netflix.skipIntro;
button = document.querySelector("#NetflixRecap");
Expand Down Expand Up @@ -229,6 +234,8 @@ function setCheckboxesToSettings() {
if (button) button.checked = settings?.Disney.watchCredits;
button = document.querySelector("#DisneySpeedSlider");
if (button) button.checked = settings?.Disney.speedSlider;
button = document.querySelector("#DisneyShowRating");
if (button) button.checked = settings?.Disney.showRating;

// ------------- Slider Options ---------------------------------------
button = document.querySelector("#SliderSteps");
Expand Down Expand Up @@ -340,6 +347,9 @@ function listenForClicks() {
// Ads
settings?.Amazon.blockFreevee &&
settings?.Netflix.NetflixAds &&
// showRating
settings?.Netflix.showRating &&
settings?.Disney.showRating &&
// SpeedSlider
settings?.Amazon.speedSlider &&
settings?.Netflix.speedSlider &&
Expand All @@ -357,6 +367,9 @@ function listenForClicks() {
// Ads
settings.Amazon.blockFreevee =
settings.Netflix.NetflixAds =
// showRating
settings.Netflix.showRating =
settings.Disney.showRating =
// SpeedSlider
settings.Amazon.speedSlider =
settings.Netflix.speedSlider =
Expand Down Expand Up @@ -388,6 +401,10 @@ function listenForClicks() {
const skipAd = settings?.Amazon.blockFreevee && settings?.Netflix.NetflixAds;
settings.Amazon.blockFreevee = settings.Netflix.NetflixAds = !skipAd;
setSettings("VideoAd");
} else if (e.target.id === "VideoShowRating") {
const showRating = settings?.Netflix.showRating && settings?.Disney.showRating;
settings.Netflix.showRating = settings.Disney.showRating = !showRating;
setSettings("VideoSpeedSlider");
} else if (e.target.id === "VideoSpeedSlider") {
const speedSlider = settings?.Amazon.speedSlider && settings?.Netflix.speedSlider && settings?.Disney.speedSlider;
settings.Amazon.speedSlider = settings.Netflix.speedSlider = settings.Disney.speedSlider = !speedSlider;
Expand Down Expand Up @@ -441,8 +458,8 @@ function listenForClicks() {
}
// ------------- Netflix ---------------------------------------
else if (e.target.id === "NetflixSkips") {
const NetflixSkips = !(settings?.Netflix.skipRecap && settings?.Netflix.skipBlocked && settings?.Netflix.profile && settings?.Netflix.showRating);
settings.Netflix.skipRecap = settings.Netflix.skipBlocked = settings.Netflix.profile = settings.Netflix.showRating = NetflixSkips;
const NetflixSkips = !(settings?.Netflix.skipRecap && settings?.Netflix.skipBlocked && settings?.Netflix.profile);
settings.Netflix.skipRecap = settings.Netflix.skipBlocked = settings.Netflix.profile = NetflixSkips;
setSettings("All NetflixSkips");
} else if (e.target.id === "NetflixIntro") {
settings.Netflix.skipIntro = !settings.Netflix.skipIntro;
Expand Down Expand Up @@ -501,6 +518,9 @@ function listenForClicks() {
} else if (e.target.id === "DisneySpeedSlider") {
settings.Disney.speedSlider = !settings.Disney.speedSlider;
setSettings("DisneySpeedSlider");
} else if (e.target.id === "DisneyShowRating") {
settings.Disney.showRating = !settings.Disney.showRating;
setSettings("DisneyShowRating");
}
// ------------- Statistics ---------------------------------------
else if (e.target.id === "upload") {
Expand Down
50 changes: 27 additions & 23 deletions chrome/skipper.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
settings: {
Amazon: { skipIntro: true, skipCredits: true, watchCredits: false, skipAd: true, blockFreevee: true, speedSlider: true, filterPaid: false, showRating: true, streamLinks: true },
Netflix: { skipIntro: true, skipRecap: true, skipCredits: true, watchCredits: false, skipBlocked: true, NetflixAds: true, speedSlider: true, profile: true, showRating: true },
Disney: { skipIntro: true, skipCredits: true, watchCredits: false, speedSlider: true },
Disney: { skipIntro: true, skipCredits: true, watchCredits: false, speedSlider: true, showRating: true },
Video: { playOnFullScreen: 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 @@ -111,16 +111,18 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
chrome.storage.local.get("DBCache", function (result) {
DBCache = result?.DBCache;
if (typeof DBCache !== "object") {
console.log("DBCache not found, creating new one", DBCache);
log("DBCache not found, creating new one", DBCache);
chrome.storage.local.set({ DBCache: {} });
DBCache = {};
}
if (isNetflix) {
if (settings.Netflix?.showRating) startShowRatingInterval();
} else if (isPrimeVideo) {
if (settings.Amazon?.streamLinks) addStreamLinks();
} else if (isDisney || isHotstar) {
// startShowRatingInterval();
}
// else if (isPrimeVideo) {
// if (settings.Amazon?.streamLinks) addStreamLinks();
// }
else if (isDisney || isHotstar) {
if (settings.Disney?.showRating) startShowRatingInterval();
}
});
});
Expand Down Expand Up @@ -156,7 +158,7 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
if (oldValue === undefined || newValue.Amazon.blockFreevee !== oldValue.Amazon?.blockFreevee) startAmazonBlockFreeveeObserver();
if (oldValue === undefined || newValue.Amazon.speedSlider !== oldValue.Amazon?.speedSlider) startAmazonSpeedSliderObserver();
if (oldValue === undefined || newValue.Amazon.filterPaid !== oldValue.Amazon?.filterPaid) startAmazonFilterPaidObserver();
if (oldValue === undefined || newValue.Video.streamLinks !== oldValue.Amazon?.streamLinks) addStreamLinks();
// if (oldValue === undefined || newValue.Video.streamLinks !== oldValue.Amazon?.streamLinks) addStreamLinks();

// if (oldValue === undefined || newValue.Video.showRating !== oldValue.Amazon?.showRating) startShowRatingInterval();
} else if (isDisney || isHotstar) {
Expand Down Expand Up @@ -205,11 +207,15 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
chrome.storage.local.set({ DBCache });
}
}
// chrome.storage.local.set({ DBCache: {} });
// justWatchAPI
async function getMovieInfo(title, card, Rating = true, locale = "en-US") {
// console.log("getMovieInfo", movieTitle);
async function getMovieInfo(title, card, Rating = true) {
// justwatch api
// const url = `https://apis.justwatch.com/content/titles/${locale}/popular?language=en&body={"page_size":1,"page":1,"query":"${title}","content_types":["show","movie"]}`;
let locale = "en-US";
if (navigator?.language) {
locale = navigator?.language;
}
// use the url for themoviedb.org now
const url = `https://api.themoviedb.org/3/search/movie?query=${encodeURI(title)}&include_adult=true&language=${locale}&page=1`;
// const response = await fetch(encodeURI(url));
Expand All @@ -231,9 +237,6 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
// const compiledData = { jWURL, score, streamLinks: offers };

// themoviedb
if (!data?.results?.[0]) {
console.log("no data found", data);
}
const compiledData = { score: data?.results?.[0]?.vote_average };
DBCache[title] = compiledData;
if (Rating) setRatingOnCard(card, compiledData, title);
Expand All @@ -250,7 +253,7 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
const config = { attributes: true, childList: true, subtree: true };

// shared functions
async function JustWatch() {
async function addRating() {
let titleCards;
if (isNetflix) titleCards = document.querySelectorAll(".title-card .boxart-container:not(.imdb)");
else if (isDisney) titleCards = document.querySelectorAll(".basic-card div div img:not(.imdb)");
Expand All @@ -259,21 +262,22 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
titleCards.forEach((card) => {
// let card = document.querySelectorAll(".title-card .boxart-container:not(.imdb)");
let title;
if (isNetflix) title = card?.children?.[1]?.firstChild?.textContent;
if (isNetflix) title = card?.children?.[1]?.firstChild?.textContent.split(" – ")[0];
else if (isDisney) title = card?.getAttribute("alt");
// amazon
// 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, card);
log("no info in DBcache", title);
// log("no info in DBcache", title);
} else {
setRatingOnCard(card, DBCache[title], title);
}
}
});
}
// deprecated justwatch api
async function setAlternativesOnCard(card, data) {
let div = document.createElement("div");
div.style = "display:flex;";
Expand Down Expand Up @@ -372,7 +376,7 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
// div.textContent = title;
} else {
div.textContent = "?";
console.log("no Score found", title, data);
log("no Score found", title, data);
}
if (isNetflix) card.appendChild(div);
else if (isDisney) card.parentElement.appendChild(div);
Expand Down Expand Up @@ -943,7 +947,7 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
else video = document.querySelector(AmazonVideoClass);
if (window.fullScreen && video) {
video.play();
console.log("auto-played on fullscreen");
log("auto-played on fullscreen");
increaseBadge();
}
}
Expand All @@ -953,9 +957,9 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
removeEventListener("fullscreenchange", OnFullScreenChange);
}
}

// deprecated
async function addStreamLinks() {
console.log("adding stream links");
log("adding stream links");
let title = document.querySelector("h1[data-automation-id='title']")?.textContent?.split(" [")[0];
if (title) {
// if not already free blue in prime icon
Expand All @@ -973,13 +977,13 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar) {
async function startShowRatingInterval() {
if (settings.Netflix?.showRating) {
log("started observing| ShowRating");
JustWatch();
let JustWatchInterval = setInterval(function () {
addRating();
let RatingInterval = setInterval(function () {
if (!settings.Netflix?.showRating) {
clearInterval(JustWatchInterval);
clearInterval(RatingInterval);
log("stopped observing| ShowRating");
} else {
JustWatch();
addRating();
}
}, 1000);
let DBCacheInterval = setInterval(function () {
Expand Down
14 changes: 7 additions & 7 deletions firefox/popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,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">
<input type="checkbox" id="VideoShowRating" />
<span class="slider round"></span>
</label>
</div>
<div class="line flex">
<p i18n>FullscreenSwitch</p>
<label class="switch">
Expand Down Expand Up @@ -195,13 +202,6 @@ <h2 id="openNetflixSettings" i18n>PageSpecificTitle;Netflix</h2>
<span class="slider round"></span>
</label>
</div>
<div class="line flex">
<p i18n>RatingSwitch</p>
<label class="switch">
<input type="checkbox" id="NetflixShowRating" />
<span class="slider round"></span>
</label>
</div>
<div class="line flex">
<p i18n>ProfileSwitch</p>
<label class="switch">
Expand Down
Loading

0 comments on commit ae5d4be

Please sign in to comment.