Skip to content

Commit

Permalink
Improve performance under youtube with ublock origin enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
qsniyg committed Jan 25, 2024
1 parent f02212d commit cd1b8a9
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 8 deletions.
44 changes: 40 additions & 4 deletions src/userscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40741,7 +40741,8 @@ var $$IMU_EXPORT$$;
.replace(/\/resize\/+[-0-9]+x[-0-9]+\//, "/");
}

if (domain_nosub === "zadn.vn" && domain.match(/^photo-resize-/)) {
if ((domain_nosub === "zadn.vn" && domain.match(/^photo-resize-/)) ||
domain === "org.photo-resize.mp3.zdn.vn") {
// https://photo-resize-zmp3.zadn.vn/w240h240_jpeg/covers/9/d/9df0d52438b40d91aeaef1c1c2338e92_1476548588.jpg
// https://photo-resize-zmp3.zadn.vn/w240h240_jpeg/covers/9/d/9df0d52438b40d91aeaef1c1c2338e92_1476548588.jpg -- gets redirected to:
// http://org.photo-resize.mp3.zdn.vn/covers/9/d/9df0d52438b40d91aeaef1c1c2338e92_1476548588.jpg
Expand Down Expand Up @@ -41447,6 +41448,10 @@ var $$IMU_EXPORT$$;
// https://www.advocate-art.com/system/ART/Modules/Application/Images/Image/images/000/376/119/medium/ALL258457.png?1788fbdd5f9e2355cd5b5100045df0bc262ada91a284f206a2fe02cd0a68e3e5
// https://www.advocate-art.com/system/ART/Modules/Application/Images/Image/images/000/376/119/original/ALL258457.png?1788fbdd5f9e2355cd5b5100045df0bc262ada91a284f206a2fe02cd0a68e3e5
domain_nowww === "advocate-art.com" ||
// thanks to anonymous for reporting:
// https://d34gglw95p9zsk.cloudfront.net/item_cocreco_images/images/000/122/614/medium/eb02072f-fca2-4a0e-bbd8-7627229f6930.jpg?1672023100
// https://d34gglw95p9zsk.cloudfront.net/item_cocreco_images/images/000/122/614/original/eb02072f-fca2-4a0e-bbd8-7627229f6930.jpg?1672023100
domain === "d34gglw95p9zsk.cloudfront.net" ||
// https://sonar.es/system/attached_images/18702/medium/badgyal_xs_sonar2017_fernandoschlaepfer_004.jpg?1497713257 -- stretched?
// https://sonar.es/system/attached_images/18702/original/badgyal_xs_sonar2017_fernandoschlaepfer_004.jpg?1497713257
domain_nowww === "sonar.es") {
Expand All @@ -41455,7 +41460,7 @@ var $$IMU_EXPORT$$;
// https://sonarreykjavik.com/system/attached_images/19379/original/BadGyal_AlexisG%C3%B3mez.jpg?1513685256
return src
.replace(/(\/attached_images\/+[0-9]+\/+)[a-z]+\/+/, "$1original/")
.replace(/(\/(?:(?:system|images)\/+)?(?:(?:attached|item)_images|App\/+BlogBody|post_pictures|events|posts|items|articles|file_uploads|screenshots|resources|pictures|guides|Image)\/+(?:(?:images|photos|files|assets|pictures|posters|uploads|screenshots|previews|imgs|cropped_images)\/+)?(?:[0-9]{3}\/+){3})[a-z_0-9]+\/+/, "$1original/");
.replace(/(\/(?:(?:system|images)\/+)?(?:(?:attached|item)_images|App\/+BlogBody|post_pictures|events|posts|items|articles|file_uploads|screenshots|resources|pictures|guides|Image|item_cocreco_images)\/+(?:(?:images|photos|files|assets|pictures|posters|uploads|screenshots|previews|imgs|cropped_images)\/+)?(?:[0-9]{3}\/+){3})[a-z_0-9]+\/+/, "$1original/");
//return src.replace(/(\/system\/(?:post_pictures\/(?:files|assets|pictures)\/|posts\/posters\/|events\/images\/)(?:[0-9]+\/){3})[a-z]+(\/[^/]*)$/, "$1original$2");
//return src.replace(/\/[a-z]*\/([-0-9a-f]*\.[^/.]*)$/, "/original/$1");
//return src.replace(/(\/[0-9]+\/[0-9]+\/[0-9]+)\/[a-z]+\/([^/]*)$/, "$1/original/$2");
Expand Down Expand Up @@ -111354,11 +111359,21 @@ var $$IMU_EXPORT$$;

if (domain_nowww === "lemmy.world" ||
// thanks to anonymous for reporting:
domain_nowww === "lemmynsfw.com") {
domain_nowww === "lemmynsfw.com" ||
// https://sopuli.xyz/pictrs/image/9250571e-5e5c-4324-bb3f-ce2d5edc4624.webp?format=webp&thumbnail=256
// https://sopuli.xyz/pictrs/image/9250571e-5e5c-4324-bb3f-ce2d5edc4624.webp
domain_nowww === "sopuli.xyz" ||
// https://lemmy.ml/pictrs/image/de0d44c4-f082-45f2-b0a3-111a985be9cd.jpeg?format=webp&thumbnail=256
// https://lemmy.ml/pictrs/image/de0d44c4-f082-45f2-b0a3-111a985be9cd.jpeg
domain_nowww === "lemmy.ml") {
// https://lemmy.world/pictrs/image/54d5e64c-05e2-4c09-913e-b5fb66f58f6a.webp?format=webp&thumbnail=256
// https://lemmy.world/pictrs/image/54d5e64c-05e2-4c09-913e-b5fb66f58f6a.webp
if (/\/pictrs\/+image\/+[-0-9a-f]{10,}\./.test(src)) {
return remove_queries(src, ["thumbnail"]).replace(/([?&])format=webp/, "$1").replace(/[?&]$/, "");
return {
url: remove_queries(src, ["thumbnail"]).replace(/([?&])format=webp/, "$1").replace(/[?&]$/, ""),
head_wrong_contenttype: true,
head_wrong_contentlength: true
};
}
}

Expand Down Expand Up @@ -125276,7 +125291,28 @@ var $$IMU_EXPORT$$;
}

function get_bounding_client_rect(el, mapcache?) {
let need_qsa_patch = false;
// ublock origin patches getBoundingClientRect under youtube, calling document.querySelectorAll every time, which is very slow
if (/youtube\.com$/.test(window.location.host))
need_qsa_patch = true;

let old_selectorall = null;

if (need_qsa_patch) {
old_selectorall = document.querySelectorAll;
try {
document.querySelectorAll = () => {return [];}
} catch (e) {}
}

var obj = get_bounding_client_rect_inner(el, mapcache, true);

if (need_qsa_patch) {
try {
document.querySelectorAll = old_selectorall;
} catch (e) {}
}

return obj.rect || obj.orig_rect;
}

Expand Down
39 changes: 35 additions & 4 deletions userscript.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -37246,7 +37246,8 @@ var $$IMU_EXPORT$$;
.replace(/\/crop\/+[-0-9]+x[-0-9]+\//, "/")
.replace(/\/resize\/+[-0-9]+x[-0-9]+\//, "/");
}
if (domain_nosub === "zadn.vn" && domain.match(/^photo-resize-/)) {
if ((domain_nosub === "zadn.vn" && domain.match(/^photo-resize-/)) ||
domain === "org.photo-resize.mp3.zdn.vn") {
// https://photo-resize-zmp3.zadn.vn/w240h240_jpeg/covers/9/d/9df0d52438b40d91aeaef1c1c2338e92_1476548588.jpg
// https://photo-resize-zmp3.zadn.vn/w240h240_jpeg/covers/9/d/9df0d52438b40d91aeaef1c1c2338e92_1476548588.jpg -- gets redirected to:
// http://org.photo-resize.mp3.zdn.vn/covers/9/d/9df0d52438b40d91aeaef1c1c2338e92_1476548588.jpg
Expand Down Expand Up @@ -37896,6 +37897,10 @@ var $$IMU_EXPORT$$;
// https://www.advocate-art.com/system/ART/Modules/Application/Images/Image/images/000/376/119/medium/ALL258457.png?1788fbdd5f9e2355cd5b5100045df0bc262ada91a284f206a2fe02cd0a68e3e5
// https://www.advocate-art.com/system/ART/Modules/Application/Images/Image/images/000/376/119/original/ALL258457.png?1788fbdd5f9e2355cd5b5100045df0bc262ada91a284f206a2fe02cd0a68e3e5
domain_nowww === "advocate-art.com" ||
// thanks to anonymous for reporting:
// https://d34gglw95p9zsk.cloudfront.net/item_cocreco_images/images/000/122/614/medium/eb02072f-fca2-4a0e-bbd8-7627229f6930.jpg?1672023100
// https://d34gglw95p9zsk.cloudfront.net/item_cocreco_images/images/000/122/614/original/eb02072f-fca2-4a0e-bbd8-7627229f6930.jpg?1672023100
domain === "d34gglw95p9zsk.cloudfront.net" ||
// https://sonar.es/system/attached_images/18702/medium/badgyal_xs_sonar2017_fernandoschlaepfer_004.jpg?1497713257 -- stretched?
// https://sonar.es/system/attached_images/18702/original/badgyal_xs_sonar2017_fernandoschlaepfer_004.jpg?1497713257
domain_nowww === "sonar.es") {
Expand All @@ -37904,7 +37909,7 @@ var $$IMU_EXPORT$$;
// https://sonarreykjavik.com/system/attached_images/19379/original/BadGyal_AlexisG%C3%B3mez.jpg?1513685256
return src
.replace(/(\/attached_images\/+[0-9]+\/+)[a-z]+\/+/, "$1original/")
.replace(/(\/(?:(?:system|images)\/+)?(?:(?:attached|item)_images|App\/+BlogBody|post_pictures|events|posts|items|articles|file_uploads|screenshots|resources|pictures|guides|Image)\/+(?:(?:images|photos|files|assets|pictures|posters|uploads|screenshots|previews|imgs|cropped_images)\/+)?(?:[0-9]{3}\/+){3})[a-z_0-9]+\/+/, "$1original/");
.replace(/(\/(?:(?:system|images)\/+)?(?:(?:attached|item)_images|App\/+BlogBody|post_pictures|events|posts|items|articles|file_uploads|screenshots|resources|pictures|guides|Image|item_cocreco_images)\/+(?:(?:images|photos|files|assets|pictures|posters|uploads|screenshots|previews|imgs|cropped_images)\/+)?(?:[0-9]{3}\/+){3})[a-z_0-9]+\/+/, "$1original/");
//return src.replace(/(\/system\/(?:post_pictures\/(?:files|assets|pictures)\/|posts\/posters\/|events\/images\/)(?:[0-9]+\/){3})[a-z]+(\/[^/]*)$/, "$1original$2");
//return src.replace(/\/[a-z]*\/([-0-9a-f]*\.[^/.]*)$/, "/original/$1");
//return src.replace(/(\/[0-9]+\/[0-9]+\/[0-9]+)\/[a-z]+\/([^/]*)$/, "$1/original/$2");
Expand Down Expand Up @@ -99939,11 +99944,21 @@ var $$IMU_EXPORT$$;
}
if (domain_nowww === "lemmy.world" ||
// thanks to anonymous for reporting:
domain_nowww === "lemmynsfw.com") {
domain_nowww === "lemmynsfw.com" ||
// https://sopuli.xyz/pictrs/image/9250571e-5e5c-4324-bb3f-ce2d5edc4624.webp?format=webp&thumbnail=256
// https://sopuli.xyz/pictrs/image/9250571e-5e5c-4324-bb3f-ce2d5edc4624.webp
domain_nowww === "sopuli.xyz" ||
// https://lemmy.ml/pictrs/image/de0d44c4-f082-45f2-b0a3-111a985be9cd.jpeg?format=webp&thumbnail=256
// https://lemmy.ml/pictrs/image/de0d44c4-f082-45f2-b0a3-111a985be9cd.jpeg
domain_nowww === "lemmy.ml") {
// https://lemmy.world/pictrs/image/54d5e64c-05e2-4c09-913e-b5fb66f58f6a.webp?format=webp&thumbnail=256
// https://lemmy.world/pictrs/image/54d5e64c-05e2-4c09-913e-b5fb66f58f6a.webp
if (/\/pictrs\/+image\/+[-0-9a-f]{10,}\./.test(src)) {
return remove_queries(src, ["thumbnail"]).replace(/([?&])format=webp/, "$1").replace(/[?&]$/, "");
return {
url: remove_queries(src, ["thumbnail"]).replace(/([?&])format=webp/, "$1").replace(/[?&]$/, ""),
head_wrong_contenttype: true,
head_wrong_contentlength: true
};
}
}
if (domain_nowww === "cache.pressmailing.net") {
Expand Down Expand Up @@ -111342,7 +111357,23 @@ var $$IMU_EXPORT$$;
return result;
}
function get_bounding_client_rect(el, mapcache) {
var need_qsa_patch = false;
// ublock origin patches getBoundingClientRect under youtube, calling document.querySelectorAll every time, which is very slow
if (/youtube\.com$/.test(window.location.host))
need_qsa_patch = true;
var old_selectorall = null;
if (need_qsa_patch) {
old_selectorall = document.querySelectorAll;
try {
document.querySelectorAll = function() { return []; };
} catch (e) { }
}
var obj = get_bounding_client_rect_inner(el, mapcache, true);
if (need_qsa_patch) {
try {
document.querySelectorAll = old_selectorall;
} catch (e) { }
}
return obj.rect || obj.orig_rect;
}
function get_popup_client_rect() {
Expand Down

0 comments on commit cd1b8a9

Please sign in to comment.