From 3fd5dd58b6ce5e02486c7fdc013444247b0b5702 Mon Sep 17 00:00:00 2001 From: sy-b <94835959+sy-b@users.noreply.github.com> Date: Wed, 29 Jun 2022 07:47:39 +0530 Subject: [PATCH 1/3] js to add 5 star rating --- Extensions/combined/src/starRating.js | 101 ++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Extensions/combined/src/starRating.js diff --git a/Extensions/combined/src/starRating.js b/Extensions/combined/src/starRating.js new file mode 100644 index 0000000..fbeac2a --- /dev/null +++ b/Extensions/combined/src/starRating.js @@ -0,0 +1,101 @@ +import { cLog } from "./utils"; + +function createStarRating(rating, isMobile) { + let starRating = document.createElement('label'); + + let starSlider = document.createElement("input"); + starSlider.setAttribute("class", "rating"); + starSlider.setAttribute("max", "5"); + starSlider.setAttribute("readonly", ""); + starSlider.setAttribute("style", `--fill:rgb(255, 215, 0);--value:${rating.toString()};};background-color: transparent;`); + starSlider.setAttribute("type", "range"); + + starRating.appendChild(starSlider); + + let YTLikeButton; + + if (isMobile){ + YTLikeButton = document.querySelector('#app > div.page-container > ytm-watch > ytm-single-column-watch-next-results-renderer > ytm-slim-video-metadata-section-renderer > ytm-slim-video-action-bar-renderer > div > ytm-slim-metadata-toggle-button-renderer:nth-child(1)'); + } else { + YTLikeButton = document.querySelector('#top-level-buttons-computed > ytd-toggle-button-renderer:nth-child(1)'); + } + + YTLikeButton.insertAdjacentElement('afterend', starRating); + + try { + let YTBar = document.querySelector('#ryd-bar-container'); + YTBar.setAttribute("style", "width: 196%; height: 2px;"); + } + catch(err) { + cLog("RateBar Not Present"); + } + + + + let style = ``; + +document.head.insertAdjacentHTML("beforeend", style); + + } + + export { createStarRating }; \ No newline at end of file From bb3fdc62c2bbcaf0eb31209c0686b314b83ae191 Mon Sep 17 00:00:00 2001 From: sy-b <94835959+sy-b@users.noreply.github.com> Date: Wed, 29 Jun 2022 07:48:32 +0530 Subject: [PATCH 2/3] import starRating in state.js Signed-off-by: sy-b <94835959+sy-b@users.noreply.github.com> --- Extensions/combined/src/state.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Extensions/combined/src/state.js b/Extensions/combined/src/state.js index df9d561..7160903 100644 --- a/Extensions/combined/src/state.js +++ b/Extensions/combined/src/state.js @@ -8,6 +8,7 @@ import { getColorFromTheme, } from "./utils"; import { localize } from "./utils"; +import { createStarRating } from "./starRating"; //TODO: Do not duplicate here and in ryd.background.js const apiUrl = "https://returnyoutubedislikeapi.com"; @@ -199,6 +200,7 @@ function processResponse(response, storedData) { getDislikeButton().style.color = getColorFromTheme(false); } } + createStarRating(response.rating, isMobile()); } // Tells the user if the API is down From 228b8b9187b7927308efaf1c20d55a800040dab4 Mon Sep 17 00:00:00 2001 From: sy-b <94835959+sy-b@users.noreply.github.com> Date: Wed, 29 Jun 2022 08:03:15 +0530 Subject: [PATCH 3/3] Decrease rate bar size Signed-off-by: sy-b <94835959+sy-b@users.noreply.github.com> --- Extensions/combined/src/starRating.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Extensions/combined/src/starRating.js b/Extensions/combined/src/starRating.js index fbeac2a..5d98814 100644 --- a/Extensions/combined/src/starRating.js +++ b/Extensions/combined/src/starRating.js @@ -24,7 +24,7 @@ function createStarRating(rating, isMobile) { try { let YTBar = document.querySelector('#ryd-bar-container'); - YTBar.setAttribute("style", "width: 196%; height: 2px;"); + YTBar.setAttribute("style", "width: 190%; height: 2px;"); } catch(err) { cLog("RateBar Not Present"); @@ -98,4 +98,4 @@ document.head.insertAdjacentHTML("beforeend", style); } - export { createStarRating }; \ No newline at end of file + export { createStarRating };