IMDB+

Add external links to IMDb. Every feature can be enabled/disabled in settings.

目前为 2018-03-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name IMDB+
  3. // @description Add external links to IMDb. Every feature can be enabled/disabled in settings.
  4. // @namespace http://n-e-s.info/
  5. // @include http://www.imdb.com/title/tt*
  6. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
  7. // @grant GM_getValue
  8. // @grant GM_setValue
  9. // @grant GM_addStyle
  10. // @version 4.2.0
  11. // ==/UserScript==
  12.  
  13. jQuery(document).ready(function ($) {
  14. let m = {};
  15. m.Id = getMovieId();
  16. m.Tt = getMovieTt();
  17. m.TtYr = getMovieTt() + "+" + getMovieYr();
  18.  
  19. let l = {};
  20. // l.ex = ["name", "link url", "title or alt text", "image url"];
  21. l.tmd = ["Torrentsmd", "http://torrentsmd.com/browse.php?imdb=" + m.Id, "tmd.ico"];
  22. l.rut = ["Rutracker", "http://rutracker.org/forum/tracker.php?nm=" + m.TtYr, "rutracker.ico"];
  23. l.tz = ["Torrentz", "http://torrentz.eu/search?f=" + m.TtYr, "torrentz.ico"];
  24. l.tpb = ["The Pirate Bay", "http://thepiratebay.se/search/" + m.TtYr + "/0/99/200", "tpb.ico"];
  25. l.yt = ["Youtube", "https://www.youtube.com/results?search_query=" + m.TtYr, "youtube.ico"];
  26. l.mpdb = ["MoviePosterDB", "http://www.movieposterdb.com/movie/" + m.Id, "mpdb.ico"];
  27. l.kp = ["Kinopoisk", "http://www.kinopoisk.ru/index.php?first=yes&kp_query=" + m.Tt, "kinopoisk.ico"];
  28. l.cmg = ["Cinemagia", "http://www.cinemagia.ro/cauta/?q=" + m.TtYr, "cinemagia.jpg"];
  29. l.crx = ["CinemaRx", "http://www.cinemarx.ro/cauta/filme/" + m.TtYr, "cinemarx.ico"];
  30. l.allm = ["allMovie", "http://www.allmovie.com/search/movies/" + m.TtYr, "allm.ico"];
  31. l.rt = ["Rotten Tomatoes", "http://www.rottentomatoes.com/alias?type=imdbid&s=" + m.Id, "rt.ico"];
  32. l.wiki = ["Wikipedia", "http://en.wikipedia.org/wiki/" + m.Tt, "wikipedia.ico"];
  33. l.osub = ["OpenSubs", "http://www.opensubtitles.org/en/search/sublanguageid-all/imdbid-" + m.Id, "opensubs.ico"];
  34. l.ssc = ["Subscene", "http://subscene.com/s.aspx?q=" + m.TtYr, "subscene.ico"];
  35. l.ggl = ["Google", "http://www.google.md/search?q=" + m.TtYr, "google.ico"];
  36.  
  37. /**
  38. * Get movie title
  39. * @returns {string}
  40. */
  41. function getMovieTt() {
  42. return encodeURIComponent(document.title.replace(/^(.+) \((.*)([0-9]{4})(.*)$/gi, '$1'));
  43. }
  44.  
  45. /**
  46. * Get movie release year
  47. * @returns {string}
  48. */
  49. function getMovieYr() {
  50. return encodeURIComponent(document.title.replace(/^(.+) \((.*)([0-9]{4})(.*)$/gi, '$3'));
  51. }
  52.  
  53. /**
  54. * Get movie id
  55. * @returns {string}
  56. */
  57. function getMovieId() {
  58. return location.pathname.match(/title\/tt(.*?)\//i)[1];
  59. }
  60.  
  61. function IMDbPlusStyle() {
  62. let s = `
  63. #title-overview-widget #IMDbPlus { padding: 5px 20px; }
  64. #title-overview-widget #IMDbPlus a { margin: 5px 1px; }
  65. #title-overview-widget #IMDbPlus #IMDbPlus-Feature-Settings { margin-left: 10px; }
  66. #action-box #IMDbPlus #IMDbPlus-Feature-Settings { margin-top: 10px; }
  67. #IMDbPlus-SettingsBox { display: none; margin-left: -404px; padding: 20px; position: fixed; top: 10%; left: 50%; width: 768px; z-index: 999; }
  68. #IMDbPlus-SettingsBox > h2 { font-size: 21px }
  69. #IMDbPlus-SettingsBox > h4 { font-size: 15px }
  70. #IMDbPlus-SettingsBox #IMDbPlus-Options { margin: 20px 0;}
  71. #IMDbPlus-SettingsBox #IMDbPlus-Options .IMDbPlus-OptionField label { display: inline-block; width: 150px; }
  72. #IMDbPlus-SettingsBox button { margin: 8px 0 0; }
  73. #IMDbPlus-SettingsBox #IMDbPlus-SettingsBox-Close { float: right; }
  74. .IMDbPlus-Button img { height: 16px; width: 16px; }
  75. `;
  76. GM_addStyle(s);
  77. }
  78.  
  79. function IMDbPlusInit() {
  80. let featuresHTML, optionsHTML, donationHTML;
  81. featuresHTML = '<div id="IMDbPlus"><h4>IMDB+ Features:</h4>';
  82. donationHTML = '<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" style="float: right;">'+
  83. '<input type="hidden" name="cmd" value="_s-xclick">'+
  84. '<input type="hidden" name="hosted_button_id" value="YSRE94S484DAA">'+
  85. '<input type="image" src="https://www.paypalobjects.com/en_GB/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online.">'+
  86. '<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">'+
  87. '</form>';
  88. optionsHTML = '<div id="IMDbPlus-SettingsBox" class="aux-content-widget-2">' + donationHTML + '<h2>IMDb+ Options</h2><h4>Control the features you want to show</h4><ul id="IMDbPlus-Options">';
  89.  
  90. $.each(l, function (key,val) {
  91. if (GM_getValue("IMDbPlus-Option-" + val[0], 1)) {
  92. featuresHTML += '<a class="IMDbPlus-Button linkasbutton-secondary" id="IMDbPlus-Feature-' + val[0] + '" href="' + val[1] + '" target="_blank" title="On ' + val[0] + '"><img alt="On ' + val[0] + '" src="http://img.n-e-s.info/imdbplus/' + val[2] + '"></a>';
  93. }
  94. optionsHTML += '<li id="IMDbPlus-Option-' + val[0] + '-Field" class="IMDbPlus-OptionField"><label for="IMDbPlus-Option-' + val[0] + '">' + val[0] + '</label> <input id="IMDbPlus-Option-' + val[0] + '" type="checkbox"' + ((GM_getValue("IMDbPlus-Option-" + val[0], 1)) ? ' checked' : '') + '></li>';
  95. });
  96.  
  97. featuresHTML += '<a class="IMDbPlus-Button linkasbutton-secondary" id="IMDbPlus-Feature-Settings" title="Open settings frame"><img alt="Settings" src="http://img.n-e-s.info/imdbplus/settings.ico"></a></div>';
  98. optionsHTML +=
  99. '</ul><hr>'+
  100. '<button id="IMDbPlus-SettingsBox-Save" class="primary">Save</button>'+
  101. '<button id="IMDbPlus-SettingsBox-Close" class="primary">Close</button>'+
  102. '</div>';
  103.  
  104. IMDbPlusStyle();
  105.  
  106. if (location.pathname.match(/reference/)) {
  107. $('#main').find('.article').prepend(featuresHTML);
  108. } else {
  109. $('#title-overview-widget').find('.title_block').append(featuresHTML);
  110. }
  111.  
  112. // $((location.pathname.match(/reference/)) ? 'section.article' : '#title-overview-widget').append(featuresHTML);
  113. $('body').append(optionsHTML);
  114.  
  115. }
  116.  
  117. IMDbPlusInit();
  118.  
  119. function showOpts() {
  120. $('#wrapper').css('visibility', 'hidden').animate({ opacity: 0 }, 500);
  121. $('#IMDbPlus-SettingsBox').show(500);
  122. }
  123.  
  124. function hideOpts() {
  125. $('#IMDbPlus-SettingsBox').hide(500);
  126. $('#wrapper').css('visibility', 'visible').animate({ opacity: 1 }, 500);
  127. }
  128.  
  129. function saveOpts() {
  130. $('.IMDbPlus-OptionField').each(function () {
  131. let inputElm = $('input', this);
  132. let inputId = inputElm.attr('id');
  133. GM_setValue(inputId, (inputElm.is(":checked") ? 1 : 0));
  134. });
  135. hideOpts();
  136. window.location.reload();
  137. }
  138.  
  139. // Interactions
  140. $('#IMDbPlus-Feature-Settings').on("click", showOpts);
  141. $('#IMDbPlus-SettingsBox-Close').on("click", hideOpts);
  142. $('#IMDbPlus-SettingsBox-Save').on("click", saveOpts);
  143.  
  144. $(document).keyup(function (e) {
  145. if(e.keyCode === 27) hideOpts();
  146. });
  147. });
  148.  
  149. /**
  150. * MIT License (MIT)
  151. *
  152. * Copyright (c) 2018 Sergiu Negara <sergiu@negara.pro>
  153. *
  154. * Permission is hereby granted, free of charge, to any person obtaining a copy
  155. * of this software and associated documentation files (the "Software"), to deal
  156. * in the Software without restriction, including without limitation the rights
  157. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  158. * copies of the Software, and to permit persons to whom the Software is
  159. * furnished to do so, subject to the following conditions:
  160. *
  161. * The above copyright notice and this permission notice shall be included in all
  162. * copies or substantial portions of the Software.
  163. *
  164. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  165. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  166. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  167. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  168. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  169. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  170. * SOFTWARE.
  171. * */