让推特图片浏览更加人性化
当前为
// ==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.0
// @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(({ clientX, clientY, target: { tagName, baseURI } }) => {
if (!(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();
}
});
})();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址