Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show exact date button #2824

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,9 @@
"showChannelVideosCount": {
"message": "Show channel videos count"
},
"showExactDate": {
"message": "Show Exact Date"
},
"showLess": {
"message": "Show less"
},
Expand Down
10 changes: 10 additions & 0 deletions js&css/extension/www.youtube.com/appearance/details/details.css
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ html[it-description='classic_hidden'] div.style-scope.ytd-watch-flexy + ytd-watc
}
*/
/*--------------------------------------------------------------
# SHOW EXACT UPLOAD DATE
--------------------------------------------------------------*/
html[it-exact-upload-date='true'] #info #date,
html[it-exact-upload-date='true'] #info #date + #info-strings>#dot,
.it-channel-exact-upload-date {
float: right !important;
margin-left: 4px !important;
color: var(--yt-spec-text-secondary) !important;
}
/*--------------------------------------------------------------
# HOW LONG AGO THE VIDEO WAS UPLOADED
--------------------------------------------------------------*/
.it-how-long-ago-the-video-was-uploaded {
Expand Down
2 changes: 2 additions & 0 deletions js&css/web-accessible/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ ImprovedTube.ytElementsHandler = function (node) {
if (document.documentElement.dataset.pageType === 'video') {
this.howLongAgoTheVideoWasUploaded();
this.channelVideosCount();
this.exactUploadDate();
}
//} else if (name === 'YTD-MENU-RENDERER' && node.classList.contains('ytd-video-primary-info-renderer')) {
// if (document.documentElement.dataset.pageType === 'video') {
Expand Down Expand Up @@ -275,6 +276,7 @@ ImprovedTube.videoPageUpdate = function () {

ImprovedTube.howLongAgoTheVideoWasUploaded();
ImprovedTube.dayOfWeek();
ImprovedTube.exactUploadDate();
ImprovedTube.channelVideosCount();
ImprovedTube.upNextAutoplay();
ImprovedTube.playerAutofullscreen();
Expand Down
79 changes: 79 additions & 0 deletions js&css/web-accessible/www.youtube.com/appearance.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,85 @@ ImprovedTube.dayOfWeek = function () {
}, 4321);
}
};
/*------------------------------------------------------------------------------
SHOW EXACT UPLOAD DATE
------------------------------------------------------------------------------*/
// ImprovedTube.exactUploadDate = function () {
// if(this.exact_date==true && this.elements.yt_channel_link) {
// // var xhr = new XMLHttpRequest(),
// // key = this.storage["google-api-key"] || ImprovedTube.defaultApiKey,
// // id = this.getParam(location.href.slice(location.href.indexOf("?") + 1), "v");
// // xhr.open("GET", "https://www.googleapis.com/youtube/v3/videos?part=snippet&id=" + id + "&key=" + key, false);
// // xhr.send();
// // if (xhr.readyState === xhr.DONE && xhr.status === 200) {
// // var response = JSON.parse(xhr.responseText);
// // var date = response.items[0].snippet.publishedA;
// // var element = ImprovedTube.elements.exact_upload_date || document.createElement("div");
// // ImprovedTube.empty(element);
// // element.appendChild(document.createTextNode("• " + date.toLocaleDateString()));
// // element.className = "it-exact-upload-date";
// // ImprovedTube.elements.exact_upload_date = element;
// // document.querySelector("#info #info-text").appendChild(element);
// // }
// var xhr = new XMLHttpRequest(),
// key = this.storage["google-api-key"] || ImprovedTube.defaultApiKey,

// id = this.getParam(location.href.slice(location.href.indexOf("?") + 1), "v");
// xhr.addEventListener("load", function () {
// var response = JSON.parse(this.responseText);
// element = ImprovedTube.elements.exact_date || document.createElement("div");

// ImprovedTube.empty(element);

// if (response.error) {
// element.appendChild(document.createTextNode("• Error: " + response.error.code));
// } else {
// element.appendChild(document.createTextNode("• " + response.items[0].snippet.publishedAt));
// }

// element.className = "it-channel-exact-upload-date";

// ImprovedTube.elements.exact_date = element;

// document.querySelector("#info #info-text").appendChild(element);
// });

// xhr.open("GET", "https://www.googleapis.com/youtube/v3/videos?part=snippet&id=" + id + "&key=" + key, true);
// xhr.send();
// console.log("exact date toggle on")
// }
// console.log("exact date tesst")
// };
ImprovedTube.exactUploadDate = function () {
if (this.storage.exact_date === true) {
const xhr = new XMLHttpRequest();
const key = this.storage["google-api-key"] || ImprovedTube.defaultApiKey;
const id = this.getParam(location.href.slice(location.href.indexOf("?") + 1), "v");

xhr.addEventListener("load", function () {
const response = JSON.parse(this.responseText);
const element = ImprovedTube.elements.exact_date || document.createElement("div");

ImprovedTube.empty(element);

if (response.error) {
element.appendChild(document.createTextNode(`• Error: ${response.error.code}`));
} else {
const publishedDate = new Date(response.items[0].snippet.publishedAt);
element.appendChild(document.createTextNode(`• ${publishedDate.toLocaleDateString()}`));
}

element.className = "it-channel-exact-upload-date";
ImprovedTube.elements.exact_date = element;
document.querySelector("#info #info-text").appendChild(element);
});

xhr.open("GET", `https://www.googleapis.com/youtube/v3/videos?part=snippet&id=${id}&key=${key}`, true);
xhr.send();
console.log("exact date toggle on");
}
console.log("exact date test");
};
/*------------------------------------------------------------------------------
HOW LONG AGO THE VIDEO WAS UPLOADED
------------------------------------------------------------------------------*/
Expand Down
4 changes: 4 additions & 0 deletions menu/skeleton-parts/appearance.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ extension.skeleton.main.layers.section.appearance.on.click.details = {
component: "switch",
text: "howLongAgoTheVideoWasUploaded"
},
exact_date: {
component: "switch",
text: "showExactDate"
},
channel_videos_count: {
component: "switch",
text: "showChannelVideosCount"
Expand Down