Skip to content

Instantly share code, notes, and snippets.

@Asseel-Naji
Created June 11, 2023 04:51
Show Gist options
  • Save Asseel-Naji/694eabfca80f233a4f54a1e04bd4db87 to your computer and use it in GitHub Desktop.
Save Asseel-Naji/694eabfca80f233a4f54a1e04bd4db87 to your computer and use it in GitHub Desktop.
Get current youtube video at current time URL and send in an API request. Used with tasker/join app + enhancer for YouTube.
/*
Author: Asseel Naji (https://naji.bio)
License: wtfpl (Do What The F*ck You Want To Public License)
---
This script is ready to be used with Join/tasker to grab the current link at the current time and send it to join.
The script can be loaded with "enhancer for youtube plugin" (https://www.mrfdev.com/enhancer-for-youtube), tempermonkey or any plugin that
can run javascript on a youtube site.
If you use join simply replace apikey and deviceId and you're ready to go.
*/
// Define API key
var apikey = 'REPLACE_ME';
var deviceId = 'REPLACE_ME';
// Get the current video's link
var videoLink = window.location.href;
// Check if the link is a playlist URL
var playlistParam = 'list=';
if (videoLink.includes(playlistParam)) {
const playlistIndex = videoLink.indexOf(playlistParam);
videoLink = videoLink.substring(0, playlistIndex);
}
// Get the current time and format it without decimal points
var currentTime = Math.floor(document.querySelector('.video-stream.html5-main-video').currentTime);
var videoLinkWithTime = videoLink + (videoLink.includes('?') ? '&' : '?') + 't=' + currentTime;
// Encode the video link with time for API call
var encodedVideoLink = encodeURIComponent(videoLinkWithTime);
// Prepare the URL for the GET request
var apiUrl = `https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush?apikey=${apikey}&deviceId=${deviceId}&url=${encodedVideoLink}`;
// Send a GET request
fetch(apiUrl)
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error('Error: ' + response.status);
}
})
.then(data => {
console.log('API Response:', data);
})
.catch(error => {
console.error('API Error:', error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment