Twitter 图片查看增强

让推特图片浏览更加人性化

当前为 2019-12-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Twitter image viewing enhancement
  3. // @name:zh-CN Twitter 图片查看增强
  4. // @name:zh-TW Twitter 圖像查看增強
  5. // @icon https://twitter.com/favicon.ico
  6. // @namespace https://moe.best/
  7. // @version 0.3.1
  8. // @description Make Twitter photo viewing more humane
  9. // @description:zh-CN 让推特图片浏览更加人性化
  10. // @description:zh-TW 讓 Twitter 照片瀏覽更人性化
  11. // @author Jindai Kirin
  12. // @include https://twitter.com/*
  13. // @license MIT
  14. // @grant none
  15. // @run-at document-end
  16. // @require https://cdn.bootcss.com/jquery/3.4.1/jquery.slim.min.js
  17. // @require https://cdn.bootcss.com/jquery-mousewheel/3.1.13/jquery.mousewheel.min.js
  18. // ==/UserScript==
  19.  
  20. (function() {
  21. 'use strict';
  22.  
  23. const closeImgView = () => $('div[aria-labelledby="modal-header"] div[aria-haspopup="false"][role="button"][style]:not([data-testid])').click();
  24. const btnGroup = () => $('div[aria-labelledby="modal-header"] div[aria-haspopup="false"][role="button"]:not([data-testid]):not([style])');
  25. const prevImg = () => {
  26. const $btn = $(btnGroup()[0]);
  27. if (!$btn.attr('disabled')) $btn.click();
  28. };
  29. const nextImg = () => {
  30. const $btn = $(btnGroup()[1]);
  31. if (!$btn.attr('disabled')) $btn.click();
  32. };
  33.  
  34. $(document).click(({ target: { tagName, baseURI } }) => {
  35. if (tagName == 'IMG' && /\/photo\//.test(baseURI)) closeImgView();
  36. });
  37.  
  38. $(window).mousewheel(({ deltaY, target: { tagName, baseURI } }) => {
  39. if (tagName == 'IMG' && /\/photo\//.test(baseURI)) {
  40. switch (deltaY) {
  41. case 1:
  42. prevImg();
  43. break;
  44. case -1:
  45. nextImg();
  46. break;
  47. }
  48. }
  49. });
  50. })();