theYNC.com Underground bypass

Watch theYNC Underground videos without needing an account

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

  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 9.4
  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. for (const [, group_url] of thumbnailURL.matchAll(
  104. /^https?:\/\/(?:media\.theync\.(?:com|org|net)|(www\.)?theync\.(?:com|org|net)\/media)\/thumbs\/(.+?)\.(?:flv|mpg|wmv|avi|3gp|qt|mp4|mov|m4v|f4v)/gim
  105. )) {
  106. if (group_url) {
  107. return 'https://media.theync.com/videos/' + group_url + '.mp4';
  108. }
  109. }
  110. }
  111.  
  112. return null;
  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. // TODO: Find a non-regex solution to this that doesn't involve eval
  144. for (const [, videoURL] of playerSetupScript.matchAll(
  145. /(?<=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))"/gim
  146. )) {
  147. if (videoURL) {
  148. return decodeURIComponent(videoURL);
  149. }
  150. }
  151. }
  152. return null;
  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.all(
  210. chunk.map((chunkFn) => chunkFn())
  211. );
  212. result.push(...chunkResult);
  213. }
  214. return result.flat();
  215. }
  216. /**
  217. * Description placeholder
  218. *
  219. * @param {number} ms
  220. * @returns {Promise<void>}
  221. */
  222. const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
  223. (function () {
  224. 'use strict';
  225.  
  226. const allowedExtensions = [
  227. 'flv',
  228. 'mpg',
  229. 'wmv',
  230. 'avi',
  231. '3gp',
  232. 'qt',
  233. 'mp4',
  234. 'mov',
  235. 'm4v',
  236. 'f4v',
  237. ];
  238.  
  239. GM_addStyle(`
  240. .loader {
  241. border: 0.25em solid #f3f3f3;
  242. border-top: 0.25em solid rgba(0, 0, 0, 0);
  243. border-radius: 50%;
  244. width: 1em;
  245. height: 1em;
  246. animation: spin 2s linear infinite;
  247. }
  248. @keyframes spin {
  249. 0% {
  250. transform: rotate(0deg);
  251. }
  252. 100% {
  253. transform: rotate(360deg);
  254. }
  255. }
  256. .border-gold {
  257. display: flex !important;
  258. align-items: center;
  259. justify-content: center;
  260. gap: 1em;
  261. }
  262. `);
  263.  
  264. waitForKeyElement(
  265. '[id="content"],[id="related-videos"] .content-block'
  266. ).then((contentBlock) =>
  267. callInChunks(
  268. Array.from(
  269. contentBlock.querySelectorAll(
  270. '.inner-block > a:has(.item-info > .border-gold)'
  271. )
  272. ).map((element) => () => {
  273. const undergroundLogo = element.querySelector(
  274. '.item-info > .border-gold'
  275. );
  276.  
  277. const loadingElement = GM_addElement('div');
  278. loadingElement.classList.add('loader');
  279. undergroundLogo.appendChild(loadingElement);
  280. return isValidURL(getTheYNCVideoURL(element))
  281. .then(
  282. (url) => ({
  283. url: url,
  284. text: 'BYPASSED',
  285. color: 'green',
  286. }),
  287.  
  288. () => {
  289. /**
  290. * @type {RegExpMatchArray | null}
  291. */
  292. const match = element.href.match(
  293. /(^https?:\/\/(?:www\.)?theync\.)(?:com|org|net)(\/.*$)/im
  294. );
  295. if (!match?.[1]) {
  296. return Promise.reject(
  297. 'Error with the URL: ' + element.href
  298. );
  299. }
  300. const [, secondLevelDomain, path] = match;
  301.  
  302. return ['com', 'org', 'net']
  303. .reduce(
  304. /**
  305. * @param {Promise<string>} accumulator
  306. * @param {string} currentTLD
  307. * @returns {Promise<string>}
  308. */
  309. (accumulator, currentTLD) =>
  310. accumulator.catch(() =>
  311. wait(1400).then(() =>
  312. queryArchive(
  313. secondLevelDomain +
  314. currentTLD +
  315. path
  316. )
  317. )
  318. ),
  319. Promise.reject()
  320. )
  321. .then((archiveURL) =>
  322. getVideoURLFromArchive(archiveURL).then(
  323. (videoURL) => ({
  324. url: videoURL,
  325. text: 'ARCHIVED',
  326. color: 'blue',
  327. }),
  328. () => ({
  329. url: archiveURL,
  330. text: 'MAYBE ARCHIVED',
  331. color: 'aqua',
  332. })
  333. )
  334. );
  335. }
  336. )
  337. .catch(() => ({
  338. url:
  339. 'https://archive.ph/' +
  340. encodeURIComponent(element.href),
  341. text: 'Try archive.today',
  342. color: 'red',
  343. }))
  344. .then(({ url, text, color }) => {
  345. undergroundLogo.textContent = text;
  346. undergroundLogo.style.backgroundColor = color;
  347. element.href = url;
  348. })
  349. .finally(() => loadingElement.remove());
  350. }),
  351. 24
  352. )
  353. );
  354. waitForKeyElement('[id="stage"]:has([id="thisPlayer"])').then((stage) => {
  355. const videoURL = retrieveVideoURL();
  356. if (videoURL) {
  357. stage.innerHTML = '';
  358. stage.style.textAlign = 'center';
  359.  
  360. const video = GM_addElement(stage, 'video', {
  361. controls: 'controls',
  362. });
  363. video.style.width = 'auto';
  364. video.style.height = '100%';
  365. const source = GM_addElement(video, 'source');
  366. source.src = videoURL;
  367. source.type = 'video/mp4';
  368. }
  369. });
  370. })();