diff --git a/js&css/extension/init.js b/js&css/extension/init.js index be8a84800..b48f2c4f7 100644 --- a/js&css/extension/init.js +++ b/js&css/extension/init.js @@ -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) } }); \ No newline at end of file diff --git a/js&css/extension/www.youtube.com/appearance/details/details.css b/js&css/extension/www.youtube.com/appearance/details/details.css index 908db761f..e33356e68 100644 --- a/js&css/extension/www.youtube.com/appearance/details/details.css +++ b/js&css/extension/www.youtube.com/appearance/details/details.css @@ -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, diff --git a/js&css/web-accessible/core.js b/js&css/web-accessible/core.js index d065750dd..2501b64b8 100644 --- a/js&css/web-accessible/core.js +++ b/js&css/web-accessible/core.js @@ -30,14 +30,14 @@ var ImprovedTube = { blacklist_buttons: [] }, regex: { - channel: new RegExp('\/(@|c\/@?|channel\/|user\/)(?[^/]+)'), - 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\/)(?[^/]+)/, + 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, diff --git a/js&css/web-accessible/functions.js b/js&css/web-accessible/functions.js index ca098f512..a9ed23910 100644 --- a/js&css/web-accessible/functions.js +++ b/js&css/web-accessible/functions.js @@ -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'); @@ -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 } \ No newline at end of file diff --git a/js&css/web-accessible/www.youtube.com/appearance.js b/js&css/web-accessible/www.youtube.com/appearance.js index 592dd1980..27a69e8e0 100644 --- a/js&css/web-accessible/www.youtube.com/appearance.js +++ b/js&css/web-accessible/www.youtube.com/appearance.js @@ -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); } }; /*------------------------------------------------------------------------------ diff --git a/js&css/web-accessible/www.youtube.com/player.js b/js&css/web-accessible/www.youtube.com/player.js index bca88f66a..3f09f2053 100644 --- a/js&css/web-accessible/www.youtube.com/player.js +++ b/js&css/web-accessible/www.youtube.com/player.js @@ -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}`); @@ -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 {