Skip to content

Commit 7508bdb

Browse files
committed
find image url in any data-* attribute
1 parent 36ddc8a commit 7508bdb

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

script.user.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// @grant GM.setValue
2626
// @grant GM.xmlHttpRequest
2727
//
28-
// @version 1.4.7
28+
// @version 1.4.8
2929
// @author tophf
3030
//
3131
// @original-version 2017.9.29
@@ -88,6 +88,7 @@ const SETTLE_TIME = 50;
8888
// used to detect JS code in host rules
8989
const RX_HAS_CODE = /(^|[^-\w])return[\W\s]/;
9090
const RX_EVAL_BLOCKED = /'Trusted(Script| Type)'|unsafe-eval/;
91+
const RX_IMAGE_URL = /https?:\/\/[^\s"<>]+?\.(jpe?g|gif|png|svg|web[mp]|mp4)[^\s"<>]*|$/i;
9192
const RX_MEDIA_URL = /^(?!data:)[^?#]+?\.(avif|bmp|jpe?g?|gif|mp4|png|svgz?|web[mp])($|[?#])/i;
9293
const BLANK_PIXEL = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
9394
const ZOOM_MAX = 16;
@@ -2650,15 +2651,14 @@ const Req = {
26502651

26512652
findImageUrl(n, url) {
26522653
if (!n) return;
2653-
let html;
2654+
let tmp;
26542655
const path =
2655-
n.getAttribute('data-src') || // lazy loaded src, whereas current `src` is an empty 1x1 pixel
2656+
// prefer data-* over `src` which is often a small thumbnail or empty pixel
2657+
Object.values(n.dataset).some(v => (tmp = v.match(RX_IMAGE_URL)[0])) && tmp ||
26562658
n.getAttribute('src') ||
2657-
n.getAttribute('data-m4v') ||
26582659
n.getAttribute('href') ||
26592660
n.getAttribute('content') ||
2660-
(html = n.outerHTML).includes('http') &&
2661-
html.match(/https?:\/\/[^\s"<>]+?\.(jpe?g|gif|png|svg|web[mp]|mp4)[^\s"<>]*|$/i)[0];
2661+
(tmp = n.outerHTML).includes('http') && tmp.match(RX_IMAGE_URL)[0];
26622662
return !!path && Util.rel2abs(Util.decodeHtmlEntities(path),
26632663
$prop('base[href]', 'href', n.ownerDocument) || url);
26642664
},

0 commit comments

Comments
 (0)