Previsualizer

Permet de prévisualiser un topic.

当前为 2016-02-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Previsualizer
  3. // @namespace JVScript
  4. // @include http://www.jeuxvideo.com/*
  5. // @version 6
  6. // @require http://code.jquery.com/jquery-2.1.3.min.js
  7. // @grant GM_addStyle
  8. // @copyright MIT
  9. // @author Kiwec
  10. // @description Permet de prévisualiser un topic.
  11. // ==/UserScript==
  12.  
  13. "use strict";
  14.  
  15. (function() {
  16.  
  17. function Link(node) {
  18. this.$message = $('<div><img style="margin: auto; display: block !important; width: 25%;" src="http://s3.noelshack.com/uploads/images/20188032684831_loading.gif" alt="Loading" /></div>');
  19. this.$message.attr('class', 'prev_content bloc-message-forum');
  20. this.$topic = node;
  21.  
  22. this.initialize();
  23. }
  24.  
  25. Link.prototype = {
  26. initialize: function() {
  27. var url = this.$topic.find('a.topic-title').attr('href');
  28. this.$topic.find('img.topic-img').wrap('<span class="span-topic-img"></span>');
  29. this.$topic.find('.span-topic-img').append(this.$message);
  30. this.$topic.find('.topic-img').on('mouseenter', (function() {
  31. $.get(url).done((function(response) {
  32. var success = $($.parseHTML(response)).find('.bloc-message-forum');
  33. this.$message.html($(success[0]).html());
  34. }).bind(this));
  35. }).bind(this));
  36. }
  37. }
  38.  
  39. function addPreload() {
  40. $('.topic-list li:not(.topic-head)').each(function() {
  41. new Link($(this));
  42. });
  43. }
  44.  
  45. addPreload();
  46. addEventListener('instantclick:newpage', addPreload);
  47.  
  48. GM_addStyle(
  49. '.prev_content { position: absolute; z-index: 1000; width: 600px; max-height: 500px; overflow-y: scroll; ' +
  50. 'display: none; margin-left: 10px; margin-top: 15px; font-weight: 200; }' +
  51. '.span-topic-img:hover .prev_content { display: block; }'
  52. );
  53.  
  54. })();