Invidious Local Subscriptions

Implements local subscriptions on Invidious.

  1. // ==UserScript==
  2. // @name Invidious Local Subscriptions
  3. // @author mthsk
  4. // @homepage https://codeberg.org/mthsk/userscripts/src/branch/master/inv-local-subscriptions
  5. // @match *://invidio.xamh.de/*
  6. // @match *://vid.puffyan.us/*
  7. // @match *://watch.thekitty.zone/*
  8. // @match *://y.com.sb/*
  9. // @match *://yewtu.be/*
  10. // @match *://youchu.be/*
  11. // @match *://youtube.076.ne.jp/*
  12. // @match *://inv.*.*/*
  13. // @match *://invidious.*/*
  14. // @version 2024.06
  15. // @description Implements local subscriptions on Invidious.
  16. // @run-at document-end
  17. // @grant GM.getValue
  18. // @grant GM.setValue
  19. // @grant GM.xmlHttpRequest
  20. // @license AGPL-3.0
  21. // @namespace https://greasyfork.org/users/751327
  22. // ==/UserScript==
  23. /**
  24. * This program is free software: you can redistribute it and/or modify
  25. * it under the terms of the GNU Affero General Public License as
  26. * published by the Free Software Foundation, either version 3 of the
  27. * License.
  28. *
  29. * This program is distributed in the hope that it will be useful,
  30. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  32. * GNU Affero General Public License for more details.
  33. *
  34. * You should have received a copy of the GNU Affero General Public License
  35. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  36. */
  37. (async function() {
  38. "use strict";
  39. let subscriptions = await GM.getValue("subscriptions") || [];
  40. let settings = await GM.getValue("settings") || {redirect: false, odysee: false, usepiped: true, pipedinstance: "https://pipedapi-libre.kavin.rocks"};
  41.  
  42. if (settings.redirect && location.pathname === "/")
  43. location.replace(location.protocol + "//" + location.hostname + "/search?q=" + makeid((Math.floor(Math.random() * 16) + 16)) + "#invlocal");
  44. else if (settings.redirect)
  45. document.body.querySelectorAll('a[href="/"]').forEach((el) => el.setAttribute("href","/search?q=" + makeid((Math.floor(Math.random() * 16) + 16)) + "#invlocal"));
  46.  
  47. if (location.pathname.toLowerCase() === "/search" && location.search.toLowerCase().startsWith("?q=") && !location.search.includes('&') && location.hash.toLowerCase() === "#invlocal")
  48. {
  49. const navbar = document.createElement("div");
  50. navbar.classList.add("feed-menu");
  51. navbar.innerHTML = '<a href="/feed/popular" class="feed-menu-item pure-menu-heading">Popular</a><a href="/feed/trending" class="feed-menu-item pure-menu-heading">Trending</a><a id="invlocal-refresh" href="javascript:void(0);" class="feed-menu-item pure-menu-heading">Refresh Subscriptions</a>';
  52. const filters = document.getElementById("filters");
  53. filters.parentElement.replaceChild(navbar, filters);
  54. document.body.querySelector('#contents div[class="pure-g"]').innerHTML = '\<center id="invlocal-loading" style="letter-spacing: 0 !important;">Fetching subscriptions...</center>';
  55. document.body.querySelectorAll('#contents div > a[href*="&page="]').forEach(el => el.parentElement.remove());
  56. document.body.querySelectorAll("#contents div.no-results-error").forEach(el => { el.remove(); document.body.querySelector("#contents footer > div.pure-g").parentElement.replaceWith(document.body.querySelector("#contents footer > div.pure-g")); });
  57. document.body.querySelectorAll('a[href$="?referer=' + encodeURIComponent(location.pathname + location.search) + '"]').forEach(el => el.href = el.href + location.hash);
  58. document.getElementById("contents").getElementsByTagName("hr")[0].remove();
  59. document.getElementById("searchbox").value = "";
  60. document.title = "Local Subscription Feed - Invidious";
  61. let feed;
  62. if (settings.hasOwnProperty("usepiped") && settings.usepiped)
  63. feed = await getPipedSubscriptionFeed(settings.pipedinstance);
  64. else
  65. feed = await getSubscriptionFeed(false);
  66. displaySubscriptionFeed(feed);
  67. let st = 40;
  68. addEventListener('scroll', function() {
  69. if (window.innerHeight + window.pageYOffset >= document.body.offsetHeight && !document.getElementById("invlocal-loading")) {
  70. displaySubscriptionFeed(feed, st);
  71. st = st + 40;
  72. }});
  73.  
  74. document.getElementById("invlocal-refresh").addEventListener('click', async function (e) {
  75. if (!e.target.hasAttribute('disabled'))
  76. {
  77. e.target.setAttribute('disabled', '');
  78. document.body.querySelector('#contents div[class="pure-g"]').innerHTML = '\<center id="invlocal-loading" style="letter-spacing: 0 !important;">Fetching subscriptions...</center>';
  79.  
  80. if (settings.hasOwnProperty("usepiped") && settings.usepiped)
  81. feed = await getPipedSubscriptionFeed(settings.pipedinstance);
  82. else
  83. feed = await getSubscriptionFeed(true);
  84.  
  85. displaySubscriptionFeed(feed);
  86. st = 40;
  87. e.target.removeAttribute('disabled');
  88. }
  89. });
  90. }
  91. else if (location.pathname.toLowerCase().startsWith("/feed/"))
  92. {
  93. document.getElementsByClassName("feed-menu")[0].innerHTML = document.getElementsByClassName("feed-menu")[0].innerHTML + "\<a href=\"/search?q=" + makeid((Math.floor(Math.random() * 16) + 16)) + "#invlocal\" class=\"feed-menu-item pure-menu-heading\">Local Subscriptions</a>"
  94. }
  95. else if (location.pathname.toLowerCase().startsWith("/channel/") || location.pathname.toLowerCase() === "/watch")
  96. {
  97. const invsubbutton = document.getElementById("subscribe");
  98. const localsubbutton = invsubbutton.cloneNode(true);
  99. localsubbutton.id = "localsubscribe";
  100. localsubbutton.removeAttribute("href");
  101. invsubbutton.parentElement.appendChild(localsubbutton);
  102.  
  103. let chid = "";
  104. let chname = "";
  105. if (location.pathname.toLowerCase().startsWith("/channel/"))
  106. {
  107. chid = location.pathname.split('/')[2];
  108. chname = document.body.querySelector('div[class="channel-profile"] span').textContent.trim();
  109. }
  110. else
  111. {
  112. chid = document.body.querySelector('a[href] .channel-profile').parentElement.getAttribute("href").split('/')[2];
  113. chname = document.getElementById("channel-name").textContent.trim();
  114. }
  115.  
  116. if (subscriptions.length > 0 && subscriptions.some(e => e.id === chid))
  117. localsubbutton.innerHTML = "\<b>Unsubscribe Locally</b>";
  118. else
  119. localsubbutton.innerHTML = "\<b>Subscribe Locally</b>";
  120.  
  121. localsubbutton.addEventListener("click", async function(ev) {
  122. if (subscriptions.length > 0 && subscriptions.some(e => e.id === chid)) { //unsubscribe if already subscribed
  123. if (!confirm("Do you really want to unsubscribe from \"" + chname + "\"?"))
  124. return;
  125.  
  126. let x = 0;
  127. subscriptions.forEach(function(e) {
  128. if (e.id === chid)
  129. {
  130. subscriptions.splice(x, 1);
  131. ev.target.innerHTML = "\<b>Subscribe Locally</b>";
  132. }
  133. x++;
  134. });
  135. }
  136. else // subscribe if not
  137. {
  138. subscriptions.push({id: chid, name: chname})
  139. ev.target.innerHTML = "\<b>Unsubscribe Locally</b>";
  140. }
  141. console.log(subscriptions);
  142. await GM.setValue('subscriptions', subscriptions);
  143. });
  144.  
  145. if (location.pathname.toLowerCase() === "/watch")
  146. {
  147. if (!settings.usepiped) window.setInterval(getSubscriptionFeed(false, true), 300000);
  148. }
  149. }
  150. else if (location.pathname.toLowerCase() === "/preferences")
  151. {
  152. let fieldset = document.body.getElementsByTagName("fieldset");
  153. fieldset = fieldset[fieldset.length - 1];
  154. const savebtn = fieldset.getElementsByTagName("button")[0];
  155. const nulegend = document.createElement('legend');
  156. nulegend.textContent = "Local Subscribe Preferences";
  157. const nusettings = document.createElement('div');
  158. nusettings.setAttribute("class", "pure-control-group");
  159. nusettings.innerHTML = '\<div class="pure-control-group"><div class="pure-control-group"><label for="invlocal_redirect">Redirect from the invidious home page to local subscriptions page: </label><input id="invlocal_redirect" type="checkbox"></div><div class="pure-control-group"><label for="invlocal_odysee">Display a "Watch on Odysee" button for videos that were synced to Odysee: </label><input id="invlocal_odysee" type="checkbox"></div><div class="pure-control-group"><label for="invlocal_usepiped">Fetch Subscriptions Through Piped: </label><input id="invlocal_usepiped" type="checkbox"></div><div class="pure-control-group"><label for="invlocal_pipedinstance">Database Instance:</label><input id="invlocal_pipedinstance" type="text"></div><div class="pure-control-group"><label for="invlocal_import">Import subscriptions: </label><a id="invlocal_import" href="javascript:void(0);">Import...</a></div><div class="pure-control-group"><label for="invlocal_export">Export subscriptions: </label><a id="invlocal_export" href="javascript:void(0);">Export...</a></div></div>';
  160. fieldset.insertBefore(nulegend, savebtn.parentElement);
  161. fieldset.insertBefore(nusettings, savebtn.parentElement);
  162.  
  163. document.getElementById("invlocal_redirect").checked = settings.redirect;
  164. document.getElementById("invlocal_odysee").checked = settings.odysee || false;
  165. document.getElementById("invlocal_usepiped").checked = settings.usepiped || false;
  166. document.getElementById("invlocal_pipedinstance").value = settings.pipedinstance || "https://pipedapi-libre.kavin.rocks";
  167.  
  168. document.getElementById("invlocal_import").addEventListener("click", (ev) => {
  169. const input = document.createElement("input");
  170. input.setAttribute("type", "file");
  171. input.setAttribute("accept", ".json");
  172. input.addEventListener("change", async function(e) {
  173. try {
  174. const file = await input.files[0].text();
  175. const newpipe_subs = JSON.parse(file);
  176. const nusubs = [];
  177. newpipe_subs.subscriptions.forEach((i) => {
  178. if (i.service_id === 0) {
  179. const chanurl = new URL(i.url);
  180. const chanid = chanurl.pathname.split("/channel/").pop().split('/')[0];
  181. nusubs.push({id: chanid, name: i.name});
  182. }
  183. });
  184. subscriptions = nusubs;
  185. await GM.setValue('subscriptions', subscriptions);
  186. await GM.setValue('feed', {last: 0, feed: []});
  187. alert("Subscriptions imported successfully!");
  188. }
  189. catch (ex) { alert("File is corrupted or not supported."); }
  190. });
  191. input.click();
  192. });
  193.  
  194. document.getElementById("invlocal_export").addEventListener("click", (ev) => {
  195. const date = new Date();
  196. const YYYYMMDDHHmm = date.getFullYear() + ("0" + (date.getMonth() + 1)).slice(-2) + ("0" + date.getDate()).slice(-2) + ("0" + date.getHours() ).slice(-2) + ("0" + date.getMinutes()).slice(-2);
  197. const newpipe_subs = {app_version: "0.24.0", app_version_int: 990, subscriptions: []};
  198. subscriptions.forEach((e) => {
  199. newpipe_subs.subscriptions.push({service_id: 0, url: "https://www.youtube.com/channel/" + e.id, name: e.name});
  200. });
  201. const a = document.createElement("a");
  202. const file = new Blob([JSON.stringify(newpipe_subs)], {type: "application/json"});
  203. a.href = URL.createObjectURL(file);
  204. a.download = "newpipe_subscriptions_" + YYYYMMDDHHmm + ".json";
  205. a.click();
  206. });
  207.  
  208. savebtn.addEventListener("click", (ev) => {
  209. settings.redirect = document.getElementById("invlocal_redirect").checked;
  210. settings.odysee = document.getElementById("invlocal_odysee").checked;
  211. settings.usepiped = document.getElementById("invlocal_usepiped").checked;
  212. if (document.getElementById("invlocal_pipedinstance").value.trim() != "")
  213. settings.pipedinstance = document.getElementById("invlocal_pipedinstance").value.trim();
  214. GM.setValue('settings', settings);
  215. });
  216. }
  217.  
  218. function makeid(length) {
  219. let result = "";
  220. const characters = "abcdefghijklmnopqrstuvwxyz0123456789";
  221.  
  222. for (let x = 0; x < length; x++)
  223. result += characters.charAt(Math.floor(Math.random() * characters.length));
  224.  
  225. return result;
  226. }
  227.  
  228. function roundViews(views) {
  229. let rounded = 0;
  230. let mode = "";
  231.  
  232. if (views >= 1000000000) {
  233. rounded = views / 1000000000;
  234. mode = "B";
  235. }
  236. else if (views >= 1000000) {
  237. rounded = views / 1000000;
  238. mode = "M"
  239. }
  240. else if (views >= 1000) {
  241. rounded = views / 1000;
  242. mode = "K"
  243. }
  244. else if (views > 1) {
  245. return views + " views";
  246. }
  247. else {
  248. return views + " view";
  249. }
  250.  
  251. if (rounded < 10)
  252. rounded = Math.floor(rounded * 10) / 10;
  253. else
  254. rounded = Math.floor(rounded);
  255.  
  256. return rounded + mode + " views";
  257. }
  258.  
  259. function msToHumanTime(ms) {
  260. const seconds = (ms / 1000);
  261. let tvalue = 0;
  262. let human = "";
  263.  
  264. if (seconds >= 31536000) {
  265. tvalue = Math.floor(seconds / 31536000);
  266. human = "year";
  267. }
  268. else if (seconds >= 2628000) {
  269. tvalue = Math.floor(seconds / 2628000);
  270. human = "month";
  271. }
  272. else if (seconds >= 604800) {
  273. tvalue = Math.floor(seconds / 604800);
  274. human = "week";
  275. }
  276. else if (seconds >= 86400) {
  277. tvalue = Math.floor(seconds / 86400);
  278. human = "day";
  279. }
  280. else if (seconds >= 3600) {
  281. tvalue = Math.floor(seconds / 3600);
  282. human = "hour";
  283. }
  284. else if (seconds >= 60) {
  285. tvalue = Math.floor(seconds / 60);
  286. human = "minute";
  287. }
  288. else {
  289. tvalue = Math.floor(seconds);
  290. human = "second";
  291. }
  292.  
  293. if (tvalue > 1)
  294. return tvalue + ' ' + human + "s ago";
  295. else
  296. return tvalue + ' ' + human + " ago";
  297. }
  298.  
  299. function durationString(scs) {
  300. const durDate = new Date(0);
  301. durDate.setSeconds(scs);
  302. const durHour = Math.floor(durDate.getTime() / 1000 / 60 / 60);
  303. const durMin = durDate.getUTCMinutes();
  304. const durSec = durDate.getUTCSeconds();
  305.  
  306. return (durHour > 0 ? durHour + ':' : '') + (durHour === 0 || durMin > 9 ? durMin : '0' + durMin) + ':' + (durSec > 9 ? durSec : '0' + durSec);
  307. }
  308.  
  309. async function displaySubscriptionFeed(feed,start = 0) {
  310. const container = document.getElementById("contents").querySelector('div[class="pure-g"]');
  311.  
  312. if (!container || start >= feed.length) {
  313. const elloading = document.getElementById('invlocal-loading');
  314. if (!!elloading && feed.length === 0)
  315. elloading.textContent = "No subscriptions to fetch.";
  316. return;
  317. }
  318.  
  319. if (start === 0)
  320. container.innerHTML = "";
  321.  
  322. let finish = start + 39;
  323. if (finish > (feed.length - 1))
  324. finish = feed.length - 1;
  325.  
  326. const vidIds = [];
  327. for (let x = start; x <= finish; x++)
  328. {
  329. vidIds.push(feed[x].videoId);
  330. container.innerHTML += '\<div class="pure-u-1 pure-u-md-1-4"><div class="h-box"><a style="width:100%" href="/watch?v=' + feed[x].videoId + '"><div class="thumbnail"><img tabindex="-1" class="thumbnail" src="/vi/' + feed[x].videoId + '/mqdefault.jpg"/> <div class="bottom-right-overlay"><p class="length">' + durationString(feed[x].lengthSeconds) + '\</p></div></div><p dir="auto">' + feed[x].title + '\</p></a><div class="video-card-row flexible"><div class="flex-left"><a href="/channel/' + feed[x].authorId + '"><p class="channel-name" dir="auto">' + feed[x].author + '\</p> </a></div> <div class="flex-right"><div class="icon-buttons"><a title="Watch on YouTube" href="https://www.youtube.com/watch?v=' + feed[x].videoId + '"><i class="icon ion-logo-youtube"></i></a> <a class="invlocal-odysee" style="visibility: hidden !important;" title="Watch on Odysee" href="' + feed[x].videoId + '"><i class="icon ion-md-rocket"></i></a> <a title="Discuss on Reddit" href="https://www.reddit.com/search?q=url%3A%22' + feed[x].videoId + '%22+AND+%28site%3Ayoutube.com+OR+site%3Ayoutu.be+OR+site%3Ayoutube-nocookie.com%29&amp;restrict_sr=&amp;sort=top&amp;t=all"><i class="icon ion-logo-reddit"></i></a> <a title="Audio mode" href="/watch?v=' + feed[x].videoId + '&amp;listen=1"><i class="icon ion-md-headset"></i></a> <a title="Switch Invidious Instance" href="https://redirect.invidious.io/watch?v=' + feed[x].videoId + '"><i class="icon ion-md-jet"></i></a></div></div></div> <div class="video-card-row flexible"><div class="flex-left"><p class="video-data" dir="auto">Shared ' + msToHumanTime(Date.now() - (feed[x].published * 1000)) + '\</p></div><div class="flex-right"><p class="video-data" dir="auto">' + roundViews(feed[x].viewCount) + '\</p></div></div></div></div>';
  331. }
  332. /*container.querySelectorAll('a[href^="https://www.reddit.com/search?q=url%3A%22"]').forEach((el) => {
  333. const vId = el.href.split("%22")[1];
  334. el.href = "javascript:void(0);";
  335. el.addEventListener("mouseover", async (ev) => {
  336. if (ev.target.parentElement.href === "javascript:void(0);") {
  337. const vEl = ev.target.parentElement.parentElement.parentElement.parentElement.parentElement;
  338. const reddit = await getJson("https://rss-to-json-serverless-api.vercel.app/api?feedURL=https%3A%2F%2Fwww.reddit.com%2Fsearch.rss%3Fq%3Durl%253A%2522" + vId + "%2522%2BAND%2B%2528site%253Ayoutube.com%2BOR%2Bsite%253Ayoutu.be%2BOR%2Bsite%253Ayoutube-nocookie.com%2529%26restrict_sr%3D%26sort%3Dtop%26t%3Dall", 0);
  339. if (reddit.items.length > 0)
  340. {
  341. ev.target.parentElement.href = reddit.items[0].url;
  342. }
  343. else
  344. {
  345. const vTitle = vEl.querySelector('a[href*="/watch?v="] p[dir="auto"]').textContent;
  346. const vChannel = vEl.getElementsByClassName("channel-name")[0].textContent;
  347. ev.target.parentElement.href = "https://www.reddit.com/r/videos/submit?title=" + encodeURIComponent(vTitle + " — " + vChannel) + "&url=" + encodeURIComponent("https://www.youtube.com/watch?v=" + vId);
  348. }
  349. }
  350. });
  351. });*/
  352. let odyUrls = {};
  353. if (!!settings.odysee && settings.odysee) {
  354. odyUrls = await getJson("https://api.odysee.com/yt/resolve?video_ids=" + encodeURIComponent(vidIds.join(',')), 0);
  355. odyUrls = (!!odyUrls.data && !!odyUrls.data.videos ? odyUrls.data.videos : {});
  356. }
  357. const odyseeEls = document.body.querySelectorAll("a.invlocal-odysee[href]");
  358. odyseeEls.forEach((ody) => {
  359. let vId = ody.getAttribute('href');
  360. if (!!settings.odysee && settings.odysee && odyUrls.hasOwnProperty(vId) && odyUrls[vId] !== null)
  361. {
  362. ody.href = "https://odysee.com/" + odyUrls[vId].replaceAll('#',':');
  363. ody.removeAttribute("class");
  364. ody.removeAttribute("style");
  365. }
  366. else {
  367. ody.remove();
  368. }
  369. });
  370. }
  371.  
  372. async function getJson(url,timeout=10000) {
  373. console.log("Connecting to " + url);
  374. try {
  375. const resp = await (function() {
  376. return new Promise((resolve, reject) => {
  377. GM.xmlHttpRequest({
  378. method: 'GET',
  379. url: url,
  380. timeout: timeout,
  381. headers: {
  382. 'Accept': 'application/json'
  383. },
  384. onload: resolve,
  385. onabort: reject,
  386. onerror: reject,
  387. ontimeout: reject
  388. });
  389. });
  390. })();
  391. return JSON.parse(resp.responseText);
  392. } catch (e) { return { error: true }; }
  393. }
  394.  
  395. async function getSubscriptionFeed(forced = false, background = false) {
  396. let feed = await GM.getValue('feed');
  397. if (forced || !feed || feed.last < (Date.now() - 1800000))
  398. {
  399. let hadError = false;
  400. feed = [];
  401. const instances = [];
  402. let jsonInstances = await getJson("https://api.invidious.io/instances.json");
  403.  
  404. if ((Object.keys(jsonInstances).length === 0 && jsonInstances.construct) || (jsonInstances.hasOwnProperty("error") && jsonInstances.error))
  405. return;
  406.  
  407. jsonInstances.forEach(function(e) {
  408. if (e[1].type === "https" && e[1].api)
  409. {
  410. instances.push(e[0]);
  411. }
  412. });
  413. console.log(instances);
  414.  
  415. if (instances.length <= 0)
  416. return;
  417.  
  418. for (let x = 0; x < subscriptions.length; x++)
  419. {
  420. if (!!document.getElementById('invlocal-loading'))
  421. document.getElementById('invlocal-loading').textContent = "Fetching channel " + (x + 1) + " out of " + subscriptions.length;
  422.  
  423. let response = await getJson("https://" + instances[Math.floor(Math.random()*instances.length)] + "/api/v1/channels/videos/" + subscriptions[x].id + "?fields=title,videoId,author,authorId,viewCount,published,lengthSeconds,videos");
  424.  
  425. if (response.hasOwnProperty("error") && background)
  426. return;
  427. else if (response.hasOwnProperty("error"))
  428. {
  429. hadError = true;
  430. continue;
  431. }
  432. else if (response.hasOwnProperty("videos"))
  433. response = response.videos;
  434.  
  435. let playlist = await getJson("https://" + instances[Math.floor(Math.random()*instances.length)] + "/api/v1/playlists/" + subscriptions[x].id + "?fields=videos(title,videoId,author,authorId,lengthSeconds)");
  436. if (playlist.hasOwnProperty("videos"))
  437. {
  438. playlist = playlist.videos;
  439.  
  440. if (playlist.length > 10)
  441. playlist = playlist.slice(0, 10);
  442.  
  443. let plv = 0;
  444. playlist.forEach(async function(vid) {
  445. if (!response.some(e => e.videoId === vid.videoId))
  446. {
  447. let vidData = await getJson("https://" + instances[Math.floor(Math.random()*instances.length)] + "/api/v1/videos/" + vid.videoId + "?fields=viewCount,published");
  448. if (!vidData.hasOwnProperty("error"))
  449. {
  450. vid.viewCount = vidData.viewCount;
  451. vid.published = vidData.published;
  452. feed.push(vid);
  453. }
  454. }
  455. plv++;
  456. });
  457. }
  458.  
  459. feed = feed.concat(response);
  460. }
  461.  
  462. feed.sort((a, b) => b.published - a.published);
  463.  
  464. if (!hadError)
  465. await GM.setValue('feed', {last: Date.now(), feed: feed});
  466. else
  467. await GM.setValue('feed', {last: 0, feed: feed});
  468.  
  469. return feed;
  470. }
  471. else
  472. return feed.feed;
  473. }
  474.  
  475. async function getPipedSubscriptionFeed(api = "pipedapi.kavin.rocks") {
  476. let feed = [];
  477. const channels = [];
  478. subscriptions.forEach(ch => channels.push(ch.id));
  479. const response = await getJson(api + "/feed/unauthenticated?channels=" + encodeURIComponent(channels.join(',')), 0);
  480.  
  481. if (response.hasOwnProperty("error"))
  482. {
  483. feed = await GM.getValue('feed');
  484.  
  485. if (!!feed && !!feed.feed)
  486. return feed.feed;
  487. else
  488. return [];
  489. }
  490.  
  491. response.forEach((e) => {
  492. feed.push({title: e.title, videoId: e.url.split("?v=").pop(), author: e.uploaderName, authorId: e.uploaderUrl.split("/channel/").pop(), viewCount: e.views, published: (e.uploaded / 1000), lengthSeconds: e.duration});
  493. });
  494. await GM.setValue('feed', {last: Date.now(), feed: feed});
  495. return feed;
  496. }
  497. })();