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.1
  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. (function () {
  193. 'use strict';
  194.  
  195. const allowedExtensions = [
  196. 'flv',
  197. 'mpg',
  198. 'wmv',
  199. 'avi',
  200. '3gp',
  201. 'qt',
  202. 'mp4',
  203. 'mov',
  204. 'm4v',
  205. 'f4v',
  206. ];
  207.  
  208. GM_addStyle(`
  209. .loader {
  210. border: 0.25em solid #f3f3f3;
  211. border-top: 0.25em solid rgba(0, 0, 0, 0);
  212. border-radius: 50%;
  213. width: 1em;
  214. height: 1em;
  215. animation: spin 2s linear infinite;
  216. }
  217. @keyframes spin {
  218. 0% {
  219. transform: rotate(0deg);
  220. }
  221. 100% {
  222. transform: rotate(360deg);
  223. }
  224. }
  225. .border-gold {
  226. display: flex !important;
  227. align-items: center;
  228. justify-content: center;
  229. gap: 1em;
  230. }
  231. `);
  232.  
  233. waitForKeyElement(
  234. '[id="content"],[id="related-videos"] .content-block'
  235. ).then(async (contentBlock) => {
  236. for (const element of contentBlock.querySelectorAll(
  237. '.upgrade-profile > .upgrade-info-block > .image-block'
  238. )) {
  239. isValidURL(getTheYNCVideoURL(element)).then(
  240. (url) => (location.href = url)
  241. );
  242. }
  243. for (/** @type {HTMLLinkElement} */ const element of contentBlock.querySelectorAll(
  244. '.inner-block > a'
  245. )) {
  246. const undergroundLogo = element.querySelector(
  247. '.item-info > .border-gold'
  248. );
  249. if (!undergroundLogo) {
  250. continue;
  251. }
  252. const loadingElement = GM_addElement('div');
  253. loadingElement.classList.add('loader');
  254. undergroundLogo.appendChild(loadingElement);
  255. await isValidURL(getTheYNCVideoURL(element))
  256. .then(
  257. (url) => ({
  258. url: url,
  259. text: 'BYPASSED',
  260. color: 'green',
  261. }),
  262.  
  263. () => {
  264. /**
  265. * @type {RegExpMatchArray | null}
  266. */
  267. const match = element.href.match(
  268. /(^https?:\/\/(?:www\.)?theync\.)(?:com|org|net)(\/.*$)/im
  269. );
  270. if (!match?.[1]) {
  271. return Promise.reject(
  272. 'Error with the URL: ' + element.href
  273. );
  274. }
  275. const [, secondLevelDomain, path] = match;
  276.  
  277. return ['com', 'org', 'net']
  278. .reduce(
  279. /**
  280. * @param {Promise<string>} accumulator
  281. * @param {string} currentTLD
  282. * @returns {Promise<string>}
  283. */
  284. (accumulator, currentTLD) =>
  285. accumulator.catch(() =>
  286. queryArchive(
  287. secondLevelDomain +
  288. currentTLD +
  289. path
  290. )
  291. ),
  292. Promise.reject()
  293. )
  294. .then((archiveURL) =>
  295. getVideoURLFromArchive(archiveURL).then(
  296. (videoURL) => ({
  297. url: videoURL,
  298. text: 'ARCHIVED',
  299. color: 'blue',
  300. }),
  301. () => ({
  302. url: archiveURL,
  303. text: 'MAYBE ARCHIVED',
  304. color: 'aqua',
  305. })
  306. )
  307. );
  308. }
  309. )
  310. .catch(() => ({
  311. url:
  312. 'https://archive.ph/' +
  313. encodeURIComponent(element.href),
  314. text: 'Try archive.today',
  315. color: 'red',
  316. }))
  317. .then(({ url, text, color }) => {
  318. undergroundLogo.textContent = text;
  319. undergroundLogo.style.backgroundColor = color;
  320. element.href = url;
  321. })
  322. .finally(() => loadingElement.remove());
  323. }
  324. });
  325. waitForKeyElement('[id="stage"]:has([id="thisPlayer"])').then((stage) => {
  326. const videoURL = retrieveVideoURL();
  327. if (videoURL) {
  328. stage.innerHTML = '';
  329. stage.style.textAlign = 'center';
  330.  
  331. const video = GM_addElement(stage, 'video', {
  332. controls: 'controls',
  333. });
  334. video.style.width = 'auto';
  335. video.style.height = '100%';
  336. const source = GM_addElement(video, 'source');
  337. source.src = videoURL;
  338. source.type = 'video/mp4';
  339. }
  340. });
  341. })();