Skip to content

Instantly share code, notes, and snippets.

@patwonder
Last active August 11, 2020 09:39
Show Gist options
  • Save patwonder/6b2c5a630e3234b017ee to your computer and use it in GitHub Desktop.
Save patwonder/6b2c5a630e3234b017ee to your computer and use it in GitHub Desktop.
新浪微博直接看大图
// ==UserScript==
// @id weibo-direct-large-image@[email protected]
// @name 新浪微博直接看大图
// @version 1.6
// @namespace [email protected]
// @author patwonder
// @description
// @updateURL https://gist.githubusercontent.com/patwonder/6b2c5a630e3234b017ee/raw/weibo-direct-large-image.user.js
// @downloadURL https://gist.githubusercontent.com/patwonder/6b2c5a630e3234b017ee/raw/weibo-direct-large-image.user.js
// @include https://www.weibo.com/*
// @include https://weibo.com/*
// @include http://www.weibo.com/*
// @include http://weibo.com/*
// @include https://www.weibo.com/*
// @include https://weibo.com/*
// @run-at document-end
// @grant none
// ==/UserScript==
(function(d,w) {
var showSelector = "a.S_txt1[action-type*=\"photoview\"], a.S_txt1[action-type*=\"photoview\"] *, a.S_txt1[action-type*=\"PhotoView\"], a.S_txt1[action-type*=\"PhotoView\"] *";
var expandSelector = "div.WB_expand_media";
var imgSelector = ".artwork_box > img, .artwork_box > div > img";
var urlReplaceRegex = /\/(bmiddle)|(mw\d+)\//;
function matchesSelector(element, selector) {
if (element.mozMatchesSelector) {
return element.mozMatchesSelector(selector);
} else if (element.webkitMatchesSelector) {
return element.webkitMatchesSelector(selector);
} else if (element.matchesSelector) {
return element.matchesSelector(selector);
} else {
try {
var elems = element.parentElement ? element.parentElement.querySelectorAll(selector) : [];
for (var i = 0, l = elems.length; i < l; i++) {
if (elems[i] === element) return true;
}
} catch (ex) { }
}
return false;
}
w.addEventListener("click", function(e) {
if (matchesSelector(e.target, showSelector)) {
try {
var expand = e.target.parentElement;
for (var i = 0; (i < 10) && expand; i++) {
if (matchesSelector(expand, expandSelector)) {
var img = expand.querySelector(imgSelector);
if (img && urlReplaceRegex.test(img.src)) {
var largeImgSrc = img.src.replace(urlReplaceRegex, "/large/");
window.open(largeImgSrc);
e.stopImmediatePropagation();
e.preventDefault();
return false;
}
}
expand = expand.parentElement;
}
} catch (e) {
}
}
}, true);
})(document, window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment