Chin Fast Image Downloader

One click to download current hovered image/webmeme

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

  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. // @license MIT
  16.  
  17. // @grant GM_download
  18. // ==/UserScript==
  19.  
  20. // jshint esversion: 6
  21.  
  22. (function () {
  23. 'use strict';
  24.  
  25. const HOTKEY = "Pause";
  26.  
  27. document.onkeydown = (e) => {
  28. // key can be whatever you want, I choose pause as it's what I bound my mouse side keys to
  29. if (e.code === HOTKEY) {
  30. // get all elements hovered
  31. let els = document.querySelectorAll(":hover");
  32. els.forEach((el) => {
  33. // only download for images
  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. let HDFilenameFromURL = (url) => {
  47. let SDFilename = url.split("/").pop();
  48. SDFilename = SDFilename.split(".");
  49.  
  50. if (SDFilename[0][SDFilename[0].length - 1] == "s") {
  51. SDFilename[0] = SDFilename[0].slice(0, -1);
  52. }
  53.  
  54. return SDFilename.join(".");
  55. }
  56. })();