theYNC.com Underground bypass

Watch theYNC Underground videos without needing an account

当前为 2025-01-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name theYNC.com Underground bypass
  3. // @description Watch theYNC Underground videos without needing an account
  4. // @namespace Violentmonkey Scripts
  5. // @match *://*.theync.com/*
  6. // @match *://theync.com/*
  7. // @match *://*.theync.net/*
  8. // @match *://theync.net/*
  9. // @match *://*.theync.org/*
  10. // @match *://theync.org/*
  11. // @match *://archive.ph/*
  12. // @match *://archive.today/*
  13. // @include /https?:\/\/web\.archive\.org\/web\/\d+?\/https?:\/\/theync\.(?:com|org|net)/
  14. // @require https://update.greasyfork.org/scripts/523012/1519437/WaitForKeyElement.js
  15. // @grant GM.xmlHttpRequest
  16. // @connect media.theync.com
  17. // @connect archive.org
  18. // @grant GM_addStyle
  19. // @grant GM_log
  20. // @grant GM_addElement
  21. // @version 10.3
  22. // @supportURL https://greasyfork.org/en/scripts/520352-theync-com-underground-bypass/feedback
  23. // @license MIT
  24. // @author https://greasyfork.org/en/users/1409235-paywalldespiser
  25. // ==/UserScript==
  26.  
  27. /**
  28. * Fetches available archives of a given address and retrieves their URLs.
  29. *
  30. * @param {string} address
  31. * @returns {Promise<string>}
  32. */
  33. function queryArchive(address) {
  34. try {
  35. const url = new URL('https://archive.org/wayback/available');
  36. url.searchParams.append('url', address);
  37.  
  38. return GM.xmlHttpRequest({
  39. method: 'GET',
  40. url,
  41. redirect: 'follow',
  42. responseType: 'json',
  43. })
  44. .then((result) => {
  45. if (result.status >= 300) {
  46. console.error(result.status);
  47. return Promise.reject(result);
  48. }
  49.  
  50. return result;
  51. })
  52. .then((result) => result.response)
  53. .then((result) => {
  54. if (
  55. result.archived_snapshots &&
  56. result.archived_snapshots.closest
  57. ) {
  58. return result.archived_snapshots.closest.url;
  59. }
  60. return Promise.reject();
  61. });
  62. } catch (e) {
  63. return Promise.reject();
  64. }
  65. }
  66.  
  67. /**
  68. * Checks whether a URL is valid and accessible.
  69. *
  70. * @param {string?} address
  71. * @returns {Promise<string>}
  72. */
  73. function isValidURL(address) {
  74. if (!address) {
  75. return Promise.reject(address);
  76. }
  77. try {
  78. const url = new URL(address);
  79. return GM.xmlHttpRequest({ url, method: 'HEAD' }).then((result) => {
  80. if (result.status === 404) {
  81. return Promise.reject(address);
  82. }
  83. return address;
  84. });
  85. } catch {
  86. return Promise.reject(address);
  87. }
  88. }
  89.  
  90. /**
  91. * Tries to guess the video URL of a given theYNC video via the thumbnail URL.
  92. * Only works on videos published before around May 2023.
  93. *
  94. * @param {Element} element
  95. * @returns {string?}
  96. */
  97. function getTheYNCVideoURL(element) {
  98. /**
  99. * @type {string | undefined | null}
  100. */
  101. const thumbnailURL = element.querySelector('.image > img')?.src;
  102. if (!thumbnailURL) {
  103. return null;
  104. }
  105. const match = thumbnailURL.match(
  106. /^https?:\/\/(?:media\.theync\.(?:com|org|net)|(?:www\.)?theync\.(?:com|org|net)\/media)\/thumbs\/(.+?)\.(?:flv|mpg|wmv|avi|3gp|qt|mp4|mov|m4v|f4v)/im
  107. );
  108. const group_url = match?.[1];
  109. if (!group_url) {
  110. return null;
  111. }
  112. return 'https://media.theync.com/videos/' + group_url + '.mp4';
  113. }
  114.  
  115. /**
  116. * Retrieves the video URL from a theYNC video page
  117. *
  118. * @param {Element} [element=document]
  119. * @returns {string?}
  120. */
  121. function retrieveVideoURL(element = document) {
  122. if (location.host === 'archive.ph' || location.host === 'archive.today') {
  123. const attribute = element
  124. .querySelector('[id="thisPlayer"] video[old-src]')
  125. ?.getAttribute('old-src');
  126. if (attribute) {
  127. return attribute;
  128. }
  129. }
  130. /**
  131. * @type {string | null | undefined}
  132. */
  133. const videoSrc = element.querySelector(
  134. '.stage-video > .inner-stage video[src]'
  135. )?.src;
  136. if (videoSrc) {
  137. return videoSrc;
  138. }
  139. const playerSetupScript = element.querySelector(
  140. '[id=thisPlayer] + script'
  141. )?.textContent;
  142. if (!playerSetupScript) {
  143. return null;
  144. }
  145. // TODO: Find a non-regex solution to this that doesn't involve eval#
  146. const videoURL = playerSetupScript.match(
  147. /(?<=file\:) *?"(?:https?:\/\/web.archive.org\/web\/\d+?\/)?(https?:\/\/(?:(?:www\.)?theync\.(?:com|org|net)\/media|media.theync\.(?:com|org|net))\/videos\/.+?\.(?:flv|mpg|wmv|avi|3gp|qt|mp4|mov|m4v|f4v))"/im
  148. )?.[1];
  149. if (!videoURL) {
  150. return null;
  151. }
  152. return decodeURIComponent(videoURL);
  153. }
  154.  
  155. /**
  156. * Retrieves the video URL from an archived YNC URL
  157. *
  158. * @param {string} archiveURL
  159. * @returns {Promise<string>}
  160. */
  161. function getVideoURLFromArchive(archiveURL) {
  162. return GM.xmlHttpRequest({ url: archiveURL, method: 'GET' })
  163. .then((result) => {
  164. if (result.status >= 300) {
  165. console.error(result.status);
  166. return Promise.reject(result);
  167. }
  168. return result;
  169. })
  170.  
  171. .then((result) => {
  172. // Initialize the DOM parser
  173. const parser = new DOMParser();
  174.  
  175. // Parse the text
  176. const doc = parser.parseFromString(
  177. result.responseText,
  178. 'text/html'
  179. );
  180.  
  181. // You can now even select part of that html as you would in the regular DOM
  182. // Example:
  183. // const docArticle = doc.querySelector('article').innerHTML
  184. const videoURL = retrieveVideoURL(doc);
  185. if (videoURL) {
  186. return videoURL;
  187. }
  188. return Promise.reject();
  189. });
  190. }
  191.  
  192. /**
  193. * Calls many async functions in chunks and returns the accumulated results of all chunks in one flattened array.
  194. *
  195. * @async
  196. * @template T
  197. * @param {(() => Promise<T>)[]} asyncFunctions A list of functions that make an async call and should be called in chunks. I.e. `() => this.service.loadData()`
  198. * @param {number} chunkSize how many async functions are called at once
  199. * @returns {Promise<T[]>}
  200. */
  201. async function callInChunks(asyncFunctions, chunkSize) {
  202. const numOfChunks = Math.ceil(asyncFunctions.length / chunkSize);
  203. const chunks = [...Array(numOfChunks)].map((_, i) =>
  204. asyncFunctions.slice(chunkSize * i, chunkSize * i + chunkSize)
  205. );
  206.  
  207. const result = [];
  208. for (const chunk of chunks) {
  209. const chunkResult = await Promise.allSettled(
  210. chunk.map((chunkFn) => chunkFn())
  211. );
  212. result.push(...chunkResult);
  213. }
  214. return result.flat();
  215. }
  216.  
  217. /**
  218. * Description placeholder
  219. *
  220. * @param {number} ms
  221. * @returns {Promise<void>}
  222. */
  223. function wait(ms) {
  224. return new Promise((resolve) => setTimeout(resolve, ms));
  225. }
  226.  
  227. (function () {
  228. 'use strict';
  229.  
  230. const allowedExtensions = [
  231. 'flv',
  232. 'mpg',
  233. 'wmv',
  234. 'avi',
  235. '3gp',
  236. 'qt',
  237. 'mp4',
  238. 'mov',
  239. 'm4v',
  240. 'f4v',
  241. ];
  242.  
  243. GM_addStyle(`
  244. .loader {
  245. border: 0.25em solid #f3f3f3;
  246. border-top: 0.25em solid rgba(0, 0, 0, 0);
  247. border-radius: 50%;
  248. width: 1em;
  249. height: 1em;
  250. animation: spin 2s linear infinite;
  251. }
  252. @keyframes spin {
  253. 0% {
  254. transform: rotate(0deg);
  255. }
  256. 100% {
  257. transform: rotate(360deg);
  258. }
  259. }
  260. .border-gold {
  261. display: flex !important;
  262. align-items: center;
  263. justify-content: center;
  264. gap: 1em;
  265. }
  266. `);
  267.  
  268. waitForKeyElement(
  269. '[id="content"],[id="related-videos"] .content-block'
  270. ).then((contentBlock) =>
  271. callInChunks(
  272. Array.from(
  273. contentBlock.querySelectorAll(
  274. '.inner-block > a:has(.item-info > .border-gold)'
  275. )
  276. ).map((element) => () => {
  277. const undergroundLogo = element.querySelector(
  278. '.item-info > .border-gold'
  279. );
  280.  
  281. const loadingElement = GM_addElement('div');
  282. loadingElement.classList.add('loader');
  283. undergroundLogo.appendChild(loadingElement);
  284. return isValidURL(getTheYNCVideoURL(element))
  285. .then(
  286. (url) => ({
  287. url: url,
  288. text: 'BYPASSED',
  289. color: 'green',
  290. }),
  291.  
  292. () => {
  293. /**
  294. * @type {RegExpMatchArray}
  295. */
  296. const [, secondLevelDomain, path] =
  297. element.href.match(
  298. /(^https?:\/\/(?:www\.)?theync\.)(?:com|org|net)(\/.*$)/im
  299. ) ?? [];
  300. if (!secondLevelDomain) {
  301. return Promise.reject(
  302. 'Error with the URL: ' + element.href
  303. );
  304. }
  305. return ['com', 'org', 'net']
  306. .reduce(
  307. (accumulator, currentTLD) =>
  308. accumulator.catch(() => {
  309. const archiveCooldown = wait(5000);
  310. return queryArchive(
  311. secondLevelDomain +
  312. currentTLD +
  313. path
  314. ).catch((reason) =>
  315. archiveCooldown.then(() =>
  316. Promise.reject(reason)
  317. )
  318. );
  319. }),
  320. Promise.reject()
  321. )
  322. .then(
  323. (archiveURL) =>
  324. getVideoURLFromArchive(archiveURL).then(
  325. (videoURL) => ({
  326. url: videoURL,
  327. text: 'ARCHIVED',
  328. color: 'blue',
  329. }),
  330. () => ({
  331. url: archiveURL,
  332. text: 'MAYBE ARCHIVED',
  333. color: 'aqua',
  334. })
  335. ),
  336. () => ({
  337. url:
  338. 'https://archive.ph/' +
  339. encodeURIComponent(element.href),
  340. text: 'Try archive.today',
  341. color: 'red',
  342. })
  343. );
  344. }
  345. )
  346. .then(({ url, text, color }) => {
  347. undergroundLogo.textContent = text;
  348. undergroundLogo.style.backgroundColor = color;
  349. element.href = url;
  350. })
  351. .finally(() => loadingElement.remove());
  352. }),
  353. 32
  354. )
  355. );
  356. waitForKeyElement('[id="stage"]:has([id="thisPlayer"])').then((stage) => {
  357. const videoURL = retrieveVideoURL();
  358. if (videoURL) {
  359. stage.innerHTML = '';
  360. stage.style.textAlign = 'center';
  361.  
  362. const video = GM_addElement(stage, 'video', {
  363. controls: 'controls',
  364. });
  365. video.style.width = 'auto';
  366. video.style.height = '100%';
  367. const source = GM_addElement(video, 'source');
  368. source.src = videoURL;
  369. source.type = 'video/mp4';
  370. }
  371. });
  372. })();