Image viewer

Use grid wallpaper to highlight transparent image. Support to view the large image by holding the right mouse and drag.

目前为 2019-10-11 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Image viewer
  3. // @namespace http://devs.forumvi.com/
  4. // @description Use grid wallpaper to highlight transparent image. Support to view the large image by holding the right mouse and drag.
  5. // @version 2.2.0
  6. // @icon http://i.imgur.com/ItcjCPc.png
  7. // @author Zzbaivong
  8. // @oujs:author baivong
  9. // @license MIT; https://baivong.mit-license.org/license.txt
  10. // @match http://*/*
  11. // @match https://*/*
  12. // @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js?v=a834d46
  13. // @noframes
  14. // @supportURL https://github.com/lelinhtinh/Userscript/issues
  15. // @run-at document-start
  16. // @grant GM_addStyle
  17. // @inject-into content
  18. // ==/UserScript==
  19.  
  20. (function () {
  21.  
  22. 'use strict';
  23.  
  24. /**
  25. * Background mode
  26. * @type {string} dark
  27. * light
  28. */
  29. var theme = 'dark';
  30.  
  31.  
  32. // Do not change the code below this line, unless you know how.
  33. var doc = document,
  34. color = theme === 'light' ? ['#eee', 'white'] : ['gray', '#444'];
  35.  
  36. if (doc.contentType.indexOf('image/') !== 0) return;
  37.  
  38. function scrollByDragging(container, disableH, disableV) {
  39.  
  40. function mouseUp(e) {
  41. if (e.which !== 3) return;
  42.  
  43. window.removeEventListener('mousemove', mouseMove, true);
  44. container.style.cursor = 'default';
  45. }
  46.  
  47. function mouseDown(e) {
  48. if (e.which !== 3) return;
  49.  
  50. pos = {
  51. x: e.clientX,
  52. y: e.clientY
  53. };
  54.  
  55. window.addEventListener('mousemove', mouseMove, true);
  56. container.style.cursor = 'move';
  57. }
  58.  
  59. function mouseMove(e) {
  60. if (!disableH) container.scrollLeft -= (-pos.x + (pos.x = e.clientX));
  61. if (!disableV) container.scrollTop -= (-pos.y + (pos.y = e.clientY));
  62. }
  63.  
  64. var pos = {
  65. x: 0,
  66. y: 0
  67. };
  68.  
  69. container.oncontextmenu = function (e) {
  70. e.preventDefault();
  71. };
  72.  
  73. container.addEventListener('mousedown', mouseDown, false);
  74. window.addEventListener('mouseup', mouseUp, false);
  75.  
  76. }
  77.  
  78. GM_addStyle('body{background-attachment: fixed !important; background-position: 0px 0px, 10px 10px !important; background-size: 20px 20px !important; background-image: linear-gradient(45deg, ' + color[0] + ' 25%, transparent 25%, transparent 75%, ' + color[0] + ' 75%, ' + color[0] + ' 100%),linear-gradient(45deg, ' + color[0] + ' 25%, ' + color[1] + ' 25%, ' + color[1] + ' 75%, ' + color[0] + ' 75%, ' + color[0] + ' 100%) !important;} body > img {background-color: transparent !important; background-image: none !important; display: block; margin: auto; position: absolute; left: 0; top: 0; right: 0; bottom: 0;} body > img:hover {background: rgba(0, 0, 0, 0.4) !important; outline: 3px solid #333;} body > img[style*="cursor: zoom-out;"], body > img.overflowing {position: relative !important;}');
  79.  
  80. scrollByDragging(doc.body);
  81. scrollByDragging(doc.documentElement);
  82.  
  83. }());