IMDB Scout

Add links from IMDB movie pages to torrent sites -- easy downloading from IMDB

当前为 2014-08-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name IMDB Scout
  3. // @namespace https://greasyfork.org/users/1057-kannibalox
  4. // @description Add links from IMDB movie pages to torrent sites -- easy downloading from IMDB
  5. //
  6. // Preference window for userscripts, hosted by greasyfork:
  7. // @require https://greasyfork.org/libraries/GM_config/20131122/GM_config.js
  8. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
  9. //
  10. // @version 2.22.1
  11. // @include http://*.imdb.com/title/tt*
  12. // @include http://*.imdb.de/title/tt*
  13. // @include http://*.imdb.es/title/tt*
  14. // @include http://*.imdb.fr/title/tt*
  15. // @include http://*.imdb.it/title/tt*
  16. // @include http://*.imdb.pt/title/tt*
  17. // @include http://*.imdb.com/search/title*
  18. // @include http://*.imdb.de/search/title*
  19. // @include http://*.imdb.es/search/title*
  20. // @include http://*.imdb.fr/search/title*
  21. // @include http://*.imdb.it/search/title*
  22. // @include http://*.imdb.pt/search/title*
  23. //
  24. // @grant GM_log
  25. // @grant GM_getValue
  26. // @grant GM_setValue
  27. // @grant GM_addStyle
  28. // @grant GM_openInTab
  29. // @grant GM_xmlhttpRequest
  30. // @grant GM_registerMenuCommand
  31. //
  32. // ==/UserScript==
  33. /*---------------------Version History--------------------
  34. 1.00 - Initial public release, everything works on barebones greasemonkey
  35.  
  36. 1.50 - Added the ability to select which sites to load from the GM script commands
  37. - Moved the required method to userscripts
  38. - Removed FH, NZB, Avax
  39. 1.60 - Added style elements and shading to display on imdb
  40.  
  41. 1.62 - Fixed bug:SCC-ARC not removing when unchecked
  42. - Alphabetized list
  43.  
  44. 1.70 - Cleaned up code
  45. - Added option to not run script on page load
  46. 1.71 - Deprecated action-box field
  47.  
  48. 1.80 - Added icons that link to OpenSubs, Criticker, RT, YT
  49.  
  50. 1.81 - Added support for tv, only displays on shows listed as 'tv series'
  51. - Added support for icheckmovies at top bar.
  52. 1.82 - Fixed title parsing for tv shows.
  53.  
  54. 1.83 - Fixed dhive not working properly
  55.  
  56. 1.90 - Set height of preference window to 450px, added scroll bar
  57.  
  58. 1.91 - Added another 11 torrent sites
  59.  
  60. 2.00 - Added auto updater
  61.  
  62. 2.01 - Added TC, FreshOn, TVT, STF, CC
  63. - Cleaned up code (tabbing)
  64. - Removed THR
  65. - Added TV-Rage to top bar
  66. 2.02 - Added PS, THC, HH, HDStar
  67. - Fixed CC false positive
  68. 2.03 - TehC now uses tt
  69. - Added Raymoz mod for AT
  70. 2.04 - Added HDbits
  71. - Added TL
  72.  
  73. 2.10 - Added genre page search functionality
  74.  
  75. 2.11 - Fixed ICM because Nuked was whining
  76.  
  77. 2.12 - Removed tvrage
  78. - Fixed iCM (added tt)
  79. - Added HDVNbits
  80. - Changed RevTT to .me
  81. - Added HDT
  82. - removed autoupdate
  83.  
  84. 2.13 - removed xvidme
  85. - reinstated autoupdate
  86. - removed google chrome code
  87. - fixed hdvn and hdt issues
  88.  
  89. 2.14 - Added @grant entries for API access
  90. - Fixed tt parser to work on imdb pages with referral info in url
  91.  
  92. 2.2 - Switch preferences window to use GM_config
  93. - Consolidate icon & site lists
  94. - Added IPT, KASS, sHD, and HDW
  95. - Fix "Open All" link
  96. - Add option for strikethroughs on search page
  97. - Removed arrays from search URLs
  98. - Spring cleaning
  99. 2.21 - Added SSL to TVT, HDME, TC, AHD, IPT, SCC
  100. - Added SSL option for CG
  101. - Added GFT, GFT-Gems, GFT-TV
  102. - Fixed SCC, SCC-ARC search URL
  103. - Removed TheBox, TheDVDClub
  104. - Added more comments, cleaned up some more stuff
  105. 2.22 - Fixed TehC, BTN, BTN-Req, THC
  106. - Added a bunch of TV sites, courtesy of seedless
  107. - Added "both" option for sites, and made changes
  108. to allow coexistences of movie and TV sites with
  109. the same name
  110. - Code re-organization, documentation
  111. - Re-added code to allow an array for searchUrl
  112. 2.22.1 - Minor fixes
  113. --------------------------------------------------------*/
  114.  
  115. //------------------------------------------------------
  116. // A list of all the sites, and the data necessary to
  117. // check IMDB against them.
  118. // Each site is a python dictionary with the following attributes:
  119. // - name: The site name, abbreviated
  120. // - searchUrl: The url to perform the search, see below for how
  121. // to tailor the string to a site
  122. // - matchRegex: The string which appears if
  123. // the searchUrl DOESN'T return a result
  124. // - TV (optional): If true, it means that this site will only
  125. // show up on TV pages. By default, sites only show up on movie pages
  126. // - both (optional): Means that the site will show up
  127. // on both movie and TV pages
  128. // To create a search URL, there are three parameters
  129. // you can use inside the URL:
  130. // - %tt%: The IMDB id with the tt prefix
  131. // - %nott%: The IMDB id without the tt prefix
  132. // - $search_string%: The movie title
  133. // See below for examples
  134. //------------------------------------------------------
  135.  
  136. var sites = [
  137. { 'name': 'AHD',
  138. 'searchUrl': 'https://awesome-hd.net/torrents.php?searchstr=%search_string%',
  139. 'matchRegex': /<h2>Error 404<\/h2>/,
  140. 'TV': true},
  141. { 'name': 'BTN',
  142. 'searchUrl': 'https://broadcasthe.net/torrents.php?imdb=%tt%',
  143. 'matchRegex': /Whatchoo talkin' bout willis?.<\/h2>|Lost your password\?/,
  144. 'TV': true},
  145. { 'name': 'BTN-Req',
  146. 'searchUrl': 'https://broadcasthe.net/requests.php?search=%search_string%',
  147. 'matchRegex': /Nothing found|Lost your password\?/,
  148. 'TV': true},
  149. { 'name': 'TVV',
  150. 'searchUrl': 'http://tv-vault.me/torrents.php?searchstr=%search_string%',
  151. 'matchRegex': /Nothing found<\/h2>/,
  152. 'TV': true},
  153. { 'name': 'BMTV',
  154. 'searchUrl': 'https://www.bitmetv.org/browse.php?search=%search_string%',
  155. 'matchRegex': /Nothing found!<\/h2>/,
  156. 'TV': true},
  157. { 'name': 'Fresh',
  158. 'searchUrl': 'http://freshon.tv/browse.php?search=%search_string%',
  159. 'matchRegex': /Nothing found!<\/h2>/,
  160. 'TV': true},
  161. { 'name': 'TvT',
  162. 'searchUrl': 'https://www.tvtorrents.com/loggedin/search.do?search=%search_string%',
  163. 'matchRegex': /Nothing found!<\/h2>/,
  164. 'TV': true},
  165. { 'name': 'GFT',
  166. 'searchUrl': 'https://www.thegft.org/browse.php?view=0&search=%search_string%',
  167. 'matchRegex': /Nothing found!<\/h2>/,
  168. 'TV': true},
  169. { 'name': 'HDME',
  170. 'searchUrl': 'https://hdme.eu/browse.php?search=%search_string%&blah=0&cat=0&incldead=1',
  171. 'matchRegex': /Try again with a refined search string.|<h1>You need cookies enabled to log in.<\/h1>/,
  172. 'TV': true},
  173. { 'name': 'IPT',
  174. 'searchUrl': 'https://www.iptorrents.com/torrents/?q=%search_string%',
  175. 'matchRegex': /<h2>Nothing found!<\/h2>|( 0 torrents )/,
  176. 'TV': true},
  177. { 'name': 'KASS',
  178. 'searchUrl': 'https://kickass.to/usearch/%search_string%',
  179. 'matchRegex': /<h2>Nothing found!<\/h2>/,
  180. 'TV': true},
  181. { 'name': 'RevTT',
  182. 'searchUrl': 'https://www.revolutiontt.me/browse.php?search=%search_string%&cat=0&incldead=1&titleonly=1',
  183. 'matchRegex': /<h2>Nothing found!<\/h2>/,
  184. 'TV': true},
  185. { 'name': 'SCC',
  186. 'searchUrl': 'https://sceneaccess.eu/browse?search=%search_string%&method=2',
  187. 'matchRegex': /Try again with a refined search string.|<h1>Note: Three (3) failed login attempts will result in a temporary security lockout.<\/h1>/,
  188. 'TV': true},
  189. { 'name': 'SCC-ARC',
  190. 'searchUrl': 'https://sceneaccess.eu/archive?search=%search_string%&method=1',
  191. 'matchRegex': /Try again with a refined search string.|<h1>Note: Three (3) failed login attempts will result in a temporary security lockout.<\/h1>/,
  192. 'TV': true},
  193. { 'name': 'SCC-NS',
  194. 'searchUrl': 'https://sceneaccess.eu/nonscene?search=%search_string%&method=2',
  195. 'matchRegex': /Try again with a refined search string.|<h1>Note: Three (3) failed login attempts will result in a temporary security lockout.<\/h1>/,
  196. 'TV': true},
  197. { 'name': 'TL',
  198. 'searchUrl': 'http://www.torrentleech.org/torrents/browse/index/query/%search_string%&/categories/2,26,27,32',
  199. 'matchRegex': /Signup With Invite|Please refine your search./,
  200. 'TV': true},
  201. { 'name': 'Goem',
  202. 'searchUrl': 'http://goem.org/browse.php?s_type=2&cat=0&search=%tt%',
  203. 'matchRegex': /Try again with a refined searchstring|<h1>Note: You need cookies enabled to log in.<\/h1>/,
  204. 'both': true},
  205. { 'name': 'TPB',
  206. 'searchUrl': 'https://thepiratebay.org/search/%tt%',
  207. 'matchRegex': /No hits. Try adding an asterisk in you search phrase.<\/h2>/,
  208. 'both': true},
  209. { 'name': 'HDW',
  210. 'searchUrl': 'http://hdwing.com/browse.php?search=%search_string%',
  211. 'matchRegex': /<h2>没找到任何内容!|对不起<\/h2>/,
  212. 'both': true},
  213. { 'name': 'AT',
  214. 'searchUrl': 'http://www.asiatorrents.com/index.php?page=torrents&options=3&search=%tt%',
  215. 'matchRegex': /torrent_history/},
  216. { 'name': 'HDVN',
  217. 'searchUrl': 'http://hdvnbits.org/torrents.php?search=%tt%&search_area=4&search_mode=0',
  218. 'matchRegex': /Nothing found! Try again with a refined search string/},
  219. { 'name': 'HDT',
  220. 'searchUrl': 'http://hd-torrents.org/torrents.php?active=0&options=2&search=%tt%',
  221. 'matchRegex': /No torrents here.../},
  222. { 'name': 'TL',
  223. 'searchUrl': 'http://www.torrentleech.org/torrents/browse/index/query/%search_string%&/categories/1,8,9,10,11,12,13,14,15,29',
  224. 'matchRegex': /Signup With Invite|Please refine your search./},
  225. { 'name': 'HDb',
  226. 'searchUrl': 'http://hdbits.org/browse2.php#film/dir=null&searchtype=film&actorfilm=film&search=%tt%',
  227. 'matchRegex': /<p>Note: You need cookies enabled to log in.<\/p>/},
  228. { 'name': 'CG',
  229. 'searchUrl': 'http://cinemageddon.net/browse.php?search=%tt%',
  230. 'matchRegex': /<h2>Nothing found!<\/h2>|<h1>Not logged in!<\/h1>/},
  231. { 'name': 'CG-SSL',
  232. 'searchUrl': 'https://cinemageddon.net/browse.php?search=%tt%',
  233. 'matchRegex': /<h2>Nothing found!<\/h2>|<h1>Not logged in!<\/h1>/},
  234. { 'name': 'Demo',
  235. 'searchUrl': 'http://www.demonoid.me/files/?query=%tt%',
  236. 'matchRegex': /<b>No torrents found<\/b>|We are currently performing the daily site maintenance.<br>/},
  237. { 'name': 'Kara',
  238. 'searchUrl': 'https://www.karagarga.net/browse.php?search_type=imdb&search=%nott%',
  239. 'matchRegex': /<h2>No torrents found<\/h2>|<h1>If you want the love<\/h1>/},
  240. { 'name': 'Tik',
  241. 'searchUrl': 'http://cinematik.net/browse.php?srchdtls=1&incldead=1&search=%tt%',
  242. 'matchRegex': /The page you tried to view can only be used when you're logged in|<h2>Nothing found!<\/h2>/},
  243. { 'name': 'SM',
  244. 'searchUrl': 'http://www.surrealmoviez.info/advanced_search.php?simdb=%tt%',
  245. 'matchRegex': /0 Movies found matching search criteria|You need to be logged in to view this page/},
  246. { 'name': 'ILC',
  247. 'searchUrl': 'http://www.iloveclassics.com/browse.php?incldead=1&searchin=2&search=%tt%',
  248. 'matchRegex': /Try again with a refined search string|<h1>Not logged in!<\/h1>/},
  249. { 'name': 'SDBits',
  250. 'searchUrl': 'http://sdbits.org/browse.php?c6=1&c3=1&c1=1&c4=1&c5=1&c2=1&m1=1&incldead=0&from=&to=&imdbgt=0&imdblt=10&uppedby=&imdb=&search=%tt%',
  251. 'matchRegex': /Nothing found!|<h1>You need cookies enabled to log in.<\/h1>/},
  252. { 'name': 'eThor',
  253. 'searchUrl': 'http://ethor.net/browse.php?stype=b&c23=1&c20=1&c42=1&c5=1&c19=1&c25=1&c6=1&c37=1&c43=1&c7=1&c9=1&advcat=0&incldead=0&includedesc=1&search=%tt%',
  254. 'matchRegex': /Try again with a refined search string.|<h1>Note: Vous devez activer vos 'cookies' pour pouvoir vous identifier.<\/h1>/},
  255. { 'name': 'x264',
  256. 'searchUrl': 'http://x264.me/browse.php?incldead=0&xtype=0&stype=3&search=%tt%',
  257. 'matchRegex': /Try again with a refined search string.|<h1>Forgot your password?<\/h1>/},
  258. { 'name': 'FSS',
  259. 'searchUrl': 'http://fss.omnilounge.co.uk/browse.php?blah=2&cat=0&incldead=1&search=%tt%',
  260. 'matchRegex': /Try again with a different search string?|<h1>You need cookies enabled to log in.<\/h1>/},
  261. { 'name': 'HDME',
  262. 'searchUrl': 'https://hdme.eu/browse.php?blah=2&cat=0&incldead=1&search=%tt%',
  263. 'matchRegex': /Try again with a refined search string.|<h1>You need cookies enabled to log in.<\/h1>/},
  264. { 'name': 'DHive',
  265. 'searchUrl': 'https://gks.gs/sphinx/?category=0&prez=&sort=normal&order=desc&q=%tt%',
  266. 'matchRegex': /Votre Recherche aucun|<h1>Mot de passe<\/h1>/},
  267. { 'name': 'CHD',
  268. 'searchUrl': 'http://chdbits.org/torrents.php?incldead=1&spstate=0&inclbookmarked=0&search_area=4&search_mode=0&search=%tt%',
  269. 'matchRegex': /Nothing found! Try again with a refined search string.|<h1>You need cookies enabled to log in or switch language.<\/h1>/},
  270. { 'name': 'PTP-Req',
  271. 'searchUrl': 'https://tls.passthepopcorn.me/requests.php?submit=true&search=%tt%',
  272. 'matchRegex': /Nothing found!|<h1>Keep me logged in.<\/h1>/},
  273. { 'name': 'ADVD',
  274. 'searchUrl': 'https://asiandvdclub.org/browse.php?descr=1&btnSubmit=Submit&search=%tt%',
  275. 'matchRegex': /Your search returned zero results|<h1>You need cookies enabled to log in.<\/h1>/},
  276. { 'name': 'iPlay',
  277. 'searchUrl': 'http://www.iplay.ro/browse.php?genre=1&status=0&search=%tt%',
  278. 'matchRegex': /Try again with a refined search string|<h1>You need cookies enabled to log in.<\/h1>/},
  279. { 'name': 'ScandBits',
  280. 'searchUrl': 'http://scanbits.org/browse.php?cat=0&incldead=0&mode=0&search=%tt%',
  281. 'matchRegex': /Try again with a refined search string|<h1>You need cookies enabled to log in.<\/h1>/},
  282. { 'name': 'TE',
  283. 'searchUrl': 'http://theempire.bz/browse.php?incldead=0&country=&nonboolean=1&search=%tt%',
  284. 'matchRegex': /Try again with a refined search string|<h1>You need cookies enabled to log in.<\/h1>/},
  285. { 'name': 'TG',
  286. 'searchUrl': 'http://thegeeks.bz/browse.php?incldead=0&country=&nonboolean=1&search=%tt%',
  287. 'matchRegex': /Try again with a refined search string|<h1>You need cookies enabled to log in.<\/h1>/},
  288. { 'name': 'LL',
  289. 'searchUrl': 'http://www.leecherslair.com/browse.php?blah=1&incldead=0&search=%tt%',
  290. 'matchRegex': /Try again with a refined search string|<h1>This site is under construction<\/h1>/},
  291. { 'name': 'MT',
  292. 'searchUrl': 'http://www.maroctorrent.net/torrents-search.php?cat=42&incldead=1&search=%tt%',
  293. 'matchRegex': /Aucun torrent|<h1>Les Cookies DOIVENT<\/h1>/},
  294. { 'name': 'FY',
  295. 'searchUrl': 'https://fuckyeahtorrents.com/browse.php?_by=2&cat=0&search=%tt%',
  296. 'matchRegex': /Try again with a refined search string|<h1>You need cookies enabled to log in.<\/h1>/},
  297. { 'name': 'SCC',
  298. 'searchUrl': 'https://sceneaccess.org/browse?method=3&search=%tt%',
  299. 'matchRegex': /Try again with a refined search string.|<h1>Note: Three (3) failed login attempts will result in a temporary security lockout.<\/h1>/},
  300. { 'name': 'SCC-ARC',
  301. 'searchUrl': 'https://sceneaccess.org/archive?=&method=3&search=%tt%',
  302. 'matchRegex': /Try again with a refined search string.|<h1>Note: Three (3) failed login attempts will result in a temporary security lockout.<\/h1>/},
  303. { 'name': 'SCC-NS',
  304. 'searchUrl': 'https://sceneaccess.eu/nonscene?=&method=3&search=%tt%',
  305. 'matchRegex': /Try again with a refined search string.|<h1>Note: Three (3) failed login attempts will result in a temporary security lockout.<\/h1>/},
  306. { 'name': 'PTP',
  307. 'searchUrl': 'https://tls.passthepopcorn.me/torrents.php?imdb=%tt%',
  308. 'matchRegex': /<h2>Your search did not match anything.<\/h2>/},
  309. { 'name': 'BitHD',
  310. 'searchUrl': 'http://www.bit-hdtv.com/torrents.php?cat=0&description_search=1&search=%tt%',
  311. 'matchRegex': /<h2>No match!<\/h2>/},
  312. { 'name': 'RevTT',
  313. 'searchUrl': 'https://www.revolutiontt.me/browse.php?search=%tt%',
  314. 'matchRegex': /<h2>Nothing found!<\/h2>/},
  315. { 'name': 'AHD',
  316. 'searchUrl': 'https://awesome-hd.net/torrents.php?id=%tt%',
  317. 'matchRegex': /<h2>Error 404<\/h2>/},
  318. { 'name': 'TehC',
  319. 'searchUrl': 'https://tehconnection.eu/torrents.php?searchstr=%tt%',
  320. 'matchRegex': /You will be banned for 6 hours after your login attempts run out.|<h2>No Search Results, try reducing your search options./},
  321. { 'name': 'CC',
  322. 'searchUrl': 'http://www.cine-clasico.com/foros/search.php?terms=any&author=&sc=1&sf=all&sr=posts&sk=t&sd=d&st=0&ch=300&t=0&submit=Search&keywords=%tt%',
  323. 'matchRegex': /You will be banned for 6 hours after your login attempts run out.|You must specify at least one word to search for. Each word must consist of at least 3 characters and must not contain more than 14 characters excluding wildcards.|Disculpe/},
  324. { 'name': 'PS',
  325. 'searchUrl': 'http://polishsource.org/browse.php?incldead=0&scene=0&pl=0&sub=&search_in=both&free=0&search=%tt%',
  326. 'matchRegex': /Nic nie znaleziono|Musisz|login/},
  327. { 'name': 'THC',
  328. 'searchUrl': ['https://horrorcharnel.kicks-ass.org/browse.php?title=3&search=%tt%', 'https://horrorcharnel.kicks-ass.org/browse.php?search=%tt%&search_what=3&status=0&codec=0&category=0&18=1'],
  329. 'matchRegex': /<h1>Not logged in!<\/h1>|Nothing found!/},
  330. { 'name': 'HH',
  331. 'searchUrl': 'http://www.horrorhaven.org/search.php?stype=articles&stext=%tt%',
  332. 'matchRegex': /0 Articles found matching search criteria/},
  333. { 'name': 'HDStar',
  334. 'searchUrl': 'http://www.hdstar.org/torrents.php?incldead=1&spstate=0&inclbookmarked=0&search_area=1&search_mode=0&search=%tt%',
  335. 'matchRegex': /Try again with a refined search string|You need cookies enabled to log in or switch language/},
  336. { 'name': 'KASS',
  337. 'searchUrl': 'https://kickass.to/usearch/imdb%3A%nott%',
  338. 'matchRegex': /<h2>Nothing found!<\/h2>/},
  339. { 'name': 'IPT',
  340. 'searchUrl': 'https://www.iptorrents.com/torrents/?q=%tt%',
  341. 'matchRegex': /<h2>Nothing found!<\/h2>|( 0 torrents )/},
  342. { 'name': 'sHD',
  343. 'searchUrl': 'https://scenehd.org/browse.php?options&unpack&incldead&search=%search_string%',
  344. 'matchRegex': /<h2>No torrents found!<\/h2>/},
  345. { 'name': 'GFT',
  346. 'searchUrl': 'https://www.thegft.org/browse.php?view=0&c2=1&c1=1&c9=1&c11=1&c48=1&c8=1&c18=1&c49=1&c7=1&c38=1&c46=1&c5=1&c13=1&c26=1&c37=1&c19=1&c47=1&c17=1&c4=1&c22=1&c25=1&c20=1&c3=1&search=%tt%&searchtype=0',
  347. 'matchRegex': /Nothing found!<\/h2>/},
  348. { 'name': 'GFT-Gems',
  349. 'searchUrl': 'https://www.thegft.org/browse.php?view=1&search=%tt%&searchtype=0',
  350. 'matchRegex': /Nothing found!<\/h2>/},
  351. ];
  352.  
  353. icon_sites = [
  354. { 'name': 'OpenSubtitles',
  355. 'icon': 'http://www.opensubtitles.org/favicon.ico',
  356. 'searchUrl': "http://www.opensubtitles.org/en/search/imdbid-%tt%"},
  357. { 'name': 'Youtube',
  358. 'icon': 'http://www.youtube.com/favicon.ico',
  359. 'searchUrl': 'http://www.youtube.com/results?search_query="%search_string%"&search=Search'},
  360. { 'name': 'Rotten Tomatoes',
  361. 'icon': "http://www.rottentomatoes.com/favicon.ico",
  362. 'searchUrl': "http://www.rottentomatoes.com/alias?type=imdbid&s=%nott%"},
  363. { 'name': 'Criticker',
  364. 'icon': 'http://www.criticker.com/favicon.ico',
  365. 'searchUrl': 'http://www.criticker.com/?st=movies&h=%search_string%&g=Go'},
  366. { 'name': 'iCheckMovies',
  367. 'icon': 'http://www.icheckmovies.com/favicon.ico',
  368. 'searchUrl': 'http://www.icheckmovies.com/search/movies/?query=%tt%'},
  369. ];
  370.  
  371. function replace_search_url_params(search_url, movie_id, movie_title) {
  372. var search_string = movie_title.replace(/ +\(.*/, '').replace(/[^a-zA-Z0-9]/g, ' ').replace(/ +/g, '+');
  373. if ($.isArray(search_url)) {
  374. search_array = [];
  375. $.each(search_url, function(index, url) {
  376. search_array[index] = replace_search_url_params(url, movie_id, movie_title);
  377. });
  378. return search_array;
  379. }
  380. return search_url.replace('%tt%', 'tt'+movie_id)
  381. .replace('%nott%', movie_id)
  382. .replace('%search_string%', search_string);
  383. }
  384.  
  385. // Adds search links to an element
  386. function add_link(elem, search_url, link_text, strikeout) {
  387. var a = $('<a />').attr('href',search_url).attr('target','_blank');
  388.  
  389. if (strikeout) {
  390. a.append($('<s />').append(link_text));
  391. } else {
  392. a.append(link_text);
  393. }
  394.  
  395. if (!onSearchPage) {
  396. // A little bit of trickery to make matches appear first in a list
  397. if (strikeout) {
  398. $('#pirateheader').append(a).append(' ');
  399. } else {
  400. $('#piratefound').append(a).append(' ');
  401. }
  402. } else {
  403. var result_box = $(elem).find('td.result_box');
  404. if (result_box.length > 0) {
  405. $(result_box).append(a);
  406. } else {
  407. $(elem).append($('<td />').append(a).addClass('result_box'));
  408. }
  409. }
  410. }
  411.  
  412. // Performs an ajax request to determine whether or not a url should be displayed
  413. function maybe_add_link(elem, link_text, search_url, search_fail_match, success_match) {
  414. if (typeof(success_match) === 'undefined') success_match = false;
  415. // If the search URL is an array, recurse briefly on the elements.
  416. if ($.isArray(search_url)) {
  417. $.each(search_url, function(index, url) {
  418. maybe_add_link(elem, link_text+'_'+(index+1).toString(), url, search_fail_match, success_match);
  419. });
  420. return;
  421. }
  422. GM_xmlhttpRequest({
  423. method: 'GET',
  424. url: search_url,
  425. onload: function (responseDetails) {
  426. if (String(responseDetails.responseText).match(search_fail_match) ? !(success_match) : success_match) {
  427. if (onSearchPage ? GM_config.get('strikeout_links_search') : GM_config.get('strikeout_links_movie')) {
  428. add_link(elem, search_url, link_text, true);
  429. }
  430. // If we're on the search page and it isn't found on PTP
  431. if (onSearchPage && link_text == 'PTP') {
  432. var box = $(elem).find('td.result_box');
  433. if (box.length > 0) {
  434. box.css('background-color','green');
  435. } else {
  436. $(elem).append($('<td />').css('background-color','green').addClass('result_box'));
  437. }
  438. }
  439. } else {
  440. add_link(elem, search_url, link_text, false);
  441. }
  442. }
  443. });
  444. }
  445.  
  446. // Run code to create fields and display sites
  447. function perform(elem, movie_id, movie_title) {
  448. var is_tv_page = Boolean(document.getElementsByTagName("title")[0].innerHTML.match("TV Series"));
  449.  
  450. $.each(sites, function(index, site) {
  451. if (site['show']) {
  452. // If we're on a TV page, only show TV links.
  453. if (Boolean(site['TV']) == is_tv_page || Boolean(site['both'])) {
  454. searchUrl = replace_search_url_params(site['searchUrl'], movie_id, movie_title);
  455. maybe_add_link(elem, site['name'], searchUrl, site['matchRegex']);
  456. }
  457. }
  458. });
  459. }
  460.  
  461. //------------------------------------------------------
  462. // Button Code
  463. //------------------------------------------------------
  464.  
  465. function display_button() {
  466. var p = $('<p />').attr('id', 'piratebutton');
  467. p.append($('<button>Load IMDB Scout</button>').click(function() {
  468. $('#piratebutton').remove();
  469. if (onSearchPage) {
  470. performSearch();
  471. } else {
  472. performPage();
  473. }
  474. }));
  475. if (onSearchPage) {
  476. $('#sidebar').append(p);
  477. } else {
  478. $('h1.header:first').parent().append(p);
  479. }
  480. }
  481.  
  482. //------------------------------------------------------
  483. // Icons at top bar
  484. //------------------------------------------------------
  485.  
  486. // Adds a dictionary of icons to the top of the page.
  487. // Unlike the other URLs, they aren't checked to see if the movie exists.
  488. function addIconBar(movie_id, movie_title) {
  489. var iconbar = $('h1.header:first');
  490. iconbar.id = 'iconbar';
  491. $.each(icon_sites, function(index, site) {
  492. var searchUrl = replace_search_url_params(site['searchUrl'], movie_id, movie_title);
  493. var image = $('<img />').attr({'style': '-moz-opacity: 0.4;',
  494. 'width': '16',
  495. 'border': '0',
  496. 'src': site['icon'],
  497. 'title': site['name']});
  498. var html = $('<span />').append($('<a />').attr('href', searchUrl).addClass('iconbar_icon').append(image));
  499. iconbar.append(html).append(' ');
  500. });
  501. //If we have access to the function
  502. if (GM_openInTab) {
  503. var aopenall = $("<a />").text("Open All")
  504. .attr("href", "javascript:;")
  505. .attr('style', 'font-weight:bold;font-size:10px;font-family: Calibri, Verdana, Arial, Helvetica, sans-serif;');
  506. aopenall.click( function () {
  507. $('.iconbar_icon').each(function () {
  508. GM_openInTab($(this).attr('href'));
  509. });
  510. }, false);
  511.  
  512. iconbar.append(aopenall);
  513. }
  514. }
  515.  
  516. //------------------------------------------------------
  517. // Search page code
  518. //------------------------------------------------------
  519.  
  520. function performSearch(){
  521. //Perform in search page
  522. var styles = '.result_box {width: 335px} .result_box a { margin-right: 5px; color: #444;} ';
  523. styles += ' .result_box a:visited { color: red;}';
  524. styles += ' #imdb2leech_tuned {position: fixed; bottom: 10px; right: 10px; z-index: 1000;} ';
  525. styles += ' #content-2-wide #main, #content-2-wide .maindetails_center {margin-left: 5px; width: 1001px;} ';
  526. GM_addStyle(styles);
  527. //Loop through each result row
  528. $('div#main table.results tr.detailed').each(function(){
  529. var link = $(this).find('td.image a');
  530. movie_title = link.html();
  531. movie_id = link.attr('href').match(/tt([0-9]*)\/?$/)[1];
  532. $(this).find('span.genre a').each(function(){
  533. if($(this).html() == "Adult") {
  534. $(this).parent().parent().parent().css('background-color','red');
  535. }
  536. });
  537. perform($(this), movie_id, movie_title);
  538. });
  539. }
  540.  
  541. //------------------------------------------------------
  542. // TV/movie page code
  543. //------------------------------------------------------
  544.  
  545. function performPage() {
  546. var movie_title = document.title.match(/^(.*?) \(/)[1];
  547. var movie_id = document.URL.match(/\/tt([0-9]+)\//)[1].trim('tt');
  548. //Create area to put links in
  549. var p = $('<p />').append(GM_config.get('pirate_header_text')).attr('id', 'pirateheader').attr('style', 'font-weight:bold; color:black; background-color: lightgray;');
  550. p.append($('<span />').attr('id', 'piratefound'));
  551. $('h1.header:first').parent().append(p);
  552. perform($('#pirateheader'), movie_id, movie_title);
  553. addIconBar(movie_id, movie_title);
  554. }
  555.  
  556. //------------------------------------------------------
  557. // Code being run (main)
  558. //------------------------------------------------------
  559.  
  560. // Get everything configured
  561.  
  562. // Create the non-site dictionary for GM_config
  563. var config_fields = {
  564. 'pirate_header_text': {
  565. 'label': 'Header text:',
  566. 'type': 'text',
  567. 'default': 'Pirate this film: '
  568. },
  569. 'load_on_start': {
  570. 'label': 'Load on start?',
  571. 'type': 'checkbox',
  572. 'default': true
  573. },
  574. 'strikeout_links_search': {
  575. 'label': 'Strike out links on search page?',
  576. 'type': 'checkbox',
  577. 'default': true
  578. },
  579. 'strikeout_links_movie': {
  580. 'label': 'Strike out links on movie page?',
  581. 'type': 'checkbox',
  582. 'default': true
  583. },
  584. };
  585.  
  586. // Sort the sites into a consistent pattern
  587. sites.sort(function (a, b) {
  588. return a['name'].toLowerCase() > b['name'].toLowerCase();
  589. });
  590.  
  591. // Add each site GM_config
  592. // The GM_config default for checkboxes is false
  593. $.each(sites, function(index, site) {
  594. config_fields['show_'+site['name']+(site['TV']?"_TV":"")] = {
  595. 'label': 'Show '+site['name']+(site['TV']?" (TV)":"")+'?',
  596. 'type': 'checkbox'
  597. }
  598. });
  599.  
  600. // Initialize and register GM_config
  601. GM_config.init({
  602. 'id': 'imbd_scout',
  603. 'title': 'IMDB Scout Preferences',
  604. 'fields': config_fields
  605. });
  606. GM_registerMenuCommand('Preferences for IMDB Scout', function() {GM_config.open()});
  607.  
  608. // Fetch per-site values from GM_config
  609. $.each(sites, function(index, site) {
  610. site['show'] = GM_config.get('show_'+site['name']+(site['TV']?"_TV":""));
  611. });
  612.  
  613. // Are we on a search page?
  614. // This variable is camelCased to show it's global
  615. // Hopefully it can be factored out of the global scope in the future
  616. var onSearchPage = Boolean(location.href.match('search'));
  617.  
  618. if (GM_config.get('load_on_start')) {
  619. if (!onSearchPage) {
  620. performPage();
  621. } else {
  622. performSearch();
  623. }
  624. } else {
  625. display_button();
  626. }