Chin Fast Image Downloader

One click to download current hovered in threads

当前为 2021-05-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Chin Fast Image Downloader
  3. // @namespace http://tampermonkey.net/
  4. // @version 1
  5. // @description One click to download current hovered in threads
  6. // @author Benjababe
  7. // @match https://boards.4channel.org/*/thread/*
  8. // @icon https://www.google.com/s2/favicons?domain=4channel.org
  9. // @grant GM_download
  10. // ==/UserScript==
  11.  
  12. // jshint esversion: 6
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. document.onkeydown = (e) => {
  18. // key can be whatever you want, I choose pause as it's what I bound my mouse side keys to
  19. if (e.code === "Pause") {
  20. // get all elements hovered
  21. let els = document.querySelectorAll( ":hover" );
  22. els.forEach((el) => {
  23. // only download for images
  24. if (el.tagName.toLowerCase() === "img") {
  25. let url = el.src,
  26. filename = HDFilenameFromURL(el.src);
  27. GM_download(url, filename);
  28. }
  29. });
  30. }
  31. }
  32.  
  33. // eg. "1622014662736s.jpg -> 1622014662736.jpg"
  34. let HDFilenameFromURL = (url) => {
  35. let SDFilename = url.split("/").pop();
  36. SDFilename = SDFilename.split(".");
  37. SDFilename[0] = SDFilename[0].slice(0, -1);
  38. return SDFilename.join(".");
  39. }
  40. })();