DuckDuckgGo Image Direct Link Patch

Make DuckDuckgGo Image search result entry's image size information as link to the direct image resource.

  1. // ==UserScript==
  2. // @name DuckDuckgGo Image Direct Link Patch
  3. // @namespace https://gf.qytechs.cn/en/users/85671-jcunews
  4. // @version 1.0.2
  5. // @license AGPL v3
  6. // @author jcunews
  7. // @description Make DuckDuckgGo Image search result entry's image size information as link to the direct image resource.
  8. // @match https://duckduckgo.com/*
  9. // @grant none
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. ((dt, xo, mo, ht) => {
  14. function processEntries() {
  15. if (!dt) {
  16. clearTimeout(ht);
  17. ht = setTimeout(processEntries, 500);
  18. return;
  19. }
  20. document.querySelectorAll(".tile--img>.tile--img__dimensions:not(.linked_didlp)").forEach((e, a, u) => {
  21. e.classList.add("linked_didlp");
  22. (a = document.createElement("A")).textContent = e.textContent;
  23. a.style.cssText = "color:inherit";
  24. a.rel = "nofollow noopener noreferrer";
  25. u = e.previousElementSibling.href;
  26. if (!dt.some((d, i) => {
  27. if (d.url === u) {
  28. a.href = d.image;
  29. dt.splice(i, 1);
  30. return true
  31. }
  32. })) a.href = 'javascript:void("Image URL is not found")';
  33. e.replaceChild(a, e.firstChild);
  34. });
  35. }
  36.  
  37. xo = XMLHttpRequest.prototype.open;
  38. XMLHttpRequest.prototype.open = function(mtd, url) {
  39. if (/^\/?i\.js\?.*o=json/.test(url)) {
  40. this.addEventListener("load", (a, l, z) => {
  41. try {
  42. if (!(l = JSON.parse(this.responseText).results)) throw 0;
  43. Array.prototype.push.apply(dt, l);
  44. } catch(z) {}
  45. if (!mo) {
  46. mo = true;
  47. (new MutationObserver(recs => {
  48. clearTimeout(ht);
  49. ht = setTimeout(processEntries, 500);
  50. })).observe(document.body, {childList: true, subtree: true});
  51. processEntries();
  52. }
  53. })
  54. }
  55. return xo.apply(this, arguments);
  56. };
  57.  
  58. dt = [];
  59. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址