Skip to content

Commit

Permalink
4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Taknok committed Jul 29, 2024
2 parents f884a5d + 4048ecd commit aad0ec6
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 638 deletions.
4 changes: 2 additions & 2 deletions app/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "__MSG_appName__",
"version": "3.9.1",
"version": "4.0.0",
"manifest_version": 2,
"description": "__MSG_appDesc__",
"icons": {
Expand All @@ -25,7 +25,7 @@
"content_scripts": [
{
"matches": ["*://youtube.com/*", "*://*.youtube.com/*"],
"js": ["scripts/constants.js", "scripts/modules/option-manager.js", "scripts/modules/miscellaneous.js", "scripts/modules/liker-material.js", "scripts/modules/liker-paper.js", "scripts/content.js"],
"js": ["scripts/constants.js", "scripts/modules/option-manager.js", "scripts/modules/miscellaneous.js", "scripts/modules/metaliker.js", "scripts/modules/liker-paper.js", "scripts/modules/liker-grid.js", "scripts/content.js"],
"run_at": "document_end"
}
],
Expand Down
11 changes: 7 additions & 4 deletions app/scripts/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ browser.runtime.onMessage.addListener( function(msg, sender, sendResponse) {

function startLikerProcess(options) {
var IS_PAPER = document.querySelector("ytd-subscribe-button-renderer") !== null;
var IS_GRID = document.querySelectorAll("ytd-watch-grid").length !== 0;
window.IS_PAPER = IS_PAPER;
window.IS_GRID = IS_GRID;
let liker = null;
if (IS_PAPER) {
if (IS_GRID) {
log("grid liker init");
liker = new GridLiker(options);
} else if (IS_PAPER) {
log("paper liker init");
liker = new PaperLiker(options);
} else {
log("material liker init");
liker = new MaterialLiker(options);
}

if (IS_CLASSIC) {
log("Classic youtube detected");
liker.init();
Expand Down
35 changes: 35 additions & 0 deletions app/scripts/modules/liker-grid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Likes YouTube videos.
* For the newer paper design layout
*/
class GridLiker extends MetaLiker {

VIDEO_SELECTOR = ".video-stream";
ACTION_ELEMENTS_SELECTOR = "#secondary-inner ytd-watch-metadata ytd-menu-renderer segmented-like-dislike-button-view-model";
LIKE_SELECTOR = "like-button-view-model button";
DISLIKE_SELECTOR = "dislike-button-view-model button";
LIVE_SELECTOR = ".ytp-live-badge[disabled='']";

isVideoRated(like, dislike) {
return like.attributes["aria-pressed"].nodeValue === "true" ||
dislike.attributes["aria-pressed"].nodeValue === "true";
}

/*
* Another tough one
* @return {Boolean} True if the user is subscribed to
* the current video's channel
*/
isUserSubscribed() {
let subscribeButtons = document.querySelectorAll("ytd-subscribe-button-renderer :not(*[hidden]) button.yt-spec-button-shape-next--tonal")
// the ':not(*[hidden]) ytd-subscribe-button-renderer :not(*[hidden]) button.yt-spec-button-shape-next--tonal'
// does not work, thus use isHidden
let buttonExist = subscribeButtons.length > 0
log("sub button exist: ", buttonExist)
if (!buttonExist) return false

let subscribeButton = Array.from(subscribeButtons).find(isNotHidden)
log("sub button not hidden: ", subscribeButton)
return subscribeButton !== undefined;
}
}
Loading

0 comments on commit aad0ec6

Please sign in to comment.