Skip to content

Commit

Permalink
initial commit: the extension detects when the detailed video preview…
Browse files Browse the repository at this point in the history
… is opened or closed
  • Loading branch information
lfarci committed Nov 21, 2021
0 parents commit f75d919
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
77 changes: 77 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@


// // const readVideoTitleFromPreviewDialogElement = (element) => {
// // const videoTitleLogoElements = element.querySelectorAll("previewModal--player-titleTreatment-logo");
// // if (videoTitleLogoElements.length > 0) {
// // return videoTitleLogoElements[0].getAttribute("title");
// // }
// // return null;
// // };

// // const readYearFromPreviewDialogElement = (element) => {
// // const yearDivElements = element.querySelectorAll(".previewModal--detailsMetadata-left .year");
// // if (yearDivElements.length > 0) {
// // return yearDivElements[0].innerText;
// // }
// // return null;
// // };

// // const readDataFromPreviewDialogElement = (element) => {
// // return {
// // title: readVideoTitleFromPreviewDialogElement(element),
// // year: readYearFromPreviewDialogElement(element)
// // };
// // }

const attemptToFindElementByClassName = (className) => {
const matches = document.getElementsByClassName(className);
let element = null;
if (matches.length > 0) {
element = matches[0];
}
return element;
};

// const onDetailedVideoPreviewDialogOpened = (handler) => {
// const DETAILED_PREVIEW_DIALOG_CLASSNAME = "previewModal--container detail-modal";
// const dialog = attemptToFindElementByClassName(DETAILED_PREVIEW_DIALOG_CLASSNAME);


// console.log(dialog);
// };


const isDetailedVideoPreviewMutation = (mutation) => {
const targetClasses = mutation.target.classList;
return mutation.type === "attributes"
&& targetClasses.contains("lolomo")
&& targetClasses.contains("is-fullbleed");
};

const handleDetailedVideoPreviewMutation = (mutation) => {
if (mutation.target.classList.contains("has-open-jaw")) {
console.log("The detailed video preview is opened.", mutation);
} else {
console.log("The detailed video preview has been closed.", mutation);
}
};

const handleDocumentBodyMutations = (mutations) => {
mutations.forEach(mutation => {
if (isDetailedVideoPreviewMutation(mutation)) {
handleDetailedVideoPreviewMutation(mutation);
}
});
};

const mainViewNode = document.getElementsByClassName("mainView")[0];
const config = {
subtree: true,
childList: true,
attributes: true,
attributeFilter: [ "class" ],
attributeOldValue: true
};

const observer = new MutationObserver(handleDocumentBodyMutations);
observer.observe(mainViewNode, config);
12 changes: 12 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "Netflix Ratings Chrome Extension",
"description": "Insert movvie and series rating into the Netflix interface.",
"version": "1.0",
"manifest_version": 3,
"content_scripts": [
{
"matches": [ "https://www.netflix.com/*" ],
"js": ["main.js"]
}
]
}

0 comments on commit f75d919

Please sign in to comment.