Restores the classic Watch page layout from before 2019
当前为
// ==UserScript==
// @name Watch9 Reconstruct
// @version 1.1.3
// @description Restores the classic Watch page layout from before 2019
// @author Aubrey
// @match https://www.youtube.com/*
// @license MIT
// @icon https://www.google.com/s2/favicons?domain=youtube.com
// @grant none
// @run-at document-start
// @namespace aubymori
// ==/UserScript==
async function waitForElm(q) {
while (document.querySelector(q) == null) {
await new Promise(r => requestAnimationFrame(r));
};
return document.querySelector(q);
};
const w9rStyle = document.createElement("style");
w9rStyle.innerHTML = `
#w9r-sub-count {
opacity: .8;
margin-left: 6px;
}
#info-strings.ytd-video-primary-info-renderer,
#owner-sub-count {
display: none !important;
}
ytd-button-renderer.style-primary #w9r-sub-count {
display: none;
}
`;
document.getElementsByTagName("head")[0].appendChild(w9rStyle);
document.addEventListener("yt-page-data-updated", async function() {
var pubDate = await waitForElm("ytd-video-primary-info-renderer");
const pubDatePnt = pubDate.data.dateText.simpleText;
function fixPubDate(date) {
if (/(Premier)|(Stream)|(Start)/.test(date)) {
return date;
} else {
return "Published on " + date;
}
}
var subCnt = await waitForElm("ytd-video-secondary-info-renderer");
const subCntPnt = subCnt.data.owner.videoOwnerRenderer.subscriberCountText.simpleText;
function fixSubCnt(cnt) {
return cnt.replace(/( subscribers)|( subscriber)/, "").replace("No", "0");
}
var subBtn = await waitForElm("#subscribe-button tp-yt-paper-button");
var pubDateElm = await waitForElm(".date.ytd-video-secondary-info-renderer");
var viewCount = await waitForElm("ytd-video-view-count-renderer");
if (document.querySelector("#w9r-sub-count") == null) {
var w9rSubCount = document.createElement("yt-formatted-string");
w9rSubCount.text = {runs:[{text: subCntPnt.replace(/( subscribers)|( subscriber)/, "").replace("No", "0")}]};
w9rSubCount.id = "w9r-sub-count";
subBtn.querySelector("yt-formatted-string").insertAdjacentElement("afterEnd", w9rSubCount)
} else {
document.querySelector("#w9r-sub-count").text = {simpleText:fixSubCnt(subCntPnt)};//{runs:[{text: fixSubCnt(subCntPnt)}]};
};
viewCount.removeAttribute("small");
pubDateElm.innerHTML = fixPubDate(pubDatePnt);
});