|
1 | 1 | // ==UserScript== |
2 | 2 | // @name YouTube™ Classic 📺 — (Remove rounded design + Return YouTube dislikes) |
3 | | -// @version 2026.1.17.55 |
| 3 | +// @version 2026.1.20 |
4 | 4 | // @author Adam Lui, Magma_Craft, Anarios, JRWR, Fuim & hoothin |
5 | 5 | // @namespace https://github.com/adamlui |
6 | 6 | // @description Reverts YouTube to its classic design (before all the rounded corners & hidden dislikes) + redirects YouTube Shorts |
|
1168 | 1168 | 'd: path("M12.7,12l6.6,6.6l-0.7,0.7L12,12.7l-6.6,6.6l-0.7-0.7l6.6-6.6L4.6,5.4l0.7-0.7l6.6,6.6l6.6-6.6l0.7,0.7L12.7,12z")', |
1169 | 1169 | '}' |
1170 | 1170 | ].join('\n') |
1171 | | - const btnStyle = document.createElement('style') |
1172 | | - btnStyle.textContent = css |
| 1171 | + const btnStyle = document.createElement('style') ; btnStyle.textContent = css |
1173 | 1172 | const heads = document.getElementsByTagName('head'), |
1174 | 1173 | btnStyleParent = heads.length ? heads[0] : document.documentElement |
1175 | 1174 | btnStyleParent.append(btnStyle) |
|
1321 | 1320 |
|
1322 | 1321 | function createRateBar(likes, dislikes) { |
1323 | 1322 | if (isMobile) return |
1324 | | - const rateBar = document.getElementById('return-youtube-dislike-bar-container') |
1325 | | - const widthPx = getBtns().children[0].clientWidth + getBtns().children[1].clientWidth +8 |
1326 | | - const widthPercent = likes + dislikes > 0 ? (likes / (likes + dislikes)) *100 : 50 |
1327 | | - const likePercent = parseFloat(widthPercent.toFixed(1)).toLocaleString() |
1328 | | - const dislikePercent = (100 - likePercent).toLocaleString() |
| 1323 | + |
| 1324 | + const rateBar = document.getElementById('return-youtube-dislike-bar-container'), |
| 1325 | + widthPx = getBtns().children[0].clientWidth + getBtns().children[1].clientWidth +8, |
| 1326 | + widthPercent = likes + dislikes > 0 ? (likes / (likes + dislikes)) *100 : 50, |
| 1327 | + likePercent = parseFloat(widthPercent.toFixed(1)).toLocaleString(), |
| 1328 | + dislikePercent = (100 - likePercent).toLocaleString() |
| 1329 | + |
1329 | 1330 | const tooltipInnerHTML = { |
1330 | 1331 | dash_like: `${likes.toLocaleString()} / ${ |
1331 | 1332 | dislikes.toLocaleString()} - ${likePercent}%`, |
|
1335 | 1336 | only_like: `${likePercent}%`, |
1336 | 1337 | only_dislike: `${dislikePercent}%` |
1337 | 1338 | }[extConfig.tooltipPercentageMode] || `${likes.toLocaleString()} / ${dislikes.toLocaleString()}` |
| 1339 | + |
1338 | 1340 | if (!rateBar && !isMobile) { |
1339 | 1341 | const colorDislikeStyle = extConfig.coloredBar ? `; background-color: ${getColorFromTheme(false)}` : '' |
1340 | 1342 | document.getElementById('menu-container').insertAdjacentHTML('beforeend', ` |
|
1352 | 1354 | </tp-yt-paper-tooltip> |
1353 | 1355 | </div> |
1354 | 1356 | `) |
| 1357 | + |
1355 | 1358 | } else { |
1356 | 1359 | const rydBar = document.getElementById('return-youtube-dislike-bar'), |
1357 | 1360 | rydBarContainer = document.getElementById('return-youtube-dislike-bar-container'), |
|
1368 | 1371 | function setState() { |
1369 | 1372 | cLog('Fetching votes...') |
1370 | 1373 | let statsSet = false |
1371 | | - fetch(`https://returnyoutubedislikeapi.com/votes?videoId=${getVideoID()}`).then(resp => |
| 1374 | + fetch(`https://returnyoutubedislikeapi.com/votes?videoId=${getVidID()}`).then(resp => |
1372 | 1375 | resp.json().then(json => { |
1373 | 1376 | if (json && !('traceId' in resp) && !statsSet) { |
1374 | 1377 | const { dislikes, likes } = json |
1375 | 1378 | cLog(`Received count: ${dislikes}`) |
1376 | 1379 | likesVal = likes ; dislikesVal = dislikes |
1377 | | - setDislikes(numberFormat(dislikes)) |
| 1380 | + setDislikes(numFormat(dislikes)) |
1378 | 1381 | if (extConfig.numberDisplayReformatLikes) { |
1379 | 1382 | const nativeLikes = getLikeCntFromBtn() |
1380 | | - if (nativeLikes != null) setLikes(numberFormat(nativeLikes)) |
| 1383 | + if (nativeLikes != null) setLikes(numFormat(nativeLikes)) |
1381 | 1384 | } |
1382 | 1385 | createRateBar(likes, dislikes) |
1383 | 1386 | if (extConfig.coloredThumbs) { |
|
1406 | 1409 | if (prevState == 1) { |
1407 | 1410 | likesVal-- |
1408 | 1411 | createRateBar(likesVal, dislikesVal) |
1409 | | - setDislikes(numberFormat(dislikesVal)) |
| 1412 | + setDislikes(numFormat(dislikesVal)) |
1410 | 1413 | prevState = 3 |
1411 | 1414 | } else if (prevState == 2) { |
1412 | 1415 | likesVal++ |
1413 | 1416 | dislikesVal-- |
1414 | | - setDislikes(numberFormat(dislikesVal)) |
| 1417 | + setDislikes(numFormat(dislikesVal)) |
1415 | 1418 | createRateBar(likesVal, dislikesVal) |
1416 | 1419 | prevState = 1 |
1417 | 1420 | } else if (prevState == 3) { |
|
1421 | 1424 | } |
1422 | 1425 | if (extConfig.numberDisplayReformatLikes) { |
1423 | 1426 | const nativeLikes = getLikeCntFromBtn() |
1424 | | - if (nativeLikes != null) setLikes(numberFormat(nativeLikes)) |
| 1427 | + if (nativeLikes != null) setLikes(numFormat(nativeLikes)) |
1425 | 1428 | } |
1426 | 1429 | } |
1427 | 1430 | } |
|
1430 | 1433 | if (checkForUserAvatarButton()) { |
1431 | 1434 | if (prevState == 3) { |
1432 | 1435 | dislikesVal++ |
1433 | | - setDislikes(numberFormat(dislikesVal)) |
| 1436 | + setDislikes(numFormat(dislikesVal)) |
1434 | 1437 | createRateBar(likesVal, dislikesVal) |
1435 | 1438 | prevState = 2 |
1436 | 1439 | } else if (prevState == 2) { |
1437 | 1440 | dislikesVal-- |
1438 | | - setDislikes(numberFormat(dislikesVal)) |
| 1441 | + setDislikes(numFormat(dislikesVal)) |
1439 | 1442 | createRateBar(likesVal, dislikesVal) |
1440 | 1443 | prevState = 3 |
1441 | 1444 | } else if (prevState == 1) { |
1442 | | - likesVal-- |
1443 | | - dislikesVal++ |
1444 | | - setDislikes(numberFormat(dislikesVal)) |
| 1445 | + likesVal-- ; dislikesVal++ |
| 1446 | + setDislikes(numFormat(dislikesVal)) |
1445 | 1447 | createRateBar(likesVal, dislikesVal) |
1446 | 1448 | prevState = 2 |
1447 | 1449 | if (extConfig.numberDisplayReformatLikes) { |
1448 | 1450 | const nativeLikes = getLikeCntFromBtn() |
1449 | | - if (nativeLikes != null) setLikes(numberFormat(nativeLikes)) |
| 1451 | + if (nativeLikes != null) setLikes(numFormat(nativeLikes)) |
1450 | 1452 | } |
1451 | 1453 | } |
1452 | 1454 | } |
1453 | 1455 | } |
1454 | 1456 |
|
1455 | | - function getVideoID() { |
| 1457 | + function getVidID() { |
1456 | 1458 | const urlObj = new URL(unsafeWindow.location.href), pathname = urlObj.pathname |
1457 | 1459 | return pathname.startsWith('/clip') ? document.querySelector('meta[itemprop="videoId"]')?.content |
1458 | 1460 | : pathname.startsWith('/shorts') ? pathname.slice(8) |
1459 | 1461 | : urlObj.searchParams.get('v') |
1460 | 1462 | } |
1461 | 1463 |
|
1462 | | - function isVideoLoaded() { |
| 1464 | + function isVidLoaded() { |
1463 | 1465 | return isMobile ? document.getElementById('player').getAttribute('loading') == 'false' |
1464 | | - : !!document.querySelector(`ytd-watch-flexy[video-id='${getVideoID()}']`) |
| 1466 | + : !!document.querySelector(`ytd-watch-flexy[video-id='${getVidID()}']`) |
1465 | 1467 | } |
1466 | 1468 |
|
1467 | 1469 | function roundDown(num) { |
|
1472 | 1474 | return val *10 ** decimal |
1473 | 1475 | } |
1474 | 1476 |
|
1475 | | - function numberFormat(numState) { |
| 1477 | + function numFormat(numState) { |
1476 | 1478 | const numDisplay = !extConfig.numberDisplayRoundDown ? numState : roundDown(numState) |
1477 | | - return getNumberFormatter(extConfig.numberDisplayFormat).format(numDisplay) |
| 1479 | + return getNumFormatter(extConfig.numberDisplayFormat).format(numDisplay) |
1478 | 1480 | } |
1479 | 1481 |
|
1480 | | - function getNumberFormatter(optionSelect) { |
| 1482 | + function getNumFormatter(optionSelect) { |
1481 | 1483 | let userLocales |
1482 | 1484 | if (document.documentElement.lang) userLocales = document.documentElement.lang |
1483 | 1485 | else if (navigator.language) userLocales = navigator.language |
|
1528 | 1530 | function setEventListeners() { |
1529 | 1531 | let jsInitChecktimer |
1530 | 1532 | function checkForJS_Finish() { |
1531 | | - if (isShorts() || (getBtns()?.offsetParent && isVideoLoaded())) { |
| 1533 | + if (isShorts() || (getBtns()?.offsetParent && isVidLoaded())) { |
1532 | 1534 | const buttons = getBtns() |
1533 | 1535 | if (!unsafeWindow.returnDislikeButtonlistenersSet) { |
1534 | 1536 | cLog('Registering button listeners...') |
|
0 commit comments