Skip to content

Commit

Permalink
fix: #1869, day of the week, hide day
Browse files Browse the repository at this point in the history
  • Loading branch information
ImprovedTube committed Dec 6, 2023
1 parent df2cac1 commit d42387b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 39 deletions.
2 changes: 1 addition & 1 deletion js&css/extension/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,5 @@ document.addEventListener('it-message-from-youtube', function () {
document.addEventListener('it-play', function (event) {
var videos = document.querySelectorAll('video');
try {chrome.runtime.sendMessage({action: 'play'})}
catch(error){console.log(error); chrome.runtime.sendMessage({action: 'play'}, function (response) { } ); }
catch(error){console.log(error); setTimeout(function () { try { chrome.runtime.sendMessage({action: 'play'}, function (response) { console.log(response) } ); } catch { } }, 321) }
});
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ html[it-hide-views-count='true'] ytd-watch-metadata #info>span:first-child,
/*------# HIDE COMMENTS COUNT---*/
html[it-hide-comments-count='true'] #comments #count,
/*------# HIDE DATE-------------*/
html[it-hide-date='true'] #info span:nth-child(3),
html[it-hide-date='true'] #info #count + #info-strings>yt-formatted-string,
html[it-hide-date='true'] #info #count + #info-strings>#dot,
html[it-hide-date='true'] ytd-watch-metadata #info>span:last-child,
Expand Down
16 changes: 8 additions & 8 deletions js&css/web-accessible/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ var ImprovedTube = {
blacklist_buttons: []
},
regex: {
channel: new RegExp('\/(@|c\/@?|channel\/|user\/)(?<name>[^/]+)'),
channel_home_page: new RegExp('\/@|((channel|user|c)\/)[^/]+(\/featured)?\/?$'),
channel_home_page_postfix: new RegExp('\/(featured)?\/?$'),
thumbnail_quality: new RegExp('(default\.jpg|mqdefault\.jpg|hqdefault\.jpg|hq720\.jpg|sddefault\.jpg|maxresdefault\.jpg)+'),
video_id: new RegExp('[?&]v=([^&]+)'),
video_time: new RegExp('[?&](?:t|start)=([^&]+)'),
playlist_id: new RegExp('[?&]list=([^&]+)'),
channel_link: new RegExp('https:\/\/www.youtube.com\/@|((channel|user|c)\/)')
channel: /\/(@|c\/@?|channel\/|user\/)(?<name>[^/]+)/,
channel_home_page: /\/@|((channel|user|c)\/)[^/]+(\/featured)?\/?$/,
channel_home_page_postfix: /\/(featured)?\/?$/,
thumbnail_quality: /(default\.jpg|mqdefault\.jpg|hqdefault\.jpg|hq720\.jpg|sddefault\.jpg|maxresdefault\.jpg)+/,
video_id: /(?:[?&]v=|embed\/)([^&?]+)/,
video_time: /[?&](?:t|start)=([^&]+)/,
playlist_id: /[?&]list=([^&]+)/,
channel_link: /https:\/\/www.youtube.com\/@|((channel|user|c)\/)/
},
video_src: false,
initialVideoUpdateDone: false,
Expand Down
21 changes: 6 additions & 15 deletions js&css/web-accessible/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,21 +564,9 @@ ImprovedTube.createPlayerButton = function (options) {
controls.insertBefore(button, controls.childNodes[3]);
}
};

ImprovedTube.empty = function (element) {
for (var i = element.childNodes.length - 1; i > -1; i--) {
element.childNodes[i].remove();
}
};

ImprovedTube.isset = function (variable) {
return !(typeof variable === 'undefined' || variable === null || variable === 'null');
};

ImprovedTube.stopPropagation = function (event) {
event.stopPropagation();
};

ImprovedTube.empty = function (element) {for (var i = element.childNodes.length - 1; i > -1; i--) { element.childNodes[i].remove(); }};
ImprovedTube.isset = function (variable) { return !(typeof variable === 'undefined' || variable === null || variable === 'null');};
ImprovedTube.stopPropagation = function (event) { event.stopPropagation(); };
ImprovedTube.showStatus = function (value) {
if (!this.elements.status) {
this.elements.status = document.createElement('div');
Expand All @@ -602,3 +590,6 @@ ImprovedTube.showStatus = function (value) {

this.elements.player.appendChild(this.elements.status);
};

ImprovedTube.videoId = function (url = document.URL) { return url.match(ImprovedTube.regex.video_id)[1] || new URL(url).searchParams.get('v') || movie_player.getVideoData().video_id }
ImprovedTube.videoTitle = function () { return document.title?.replace(/\s*-\s*YouTube$/, '') || movie_player.getVideoData().title || document.querySelector('#title > h1 > *')?.textContent }
14 changes: 7 additions & 7 deletions js&css/web-accessible/www.youtube.com/appearance.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,18 +428,18 @@ ImprovedTube.hideDetailButton = function (el) {
ImprovedTube.dayOfWeek = function () { if (this.storage.day_of_week === true) {
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
setTimeout(function () {
var videoDate = document.querySelector("[itemprop=datePublished]").content;
var videoDate; try { videoDate = JSON.parse(document.querySelector('#microformat script')?.textContent)?.uploadDate } //YouTube related video or internal link?
catch { try { videoDate = document.querySelector("[itemprop=datePublished]").content;} catch { } } //..no? must be new session?
var tempDate = new Date(videoDate);
var element = document.querySelector(".ytd-day-of-week");
if (!element) {
var label = document.createElement("span");
label.textContent = " , " + days[tempDate.getDay() + 1];
label.textContent = days[tempDate.getDay() + 1] + ' ';
label.className = "ytd-day-of-week";
document.querySelector("ytd-video-primary-info-renderer #info #info-strings yt-formatted-string").append(label);
} else {
element.textContent = days[tempDate.getDay() + 1] + ", ";
}
}, 25);
//update please:
try {document.querySelector("#info span:nth-child(2)")?.append(label);} catch { try {document.querySelector("#info #info-strings yt-formatted-string")?.append(label);}catch {}}
} // else { element.textContent = days[tempDate.getDay() + 1] + ", "; }
}, 4321);
}
};
/*------------------------------------------------------------------------------
Expand Down
16 changes: 8 additions & 8 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,16 @@ console.log("genre: " + DATA.genre + "//title: " + DATA.title + "//keywords: "
DATA = {};
defaultKeywords = "video,sharing,camera,phone,video phone,free,upload";
DATA.keywords = false; keywords = false; amountOfSongs = false;
DATA.videoID = location.href.match(/(\?|\&)v=[^&]+/)?.[0].substr(3) || location.href.match(/()embed\/[^&]+/)?.[0].substr(3) || improvedTube.videoID || false;
ImprovedTube.fetchDOMData = function () {
try { DATA = JSON.parse(document.getElementById('scriptTag')?.textContent) ?? false; DATA.title = DATA.name;}
catch (error) {
console.error('Error parsing id="scriptTag"\'s JSON:', error);
DATA.genre = false; DATA.keywords = false; DATA.lengthSeconds = false;
DATA.videoID = improvedTube.videoId() || false;
ImprovedTube.fetchDOMData = function () {
// if (history.length > 1 && history.state.endpoint.watchEndpoint) {
try { DATA = JSON.parse(document.querySelector('#microformat script')?.textContent) ?? false; DATA.title = DATA.name;}
catch { DATA.genre = false; DATA.keywords = false; DATA.lengthSeconds = false;
try {
DATA.title = document.getElementsByTagName('meta')?.title?.content || false;
DATA.genre = document.querySelector('meta[itemprop=genre]')?.content || false;
DATA.duration = document.querySelector('meta[itemprop=duration]')?.content || false;
} if ( false )
} catch {}} if ( DATA.title === ImprovedTube.videoTitle() )
{ keywords = document.getElementsByTagName('meta')?.keywords?.content || false; if(!keywords){keyword=''} ImprovedTube.speedException(); }
else { keywords = ''; (async function () { try { const response = await fetch(`https://www.youtube.com/watch?v=${DATA.videoID}`);

Expand Down Expand Up @@ -581,7 +581,7 @@ ImprovedTube.screenshot = function () {
var a = document.createElement('a');
a.href = URL.createObjectURL(blob); console.log("screeeeeeenshot tada!");

a.download = location.href.match(/(\?|\&)v=[^&]+/)[0].substr(3) || location.href.match(/()embed\/[^&]+/)[0].substr(3) || improvedTube.videoID || location.href.match + '-' + new Date(ImprovedTube.elements.player.getCurrentTime() * 1000).toISOString().substr(11, 8).replace(/:/g, '-') + '.png';
a.download = (ImprovedTube.videoId() || location.href.match) + '-' + new Date(ImprovedTube.elements.player.getCurrentTime() * 1000).toISOString().substr(11, 8).replace(/:/g, '-') + '-' + ImprovedTube.videoTitle() + '.png';

a.click();
} else {
Expand Down

0 comments on commit d42387b

Please sign in to comment.