· 5 years ago · Jan 20, 2021, 06:28 PM
1!function(){"use strict";!function e(){"undefined"!=typeof API&&API.enabled&&"undefined"!=typeof jQuery&&"undefined"!=typeof require?function(){var e={},t={},i=localStorage.getItem("yt-api-key");function o(){$.ajax({url:`https://www.googleapis.com/youtube/v3/videos?id=${t.cid}&key=${gapi.config.get().client.apiKey}&part=snippet,contentDetails`,type:"GET",success:i=>{if(t.author=i.items[0].snippet.title.split("-"),1===t.author.length)t.title=t.author[0].trim(),t.author=i.items[0].snippet.channelTitle;else{var o=t.author.shift().trim();t.title=t.author.join("-").trim(),t.author=o}t.image=i.items[0].snippet.thumbnails.default.url,t.duration=function(e){var t=e.match(/\d+/g),i=e.indexOf("H"),o=e.indexOf("M"),a=e.indexOf("S");switch(!0){case o>=0&&-1==i&&-1==a:t=[0,t[0],0];break;case i>=0&&-1==o:t=[t[0],0,t[1]];break;case i>=0&&-1==o&&-1==a:t=[t[0],0,0]}switch(e=0,t.length){case 1:e+=parseInt(t[0]);break;case 2:e+=60*parseInt(t[0]),e+=parseInt(t[1]);break;case 3:e+=3600*parseInt(t[0]),e+=60*parseInt(t[1]),e+=parseInt(t[2])}return e}(i.items[0].contentDetails.duration),t.format=1,t.id=-1,$.ajax({url:`/_/playlists/${e.id}/media/insert`,type:"POST",data:JSON.stringify({media:[t],append:!1}),contentType:"application/json",success:()=>alert("Media added!\nIf you don't see it, try switching playlists or refreshing."),error:e=>{"maxItems"===e.responseJSON.status?alert("This playlist is full!"):alert("Sorry, the media couldn't be added.")}})},error:e=>{e.responseJSON.error.message.indexOf("Daily Limit")>-1||e.responseJSON.error.errors&&"quotaExceeded"==e.responseJSON.error.errors[0].reason?alert('The current API Key has exceeded its quota.\nTry setting your own by typing "/key [YOUR KEY HERE]" in the chat'):(console.error("[YT-WORKAROUND]",e),e.responseJSON.error.message?alert("YouTube error: "+e.responseJSON.error.message):alert("Something went wrong with YouTube. You can check the console for more info."))}})}null==i?(i="AIzaSyD--___tekD3NI_-Sj8cAnNyuDKFmdtOkM",API.chatLog("⚠ YT-workaround is using the default API key, this is not recommended as everyone uses the same and it is limited. You should get your own and configure it with /key [YOUR KEY HERE]")):API.chatLog("YT-workaround is using a custom key!"),window.gapi.client.setApiKey(i);var a=$('<div id="playlist-add-button" class="button" title="YouTube Grab+"><i class="fa fa-plus-square"></i></div>'),r=_.find(require.s.contexts._.defined,e=>e&&e.activeMedia);a.click(function(){r.models.forEach(i=>{(i=i.toJSON()).visible&&(200===i.count?alert(`${i.name} is full!`):(e=i,t.cid=prompt(`Importing in ${e.name}:\nVideo's link:`),0!=!!t.cid&&(t.cid=t.cid.replace(/(?:https?:)?(?:\/\/)?(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube(?:-nocookie)?\.com\/\S*?[^\w\s-])((?!videoseries)[\w-]{11})(?=[^\w-]|$)(?![?=&+%\w.-]*(?:['"][^<>]*>|<\/a>))[?=&+%\w.-]*/gi,"$1"),o())))})}),$(".playlist-buttons-container .playlist-edit-group").prepend(a),API.on(API.CHAT_COMMAND,function(e){if("/key"===(e=e.split(" "))[0]&&2==e.length){if(!1===/AIza[0-9A-z\-_]{35}/.test(e[1]))return void API.chatLog("This is not a valid YT API Key!");window.gapi.client.setApiKey(e[1]),localStorage.setItem("yt-api-key",e[1]),API.chatLog("Custom API key saved!")}else API.chatLog("Please use this format: /key [KEY] (do not include the square brackets obviously)")}),API.chatLog("YT-workaround fully loaded! Refresh to de-activate it.")}():setTimeout(e,200)}()}();