Chin Fast Image Downloader

One click to download current hovered image/webmeme

当前为 2021-11-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Chin Fast Image Downloader
  3. // @namespace https://greasyfork.org/en/users/86284-benjababe
  4. // @version 1.04
  5. // @description One click to download current hovered image/webmeme
  6. // @author Benjababe
  7.  
  8. // @match https://boards.4channel.org/*
  9. // @match https://arch.b4k.co/*
  10. // @match https://archived.moe/*
  11. // @match https://archive.nyafuu.org/*
  12. // @match https://archive.wakarimasen.moe/*
  13. // @match https://desuarchive.org/*
  14. // @match https://warosu.org/*
  15.  
  16. // @grant GM_download
  17. // ==/UserScript==
  18.  
  19. // jshint esversion: 6
  20.  
  21. (function () {
  22. 'use strict';
  23.  
  24. const HOTKEY = "Pause";
  25.  
  26. document.onkeydown = (e) => {
  27. // key can be whatever you want, I choose pause as it's what I bound my mouse side keys to
  28. if (e.code === HOTKEY) {
  29. // get all elements hovered
  30. let els = document.querySelectorAll(":hover");
  31. els.forEach((el) => {
  32. // only download for images
  33. // for webms, it works only on its thumbnail
  34. if (el.tagName.toLowerCase() === "img") {
  35. // link to original image/webmeme usually is the parent <a> element
  36. let parent = el.parentNode,
  37. url = parent.href,
  38. filename = HDFilenameFromURL(url);
  39. GM_download(url, filename);
  40. }
  41. });
  42. }
  43. }
  44.  
  45. // eg. ".../1622014662736s.jpg -> 1622014662736.jpg"
  46. // this function shouldn't ever need to be called, it's ran just in case
  47. let HDFilenameFromURL = (url) => {
  48. let SDFilename = url.split("/").pop(),
  49. re = /([0-9]{1,})[s]{0,}([.a-zA-Z]{1,})/,
  50. match = SDFilename.match(re);
  51.  
  52. return match[1] + match[2];
  53. }
  54. })();