This is my code "`)
 const {
 stash,
 Stash,
 waitForElementId,
 waitForElementClass,
 waitForElementByXpath,
 getElementByXpath,
 getClosestAncestor,
 updateTextInput,
 } = unsafeWindow.stash;

 async function querySceneRating(sceneId) {
 const gqlQuery = {
 'query': `query {
 findScene(id: ${sceneId}){
 rating
 }
 }`
 };
 let rating = await stash.callGQL(gqlQuery);
 if (!rating.data.findScene) {
 // handle the error here
 console.log("Error with querySceneRating GraphQL: " + rating);
 }
 return rating
 }

 async function updateSceneRating(sceneId, rating) {
 console.log("Updating Rating")
 console.log("updateSceneRating sceneId " + sceneId)
 console.log("updateSceneRating rating " + rating)
 const reqData = {
 "operationName": "sceneUpdate",
 "variables": {
 "input": {
 "id": sceneId,
 "rating100": rating \* 20
 }
 },
 "query": `mutation sceneUpdate($input: SceneUpdateInput!){
 sceneUpdate(input: $input){
 id
 rating100
 }
 }`
 }
 const response = await stash.callGQL(reqData);
 currentRating = rating;
 setTimeout(function() {
 updateElements(currentRating);
 }, 2000)
 console.log("updateSceneRating: rating: " + currentRating)
 }

 function updateElements(rating) {
 let sceneId = updateSceneId();
 console.log("updateElements sceneId" + sceneId);
 console.log("updateElements rating" + rating);

 // code to update the elements here
 waitForElementId("video-stars", async function(IdName, el) {
 console.log("updateElements: rating: " + rating);
 currentRating = rating;
 console.log("updateElements: currentRating: " + currentRating)
 const customdivElements = document.getElementById('video-stars')
 const ratingButtons = customdivElements.querySelectorAll('.rating-stars button');
 // Set Classes & Titles inital values
 if (currentRating == null) {
 console.log("updateElements - rating == null: ");
 updateTitles(0);
 updateClasses(0);
 } else {
 console.log("updateElements - rating != null - rating: " + rating);

 updateTitles(currentRating);
 updateClasses(currentRating);
 }

 })
 return
 }

 function updateSceneId() {
 const currentUrl = window.location.href.split('?')[0];
 const sceneId = currentUrl.substring(currentUrl.lastIndexOf('/') + 1);
 console.log("updateSceneId" + sceneId);
 return sceneId
 }

 function updateTitles(num) {
 const customdivstitle = document.getElementById('video-stars')
 const ratingButtons = customdivstitle.querySelectorAll('.rating-stars button');
 ratingButtons.forEach(btn => {
 btn.title = num;
 });
 }

 function updateClasses(num) {
 const customdivclasses = document.getElementById('video-stars')
 const ratingButtons = customdivclasses.querySelectorAll('.rating-stars button');
 ratingButtons.forEach((btn, i) => {
 if (i < num) {
 btn.classList.remove('star-fill-0');
 btn.classList.add('star-fill-100');
 } else {
 btn.classList.add('star-fill-0');
 btn.classList.remove('star-fill-100');
 }
 });
 }

 stash.addEventListener("page:scene", async function() {
 let sceneId = updateSceneId();
 // let rating = (await querySceneRating(sceneId)).data.findScene.rating;

 waitForElementClass("rating-stars", function () {
 const n = document.getElementsByClassName('rating-stars')[1];
 let node = n.cloneNode(true);

 waitForElementByXpath("//div[contains(@class, 'VideoPlayer')]", function(xpath, el) {
 if (!document.getElementById('video-stars')) {
 const control = el.querySelector('.vjs-control-bar');
 node.setAttribute('id', 'video-stars');
 // ratingStarsNode.innerHTML = ratingstars;
 control.appendChild(node);
 control.insertBefore(node, control.childNodes[9]);
 }

 // Get current set rating or if on first pass get rating from HTMl
 let rating = currentRating || node.querySelector('button').title \* 20;
 console.log("xpath rating: " + rating);

 const customdiv = document.getElementById('video-stars');
 const ratingButtons = customdiv.querySelectorAll('button');
 const unfilledstar = customdiv.querySelectorAll('.unfilled-star div');
 // const sceneid = updateSceneId();
 rating = Math.floor(rating / 20);
 ratingButtons.forEach((btn, index) => {
 index += 1
 btn.addEventListener('mouseover', event => {
 if (rating !== "0" && rating !== index) {
 console.log('mouseover-rating !== "0" && rating !== index - ' + "index: " + index + " rating: " + rating);

 updateTitles(index);
 updateClasses(index);
 }
 });

 ratingButtons.forEach((btn, index) => {
 index += 1
 btn.addEventListener('mouseover', event => {
 if (index === rating) {
 ratingButtons.forEach(button => {
 console.log('index === rating - ' + "index: " + index + " rating: " + rating)

 updateTitles("Unset");
 })
 }
 }
 )
 })

 btn.addEventListener('mouseout', event => {
 if (rating !== "0" && rating !== btn.title) {
 console.log('mouseout: rating !== "0" && rating !== event.target.title-: ' + 'btn.title: ' + btn.title + ' event.target.title: ' + event.target.title + ' rating: ' + rating);

 if (rating !== "0") {
 updateTitles(rating);
 updateClasses(rating);
 console.log('mouseout: rating: ' + rating);
 }
 }});

 btn.addEventListener('click', event => {
 if (btn.title !== "Unset") {
 console.log("click: btn: Not unset - btn.title - " + btn.title);
 updateSceneRating(sceneId, btn.title);
 } else {
 updateTitles("0");
 updateClasses(0);
 console.log("click: btn: Unset: " + "0");

 updateSceneRating(sceneId, null);
 }
 });
 });
 unfilledstar.forEach((div, index) => {
 index += 1
 unfilledstar.addEventListener('click', event => {
 if (ratingButtons.title == "Unset") {
 console.log("click: unfilled star: unset");
 updateTitles("0");
 updateClasses(0);
 updateSceneRating(sceneId, null);
 } else {
 console.log("click: unfilled star: Title != unfill");

 updateTitles(event.target.title);
 updateClasses(event.target.title);
 updateSceneRating(sceneId, event.target.title);

 }
 });
 });

 document.addEventListener("DOMContentLoaded", () => {
 console.log("Loaded")
 const observer = new MutationObserver(mutations => {
 mutations.forEach(mutation => {
 Array.from(mutation.addedNodes).forEach(addedNode => {
 if (addedNode.matches && addedNode.matches('.fade.toast.success.show')) {
 setTimeout(function() {
 updateElements();
 }, 2000);

 }
 });
 });
 });
 observer.observe(document.body, {
 childList: true,
 subtree: true
 });

 });
 })
 })
 })
})();" on the first pass through the button event listeners use let "node.querySelector('button').title \* 20;" to determine the current rating. Once a rating star has been clicked the button passes the rating to the update rating function and that to the updateElements function. Then it's supposed to follow this logic if hovering or clicking on the button event listeners a second time and so on. To use " let rating = currentRating || node.querySelector('button').title \* 20;" to get to current most up to date rating value (The one that was just set) and have the event listeners use the updated value instead of the old one. But it isn't working.
이것은 내 코드입니다 "`) const { stash, Stash, waitForElementId, waitForElementClass, waitForElementByXpath, getElementByXpath, 가장 가까운 조상, 업데이트 텍스트 입력, } = unsafeWindow.stash; 비동기 함수 querySceneRating(sceneId) { const gqlQuery = { 'query': `query { findScene(id: ${sceneId}){ rating } }` }; let rating = await stash.callGQL(gqlQuery); if (!rating.data.findScene) { // 여기서 오류를 처리합니다. console.log("쿼리 장면 등급 GraphQL에 오류가 발생했습니다: " + rating); } 평점 반환 } 비동기 함수 updateSceneRating(sceneId, rating) { console.log("평점 업데이트 중") console.log("updateSceneRating 장면아이디 " + 장면아이디) console.log("updateSceneRating rating " + rating) const reqData = { "작업 이름": "sceneUpdate", "variables": { "input": { "id": sceneId, "rating100": 평점 \* 20 } }, "쿼리": `mutation sceneUpdate($input: SceneUpdateInput!){ sceneUpdate(input: $input){ id rating100 } }` } const response = await stash.callGQL(reqData); currentRating = rating; setTimeout(function() { updateElements(currentRating); }, 2000) console.log("updateSceneRating: rating: " + currentRating) } 함수 updateElements(rating) { let sceneId = updateSceneId(); console.log("updateElements sceneId" + sceneId); console.log("updateElements rating" + rating); // 여기에 요소를 업데이트하는 코드 waitForElementId("video-stars", async function(IdName, el) { console.log("updateElements: rating: " + rating); currentRating = rating; console.log("updateElements: currentRating: " + currentRating) const customdivElements = document.getElementById('video-stars') const ratingButtons = customdivElements.querySelectorAll('.rating-stars button'); // 클래스 및 제목 초기값 설정 if (currentRating == null) { console.log("updateElements - rating == null: "); updateTitles(0); updateClasses(0); } else { console.log("updateElements - rating != null - rating: " + rating); updateTitles(currentRating); updateClasses(currentRating); } }) return } 함수 updateSceneId() { const currentUrl = window.location.href.split('?')[0]; const sceneId = currentUrl.substring(currentUrl.lastIndexOf('/') + 1); console.log("updateSceneId" + sceneId); 반환 장면아이디 } 함수 updateTitles(num) { const customdivstitle = document.getElementById('video-stars') const ratingButtons = customdivstitle.querySelectorAll('.rating-stars button'); ratingButtons.forEach(btn => { btn.title = num; }); } 함수 updateClasses(num) { const customdivclasses = document.getElementById('video-stars') const ratingButtons = customdivclasses.querySelectorAll('.rating-stars button'); ratingButtons.forEach((btn, i) => { if (i < num) { btn.classList.remove('star-fill-0'); btn.classList.add('star-fill-100'); } else { btn.classList.add('star-fill-0'); btn.classList.remove('star-fill-100'); } }); } stash.addEventListener("page:scene", async function() { let sceneId = updateSceneId(); // let rating = (await querySceneRating(sceneId)).data.findScene.rating; waitForElementClass("rating-stars", function () { const n = document.getElementsByClassName('rating-stars')[1]; let node = n.cloneNode(true); waitForElementByXpath("//div[contains(@class, 'VideoPlayer')]", function(xpath, el) { if (!document.getElementById('video-stars')) { const control = el.querySelector('.vjs-control-bar'); node.setAttribute('id', 'video-stars'); // ratingStarsNode.innerHTML = ratingstars; control.appendChild(node); control.insertBefore(node, control.childNodes[9]); } // 현재 설정된 등급을 가져오거나 첫 번째 통과 시 HTMl에서 등급을 가져옵니다. let rating = currentRating || node.querySelector('button').title \* 20; console.log("xpath rating: " + rating); const customdiv = document.getElementById('video-stars'); const ratingButtons = customdiv.querySelectorAll('button'); const unfilled-star = customdiv.querySelectorAll('.unfilled-star div'); // const sceneid = updateSceneId(); rating = Math.floor(rating / 20); ratingButtons.forEach((btn, index) => { { index += 1 btn.addEventListener('mouseover', event => { if (rating !== "0" && rating !== index) { console.log('mouseover-rating !== "0" && rating !== index - ' + "index: " + index + " rating: " + rating); updateTitles(index); updateClasses(index); } }); ratingButtons.forEach((btn, index) => { { index += 1 btn.addEventListener('mouseover', event => { if (index === rating) { ratingButtons.forEach(button => { console.log('index === rating - ' + "index: " + index + " rating: " + rating) updateTitles("Unset"); }) } } ) }) btn.addEventListener('mouseout', event => { if (rating !== "0" && rating !== btn.title) { console.log('mouseout: rating !== "0" && rating !== event.target.title-: ' + 'btn.title: ' + btn.title + ' event.target.title: ' + event.target.title + ' rating: ' + rating); if (rating !== "0") { updateTitles(rating); 업데이트클래스(등급); console.log('마우스아웃: 등급: ' + 등급); } }}); btn.addEventListener('clic