Chin Fast Image Downloader

One click to download current hovered image/webmeme

当前为 2021-10-09 提交的版本,查看 最新版本

  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. if (el.tagName.toLowerCase() === "img") {
  34. // link to original image/webmeme usually is the parent <a> element
  35. let parent = el.parentNode,
  36. url = parent.href,
  37. filename = HDFilenameFromURL(url);
  38. GM_download(url, filename);
  39. }
  40. });
  41. }
  42. }
  43.  
  44. // eg. ".../1622014662736s.jpg -> 1622014662736.jpg"
  45. let HDFilenameFromURL = (url) => {
  46. let SDFilename = url.split("/").pop();
  47. SDFilename = SDFilename.split(".");
  48.  
  49. if (SDFilename[0][SDFilename[0].length - 1] == "s") {
  50. SDFilename[0] = SDFilename[0].slice(0, -1);
  51. }
  52.  
  53. return SDFilename.join(".");
  54. }
  55. })();