您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
让推特图片浏览更加人性化
当前为
- // ==UserScript==
- // @name Twitter image viewing enhancement
- // @name:zh-CN Twitter 图片查看增强
- // @name:zh-TW Twitter 圖像查看增強
- // @icon https://twitter.com/favicon.ico
- // @namespace https://moe.best/
- // @version 0.4.1
- // @description Make Twitter photo viewing more humane
- // @description:zh-CN 让推特图片浏览更加人性化
- // @description:zh-TW 讓 Twitter 照片瀏覽更人性化
- // @author Jindai Kirin
- // @include https://twitter.com/*
- // @license MIT
- // @grant none
- // @run-at document-end
- // @require https://cdn.bootcss.com/jquery/3.4.1/jquery.slim.min.js
- // @require https://cdn.bootcss.com/jquery-mousewheel/3.1.13/jquery.mousewheel.min.js
- // ==/UserScript==
- (function() {
- 'use strict';
- const closeImgView = () => $('div[aria-labelledby="modal-header"] div[aria-haspopup="false"][role="button"][style]:not([data-testid])').click();
- const btnGroup = () => $('div[aria-labelledby="modal-header"] div[aria-haspopup="false"][role="button"]:not([data-testid]):not([style])');
- const prevImg = () => {
- const $btn = $(btnGroup()[0]);
- if (!$btn.attr('disabled')) $btn.click();
- };
- const nextImg = () => {
- const $btn = $(btnGroup()[1]);
- if (!$btn.attr('disabled')) $btn.click();
- };
- $(window).mousewheel(({ deltaY, target: { tagName, baseURI } }) => {
- if (tagName == 'IMG' && /\/photo\//.test(baseURI)) {
- switch (deltaY) {
- case 1:
- prevImg();
- break;
- case -1:
- nextImg();
- break;
- }
- }
- });
- let x = 0;
- let y = 0;
- $(window).mousedown(({ clientX, clientY }) => {
- x = clientX;
- y = clientY;
- });
- $(window).mouseup(({ button, clientX, clientY, target: { tagName, baseURI } }) => {
- if (button !== 0 || !(tagName == 'IMG' && /\/photo\//.test(baseURI))) return;
- const [sx, sy] = [clientX - x, clientY - y].map(Math.abs);
- const mx = clientX - x;
- if (sx <= 10 && sy <= 10) closeImgView();
- if (sy <= sx) {
- if (mx > 0) prevImg();
- else if (mx < 0) nextImg();
- }
- });
- })();