Nyaa.si - Load More Thumbnail

Load image from cover/screenshot links.

2023-06-02 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

  1. // ==UserScript==
  2. // @name Nyaa.si - Load More Thumbnail
  3. // @name:zh-CN Nyaa.si - 自动加载更多预览图
  4. // @namespace none
  5. // @description Load image from cover/screenshot links.
  6. // @description:zh-CN 从封面/截图链接加载图片并显示。
  7. // @version 0.7
  8. // @license MIT
  9. // @author York Wang
  10. // @match https://sukebei.nyaa.si/*
  11. // @match https://pics.dmm.co.jp/*
  12. // @match https://imgrock.pw/*
  13. // @match https://picrok.com/*
  14. // @match https://picbaron.com/*
  15. // @match https://imgbaron.com/*
  16. // @match https://kvador.com/*
  17. // @match https://kropic.com/*
  18. // @match https://imgsto.com/*
  19. // @match https://imgsen.com/*
  20. // @match https://imgstar.eu/*
  21. // @match https://picdollar.com/*
  22. // @match https://pics4you.net/*
  23. // @match https://silverpic.com/*
  24. // @match https://fotokiz.com/*
  25. // @match https://premalo.com/*
  26. // @match https://piczhq.com/*
  27. // @match https://trypicz.com/*
  28. // @match http://imglord.com/*
  29. // @match https://croea.com/*
  30. // @match https://imgtaxi.com/*
  31. // @match https://imgadult.com/*
  32. // @match https://imgdrive.net/*
  33. // @match https://xxxwebdlxxx.org/*
  34. // @match https://uvonahaze.xyz/*
  35. // @match https://trans.firm.in/*
  36. // @match https://imgdawgknuttz.com/*
  37. // @match https://imagetwist.netlify.app/*
  38. // @match https://imagetwist.com/*
  39. // @match https://imagexport.com/*
  40. // @match https://hentai4free.net/*
  41. // @match https://pixhost.to/*
  42. // @match https://imgair.net/*
  43. // @match http://imgair.net/*
  44. // @match http://imgfrost.net/*
  45. // @match http://imgblaze.net/*
  46. // @run-at document-end
  47. // @grant unsafeWindow
  48. // @grant GM_xmlhttpRequest
  49. // ==/UserScript==
  50.  
  51. (function() {
  52. 'use strict';
  53.  
  54. function Handler(pattern, process, processNyaa) {
  55. this.pattern = pattern
  56. this.process = process
  57. this.processNyaa = processNyaa
  58. }
  59. Handler.prototype.canHandle = function(url) {
  60. return this.pattern.test(url)
  61. }
  62. Handler.prototype.handle = function() {
  63. this.process(url => {
  64. document.location.href = url
  65. unsafeWindow.top.postMessage({"LMT": url}, '*')
  66. })
  67. }
  68. const handlers = []
  69. const addHandler = (pattern, process, processNyaa) => handlers.push(new Handler(pattern, process, processNyaa))
  70.  
  71. addHandler(/^https?:\/\/pics\.dmm\.co\.jp(\/[\w]+)+\.jpg.*/, callback => {
  72. callback(document.location.href.match(/^https?:\/\/pics\.dmm\.co\.jp(\/[\w]+)+\.jpg/)[0])
  73. })
  74. addHandler(/^https?:\/\/(imgrock\.pw)(\/[\w\-]+)+(\.[\w\-]+)+/, callback => {
  75. // pause on CAPTCHA
  76. const iframe = document.querySelector('iframe')
  77. if(iframe && iframe.src.indexOf('captcha') > -1) return
  78.  
  79. const img = document.querySelector('.picview')
  80. if(img) {
  81. callback(img.src)
  82. } else {
  83. const btns = document.querySelectorAll('input[name=fnext]')
  84. for(let i=0;i<btns.length;i++) {if(!btns[i].style.display) btns[i].click()}
  85. const forms = document.querySelectorAll('form')
  86. for(let i=0;i<forms.length;i++) {if(forms[i].hito) {forms[i].submit()}}
  87. }
  88. })
  89. addHandler(/^https?:\/\/(picrok\.com)(\/[\w\-]+)+\.php/, callback => {
  90. // pause on CAPTCHA
  91. const iframe = document.querySelector('iframe')
  92. if(iframe && iframe.src.indexOf('captcha') > -1) return
  93.  
  94. const img = document.querySelector('.picview')
  95. if(img) {
  96. callback(img.src)
  97. } else {
  98. unsafeWindow.setTimeout(() => {
  99. const forms = document.querySelectorAll('form')
  100. const btns = document.querySelectorAll('form>button')
  101. // for(let i=0;i<btns.length;i++) {if(btns[i].style.display) forms[i-1].submit()}
  102. }, 5000)
  103. }
  104. })
  105. addHandler(/^https?:\/\/(picbaron\.com|imgbaron\.com|kvador\.com|kropic\.com|imgsto\.com|imgsen\.com|imgstar\.eu|picdollar\.com|pics4you\.net|silverpic\.com|fotokiz\.com|premalo\.com|piczhq\.com|trypicz\.com|imglord\.com)(\/.+)+(\.[\w\-]+)+/, callback => {
  106. const img = document.querySelector('.pic')
  107. if(img) {
  108. callback(img.src)
  109. } else {
  110. const form = document.querySelector('form')
  111. form && form.submit()
  112. }
  113. })
  114. addHandler(/^https?:\/\/(croea\.com)(\/\w+)+/, callback => {
  115. const img = document.querySelector('.pic')
  116. if(img) {
  117. callback(img.src)
  118. } else {
  119. const form = document.querySelector('form')
  120. form && form.submit()
  121. }
  122. }, url => {
  123. GM_xmlhttpRequest({
  124. method: 'GET',
  125. url: url,
  126. onload: res => {
  127. const src = res.responseText.match(/src="(.*)" class="pic img img-responsive"/)
  128. if(src.length > 1) {
  129. GM_xmlhttpRequest({
  130. method: 'GET',
  131. responseType: "blob",
  132. url: src[1],
  133. onload: res => {
  134. const reader = new FileReader()
  135. reader.onload = () => {
  136. window.postMessage({"LMT": reader.result}, '*')
  137. }
  138. reader.readAsDataURL(res.response)
  139. }
  140. })
  141. }
  142. }
  143. })
  144. })
  145. addHandler(/^https?:\/\/(imgtaxi\.com|imgadult\.com|imgdrive\.net)(\/\w+)+/, callback => {
  146. unsafeWindow.ctipops = []
  147. unsafeWindow.adbctipops = []
  148. const img = document.querySelector('img.centred') || document.querySelector('img.centred_resized')
  149. if(img) {
  150. callback(img.src)
  151. } else {
  152. unsafeWindow.setTimeout(() => {
  153. const btn = document.querySelector('.overlay_ad_link')
  154. if(btn) {
  155. btn.focus()
  156. btn.click()
  157. }
  158. }, 1000)
  159. }
  160. }, url => {
  161. GM_xmlhttpRequest({
  162. method: 'GET',
  163. url: url,
  164. onload: res => {
  165. const src = res.responseText.match(/og:image:secure_url" content="(.*)"/)
  166. if(src.length > 1) window.postMessage({"LMT": src[1].replace('small','big')}, '*')
  167. }
  168. })
  169. })
  170. addHandler(/^https?:\/\/(xxxwebdlxxx\.org)(\/\w+)+/, callback => {
  171. unsafeWindow.ctipops = []
  172. unsafeWindow.adbctipops = []
  173. const img = document.querySelector('img.centred') || document.querySelector('img.centred_resized')
  174. if(img) {
  175. callback(img.src)
  176. } else {
  177. unsafeWindow.setTimeout(() => {
  178. const btn = document.querySelector('.overlay_ad_link')
  179. if(btn) {
  180. btn.focus()
  181. btn.click()
  182. }
  183. }, 1000)
  184. }
  185. })
  186. addHandler(/^https?:\/\/(uvonahaze\.xyz|trans\.firm\.in||imgdawgknuttz\.com)(\/\w+)+/, callback => {
  187. const img = document.querySelector('img.centred') || document.querySelector('img.centred_resized')
  188. if(img) {
  189. callback(img.src)
  190. } else {
  191. const btn = document.querySelector('input[name=imgContinue]')
  192. btn && btn.click()
  193. }
  194. })
  195. addHandler(/^https?:\/\/(imagetwist\.netlify\.app)(\/\w+)+/, callback => {
  196. if(unsafeWindow.targetURL) document.location.href = unsafeWindow.targetURL
  197. })
  198. addHandler(/^https?:\/\/(imagetwist\.com|imagexport\.com)(\/\w+)+/, callback => {
  199. const img = document.querySelector('.img-responsive')
  200. if(img) {
  201. callback(img.src)
  202. }
  203. })
  204. addHandler(/^https?:\/\/hentai4free\.net(\/\w+)+/, callback => {
  205. unsafeWindow.wuLu && unsafeWindow.wuLu()
  206. const img = document.querySelector('#image-viewer-container>img')
  207. if(img) {
  208. callback(img.src)
  209. }
  210. })
  211. addHandler(/^https?:\/\/pixhost\.to(\/\w+)+/, callback => {
  212. const img = document.querySelector('img.image-img')
  213. if(img) {
  214. callback(img.src)
  215. } else {
  216. const btn = document.querySelector('a.continue')
  217. btn && btn.click()
  218. }
  219. })
  220. addHandler(/^https?:\/\/(imgair\.net|imgfrost\.net|imgblaze\.net)(\/\w+)+/, callback => {
  221. unsafeWindow.wuLu && unsafeWindow.wuLu()
  222. const img = document.querySelector('#newImgE')
  223. if(img) {
  224. callback(img.src)
  225. }
  226. }, url => {
  227. GM_xmlhttpRequest({
  228. method: 'GET',
  229. url: url.replace(/^https?:\/\/(imgfrost\.net|imgblaze\.net)/, 'https://imgair.net'),
  230. onload: res => {
  231. const src = res.responseText.match(/document\.getElementById\("newImgE"\)\.src = "(.*)"/)
  232. if(src.length > 1) window.postMessage({"LMT": src[1]}, '*')
  233. }
  234. })
  235. })
  236.  
  237. const href = document.location.href
  238. if(/^https?:\/\/(sukebei\.nyaa\.si).+/g.test(href)) {
  239. if(document.title === '502 Bad Gateway') {
  240. document.location.href = document.location.href
  241. return
  242. }
  243. if(/^https?:\/\/(sukebei\.nyaa\.si\/view\/).+/g.test(href)) {
  244. const desc = document.querySelector('#torrent-description')
  245. const links = desc.querySelectorAll('a')
  246. if(!desc || !links) return
  247.  
  248. const list = []
  249. for(let i in links) {
  250. if(!links[i].href) continue
  251. handlers.forEach(h=>{h.canHandle(links[i].href) && list.push({href:links[i].href,handler:h})})
  252. }
  253.  
  254. let LMT_Wrap, LMT_Frame, LMT_Loading
  255. function createWrap() {
  256. desc.parentNode.insertAdjacentHTML('afterend', '<div class="panel panel-default"><div class="panel-body" id="LMT_Wrap"></div></div>')
  257. LMT_Wrap = document.querySelector('#LMT_Wrap')
  258.  
  259. LMT_Loading = document.createElement('div')
  260. LMT_Loading.textContent = 'Loading Images...'
  261. LMT_Wrap.appendChild(LMT_Loading)
  262.  
  263. LMT_Frame = document.createElement('iframe')
  264. LMT_Frame.id = 'LMT_Frame'
  265. LMT_Frame.sandbox = 'allow-forms allow-scripts allow-same-origin'
  266. LMT_Frame.style.display = 'none'
  267. LMT_Wrap.appendChild(LMT_Frame)
  268. }
  269.  
  270. function process() {
  271. if(list.length) {
  272. if(!LMT_Frame) createWrap()
  273. let url = list.shift()
  274. if(url.handler.processNyaa) {
  275. url.handler.processNyaa(url.href)
  276. } else {
  277. LMT_Frame.src = url.href
  278. }
  279. } else {
  280. if(LMT_Frame) {
  281. LMT_Wrap.removeChild(LMT_Frame)
  282. LMT_Wrap.removeChild(LMT_Loading)
  283. }
  284. }
  285. }
  286.  
  287. unsafeWindow.addEventListener('message', function (e) {
  288. if(e.data.LMT) {
  289. LMT_Frame.src = ''
  290. const img = document.createElement('img')
  291. img.src = e.data.LMT
  292. img.style['max-width'] = '100%'
  293. LMT_Wrap.appendChild(img)
  294. process()
  295. }
  296. })
  297.  
  298. process()
  299. }
  300. } else {
  301. handlers.forEach(h=>{h.canHandle(href) && h.handle()})
  302. }
  303. })();