diff --git a/userscript_smaller.user.js b/userscript_smaller.user.js index d9988928..60ec137e 100644 --- a/userscript_smaller.user.js +++ b/userscript_smaller.user.js @@ -1925,6 +1925,12 @@ var $$IMU_EXPORT$$; return filename.replace(special_regex, "_"); return filename; }; + var is_same_origin = function(url1, url2) { + // https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy + // FIXME: this returns failure for http://site.com:80/ and http://site.com/ + var norm = function(url) { return url.replace(/^([a-z]+:\/\/[^/]+\/+).*/, "$1"); }; + return norm(url1) === norm(url2); + }; var do_browser_download = function(imu, filename, cb) { if (_nir_debug_) { console_log("do_browser_download", imu, filename, cb); @@ -1937,6 +1943,10 @@ var $$IMU_EXPORT$$; var attr = document.createAttribute("download"); a.setAttributeNode(attr); } + // download only works for same-origin urls: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a + if (!is_same_origin(window_location, a.href)) { + a.setAttribute("target", "_blank"); + } a.style.display = "none"; a.onclick = function(e) { e.stopPropagation(); @@ -2005,8 +2015,14 @@ var $$IMU_EXPORT$$; }); } else if (use_gm_download) { var headers; - if (imu.headers) - headers = headers_dict_to_list(imu.headers); + if (imu.headers) { + if (false) { + // why? this breaks both tampermonkey and violetmonkey + headers = headers_dict_to_list(imu.headers); + } else { + headers = imu.headers; + } + } var download_obj = { url: imu.url, headers: headers, @@ -19127,9 +19143,9 @@ var $$IMU_EXPORT$$; if (newsrc !== src) return newsrc; } - if (domain_nowww === "etonline.com") { + if (domain_nowww === "etonline.com" && /\/sites\/+default\/+files\//.test(src)) { return { - url: src, + url: src.replace(/\?.*/, ""), head_wrong_contentlength: true }; } @@ -20307,7 +20323,11 @@ var $$IMU_EXPORT$$; domain === "invidious.einfachzocken.eu" || domain === "invidious.nerdvpn.de" || domain === "inv.n8pjl.ca" || - domain === "youtube.owacon.moe") { + domain === "youtube.owacon.moe" || + domain === "invidious.jing.rocks" || + domain === "vid.lilay.dev" || + domain === "inv.oikei.net" || + domain === "invidious.privacyredirect.com") { newsrc = src.replace(/^[a-z]+:\/\/[^/]+\/+(vi\/+.*?)(?:[?#].*)?$/, "https://i.ytimg.com/$1"); if (newsrc !== src) return newsrc; @@ -20354,9 +20374,15 @@ var $$IMU_EXPORT$$; base = decodeURIComponent(base); return base; } + match = src.match(/^[a-z]+:\/\/[^/]+\/+[a-z]+\/+~1~(voi)~([0-9]{4})~([0-9]{2})~([0-9]{2})~([-0-9a-f]+\.[a-z]+)\//); + if (match) { + return "https://i.pmdstatic.net/" + match[1] + "/" + match[2] + "/" + match[3] + "/" + match[4] + "/" + match[5]; + } } if (domain_nosub === "pmdstatic.net" && domain.match(/img\..*?pmdstatic\.net$/)) { - return decodeURIComponent(src.replace(/.*?\.pmdstatic\.net\/fit\/([^/]*).*/, "$1").replace(/\./g, "%")); + newsrc = src.replace(/.*?\.pmdstatic\.net\/fit\/([^/]*).*/, "$1").replace(/\./g, "%"); + if (newsrc !== src) + return decodeURIComponent(newsrc); } if (domain_nowww === "gala.fr") return src.replace(/^[a-z]+:\/\/[^/]+\/+imgre\//, "https://gal.img.pmdstatic.net/"); if (domain === "dynaimage.cdn.cnn.com") { @@ -20458,6 +20484,7 @@ var $$IMU_EXPORT$$; domain === "imgix.thezoereport.com" || domain === "cdn-imgix-open.headout.com" || domain === "images.assettype.com" || + domain === "media.assettype.com" || domain === "images.seoghoer.dk" || (domain === "static.camp-fire.jp" && string_indexof(src, "/uploads/") >= 0) || domain === "media.popculture.com" || @@ -20938,6 +20965,12 @@ var $$IMU_EXPORT$$; domain === "img.projektn.sk" || (domain === "images.daznservices.com" && /\/di\/+library\//.test(src)) || domain_nowww === "thetv.jp" || + (domain === "metac.nxtv.jp" && /\/img\//.test(src)) || + domain === "media-assets.grailed.com" || + (domain === "media.victorinox.com" && string_indexof(src, "/transform/") >= 0) || + domain === "image.heavenly.tv" || + domain === "images.footballfanatics.com" || + domain === "stat.dokusho-ojikan.jp" || src.match(/\/demandware\.static\//) || src.match(/\?i10c=[^/]*$/) || /^[a-z]+:\/\/[^?]*\/wp(?:-content\/+(?:uploads|blogs.dir)|\/+uploads)\//.test(src) @@ -20988,6 +21021,7 @@ var $$IMU_EXPORT$$; (domain === "digitalcontent.api.tesco.com" && /\/v2\/+media\//.test(src)) || (domain === "gitlab.winehq.org" && /\/uploads\/+/.test(src)) || domain === "cdn.hfashionmall.com" || + (domain === "steamcommunity-a.akamaihd.net" && string_indexof(src, "/image/") >= 0) || (domain_nosub === "ztat.net" && /^img[0-9]*\./.test(domain))) { return { url: src.replace(/\?.*$/, ""), @@ -21385,6 +21419,7 @@ var $$IMU_EXPORT$$; domain === "static.purple.fr" || (domain_nowww === "voguehk.com" && /\/media\//.test(src)) || domain === "cdn.anime-planet.com" || + (domain_nowww === "inglam.club" && /\/img\//.test(src)) || domain === "wp-assets.futurism.com") { src = src.replace(/-[0-9]+x[0-9]+\.([^/]*(?:[?#].*)?)$/, ".$1"); } @@ -21445,6 +21480,7 @@ var $$IMU_EXPORT$$; domain === "cdn.sweatband.com" || domain === "images.cinefil.com" || (domain_nowww === "palmaresadisq.ca" && string_indexof(src, "/uploads/") >= 0) || + domain === "image.b2bmilestone.com" || domain === "music-bandlink.s3.yandex.net") { newsrc = src.replace(/_[0-9]+x[0-9]+(\.[^/.]*)$/, "$1"); if (newsrc !== src) @@ -22332,6 +22368,11 @@ var $$IMU_EXPORT$$; if (match) obj.filename = match[1]; obj.url = src.replace(/\/[0-9]*x[0-9]*[a-z]*(?:-[0-9]+)?(\.[^/.]*)$/, "/999999999x0w-999$1"); + if (obj.url !== src) + return obj; + obj.url = src.replace(/(_file)_cropped(\.[a-z]+\/+999999999x0w[^/]+)$/, "$1$2"); + if (obj.url !== src) + return obj; if (/\.png(?:[?#].*)?$/i.test(obj.url)) { match = src.match(/image\/+thumb\/+(.*?\/+(?:[a-f0-9]{2}\/+){3}(?:[-0-9a-f]{20,}\/)?[^/]+)\//); if (match) { @@ -22420,6 +22461,9 @@ var $$IMU_EXPORT$$; if (options.do_request && options.cb && /:\/\/[^/]+\/+[0-9a-f]{32}\/+[0-9a-f]{16}-[0-9a-f]{2}\/+s[0-9]+x[0-9]+u?(?:_[fc][0-9]+)?\/+[0-9a-f]{20,}\./.test(src)) { var get_initialstate_from_text = function(text) { var match = text.match(/window\['___INITIAL_STATE___'\]\s*=\s*({.*?"ImageUrlPage":.*?})\s*;\s*(?:<\/script>[\s\S]*)?$/); + if (!match) { + match = text.match(/___INITIAL_STATE___">\s*({.*?})\s*<\/script/); + } if (match) { var json = match[1].replace(/(\"\s*:)\s*(?:\/.*?\/|undefined|new RegExp\(.*?\))\s*([,}])/g, "$1null$2"); try { @@ -22991,17 +23035,25 @@ var $$IMU_EXPORT$$; if (domain_nosub === "imgbox.com" && (domain.match(/^thumbs[0-9]*\./) || domain.match(/images[0-9]*\./))) { + var obj_1 = { + url: src + }; + var match_1 = src.match(/\/(?:[0-9a-f]{2}\/+){2}([^/_.]+)_([a-z])\./); + if (match_1) { + if (match_1[2] === "o") + obj_1.is_original = true; + obj_1.extra = { + page: "https://imgbox.com/" + match_1[1] + }; + } newsrc = src .replace(/\/thumbs([0-9]*)\.imgbox\.com\//, "/images$1.imgbox.com/") .replace(/_[a-z](\.[^/.]*)/, "_o$1"); - if (newsrc !== src) - return newsrc; - if (/\/(?:[0-9a-f]{2}\/+){2}[^/_.]+_o\./.test(src)) { - return { - url: src, - is_original: true - }; + if (newsrc !== src) { + obj_1.url = newsrc; + return obj_1; } + return obj_1; } if (domain_nosub === "imgbox.com" && /^(?:[0-9]+[-.])?t\./.test(domain) && options.do_request && options.cb) { newsrc = src.replace(/^[a-z]+:\/\/(?:[0-9]+[-.])?t\./, "https://t."); @@ -23089,7 +23141,8 @@ var $$IMU_EXPORT$$; return newsrc; } if (domain_nowww === "theplace2.ru" || - domain_nowww === "theplace.ru") { + domain_nowww === "theplace.ru" || + domain_nowww === "theplace-2.com") { return src.replace(/(:\/\/[^/]*\/)cache\/(.*?)-g[^/.]*(\.[^/.]*)/, "$1$2$3"); } if ((domain_nosub === "craveonline.com" && domain.match(/cdn[0-9]*-www\.craveonline\.com/)) || @@ -23298,7 +23351,7 @@ var $$IMU_EXPORT$$; ]; var is_picdomain = false; var request_domain; - match = domain.match(/^[ui](?:mg)?[0-9]+([a-z]+)?\./); + match = domain.match(/^[uis](?:mg)?[0-9]+([a-z]+)?\./); if (match) { is_picdomain = true; request_domain = domain_nosub; @@ -23314,9 +23367,9 @@ var $$IMU_EXPORT$$; }, query_for_id: "https://${domain}/${id}/${ext}", process: function(done, resp, cache_key) { - var match = resp.responseText.match(/]*\sdownload/); + var match = resp.responseText.match(/]*\sdownload/); if (!match) { - match = resp.responseText.match(/]*>\s*]*\sclass="[^"]*pic[^"]*"/); + match = resp.responseText.match(/]*>\s*]*\sclass="[^"]*pic[^"]*"/); } if (!match) { console_error(cache_key, "Unable to find match for", resp); @@ -24280,7 +24333,7 @@ var $$IMU_EXPORT$$; } if (domain_nowww === "soundcloud.com") { var soundcloud_get_clientid_from_js_resp = function(resp) { - var match = resp.responseText.match(/,client_id:("[^"]{20,}"),/); + var match = resp.responseText.match(/[{,]client_id:("[^"]{20,}"),/); if (!match) { console_error("Unable to find text from", resp); return null; @@ -24300,7 +24353,7 @@ var $$IMU_EXPORT$$; }); }; var soundcloud_fetch_clientid_js_from_resp = function(resp, cb) { - var match = match_all(resp.responseText, /