🏠 返回首頁 

Greasy Fork is available in English.

Mangaupdates Cover Preview

Previews covers in mangaupdates.com when hovering over hyperlinks that lead to manga pages.

  1. // ==UserScript==
  2. // @name Mangaupdates Cover Preview
  3. // @namespace https://twitter.com/Kuroonehalf
  4. // @include https://www.mangaupdates.com/*
  5. // @include http://www.mangaupdates.com/*
  6. // @version 2.0
  7. // @description Previews covers in mangaupdates.com when hovering over hyperlinks that lead to manga pages.
  8. // @grant GM_setValue
  9. // @grant GM_getValue
  10. // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
  11. // @license http://creativecommons.org/licenses/by-nc-sa/4.0/
  12. // ==/UserScript==
  13. // Link title suppression
  14. $('[title]').each( function() {
  15. var $this = $(this);
  16. $this.data('title',$this.attr('title'));
  17. $this.removeAttr('title');
  18. });
  19. // Centering function
  20. var pathname = document.URL;
  21. var MangaPageTest = /series\.html\?id\=[0-9]*$/;
  22. jQuery.fn.center = function () {
  23. this.css('top', Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) + $(window).scrollTop()) + 'px');
  24. if (pathname.search(MangaPageTest) != -1){
  25. this.css('left', Math.max(0, (($(window).width() - $(this).outerWidth()) * 0.4) + $(window).scrollLeft()) + 'px');
  26. }
  27. else {
  28. this.css('left', Math.max(0, (($(window).width() - $(this).outerWidth()) * 0.6) + $(window).scrollLeft()) + 'px');
  29. }
  30. return this;
  31. }
  32. $('body').append('<div ID="popover"></div>');
  33. $('#popover').css('position', 'absolute');
  34. $('#popover').css('z-index', '10');
  35. $('#popover').css('box-shadow', '0px 0px 5px #7A7A7A');
  36. $('.col-6 a').mouseover(function () {
  37. var Href = $(this).attr('href');
  38. console.log(Href);
  39. if (Href.search(MangaPageTest) != - 1) {
  40. console.log("This is a manga page");
  41. $(this).css('font-weight', 'bold'); // Bolds previously hovered links.
  42. if (GM_getValue(Href)) {
  43. var retrievedLink = GM_getValue(Href);
  44. $('#popover').empty();
  45. $('#popover').append('<img src="' + retrievedLink + '"></img>');
  46. $('#popover img').load(function() {
  47. $('#popover').center();
  48. });
  49. console.log(Href + " has been found and retrieved from the cache."); // for testing purposes
  50. }
  51. else {
  52. $.ajax({
  53. url: Href,
  54. dataType: 'text',
  55. success: function (data) {
  56. var imagelink = $('<div>').html(data)[0].getElementsByClassName('sContent')[13].getElementsByTagName('img') [0].src;
  57. // clear what's inside #popover and put the new image in there
  58. $('#popover').empty();
  59. $('#popover').append('<img src="' + imagelink + '"></img>');
  60. $('#popover img').load(function () {
  61. $('#popover').center();
  62. });
  63. // // cache info
  64. GM_setValue(Href, imagelink);
  65. console.log(imagelink + ') successfully cached.') // for testing purposes
  66. }
  67. });
  68. }
  69. }
  70. });
  71. $('.col-6 a').mouseleave(function () {
  72. $('#popover').empty();
  73. });