Twitter 图片查看增强

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

当前为 2020-03-04 提交的版本,查看 最新版本

  1. // 注意 NOTICE
  2. // v0.5.0 中包含一些重大更新,如果你不是简体中文用户,请访问脚本主页以了解这一变更,否则你可能无法正常使用。
  3. // There are some significant changes in v0.5.0, please visit the homepage of this script for more information.
  4. // ==UserScript==
  5. // @name Twitter image viewing enhancement
  6. // @name:zh-CN Twitter 图片查看增强
  7. // @name:zh-TW Twitter 圖像查看增強
  8. // @icon https://twitter.com/favicon.ico
  9. // @namespace https://moe.best/
  10. // @version 0.5.0
  11. // @description Make Twitter photo viewing more humane
  12. // @description:zh-CN 让推特图片浏览更加人性化
  13. // @description:zh-TW 讓 Twitter 照片瀏覽更人性化
  14. // @author Jindai Kirin
  15. // @include https://twitter.com/*
  16. // @license MIT
  17. // @grant GM_getValue
  18. // @grant GM_setValue
  19. // @grant GM_registerMenuCommand
  20. // @grant GM_openInTab
  21. // @run-at document-end
  22. // @require https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js
  23. // @require https://cdn.jsdelivr.net/npm/jquery-mousewheel@3.1.13/jquery.mousewheel.min.js
  24. // ==/UserScript==
  25.  
  26. (function() {
  27. 'use strict';
  28.  
  29. const defaultLabels = { close: '关闭', prev: '上一个', next: '下一步' };
  30. const labels = (() => {
  31. try {
  32. return JSON.parse(GM_getValue('labels', JSON.stringify(defaultLabels)));
  33. } catch (error) {
  34. console.warn('Invalid setting.');
  35. return defaultLabels;
  36. }
  37. })();
  38. console.log('aria-labels', labels);
  39. GM_registerMenuCommand('Set aria-labels', () => {
  40. let input, list;
  41. let error = false;
  42. do {
  43. input = prompt(`Please input the aria-label of close, prev, next button and join them by comma (,). Input nothing will reset it to default value.${error ? '\n\nINPUT ERROR' : ''}`, input || Object.values(labels).join(','));
  44. if (input === null) return;
  45. if (input.length === 0) list = Object.values(defaultLabels);
  46. else list = input.split(',').map(label => label.trim());
  47. error = list.length !== Object.keys(labels).length;
  48. } while (error);
  49. Object.keys(labels).forEach((key, index) => {
  50. labels[key] = list[index];
  51. });
  52. GM_setValue('labels', JSON.stringify(labels));
  53. console.log('aria-labels', labels);
  54. });
  55.  
  56. const getBtnByLabel = label => $(`div[aria-labelledby="modal-header"] div[aria-label="${label}"]`);
  57.  
  58. const closeImgView = () => {
  59. const $btn = getBtnByLabel(labels.close);
  60. if ($btn.length) $btn.click();
  61. else if (confirm("It seems that you haven't set the right aria-labels yet. Please visit the homepage of this script for more information.")) GM_openInTab('https://gf.qytechs.cn/zh-CN/scripts/387918', false);
  62. };
  63. const prevImg = () => getBtnByLabel(labels.prev).click();
  64. const nextImg = () => getBtnByLabel(labels.next).click();
  65.  
  66. $(document).mousewheel(({ deltaY, target: { tagName, baseURI } }) => {
  67. if (tagName == 'IMG' && /\/photo\//.test(baseURI)) {
  68. switch (deltaY) {
  69. case 1:
  70. prevImg();
  71. break;
  72. case -1:
  73. nextImg();
  74. break;
  75. }
  76. }
  77. });
  78.  
  79. let x = 0;
  80. let y = 0;
  81. $(document).mousedown(({ clientX, clientY }) => {
  82. x = clientX;
  83. y = clientY;
  84. });
  85. $(document).mouseup(({ button, clientX, clientY, target: { tagName, baseURI } }) => {
  86. if (button !== 0 || !(tagName == 'IMG' && /\/photo\//.test(baseURI))) return;
  87. const [sx, sy] = [clientX - x, clientY - y].map(Math.abs);
  88. const mx = clientX - x;
  89. if (sx <= 10 && sy <= 10) closeImgView();
  90. if (sy <= sx) {
  91. if (mx > 0) prevImg();
  92. else if (mx < 0) nextImg();
  93. }
  94. });
  95. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址